在虚拟机启动后执行编排任务, nova boot时指定 user-data 参数
数据获取方式:
- 169.254.169.254
- config drive(In Heat set config_drive: true)
常见使用方式如下:
#nova boot \
--image ubuntu-trusty-server-amd64
--key_name testkey \
--flavor m1.small \
--user-data userdata.txt \
--nic net-id=443434-dsx3-2323-dssx-43343434 \
test
And, userdata.txt
#!/bin/sh -e
#Frobincate a newly booted box
initialize_box
for foo in forbnications; do
frobincate_machine $foo || break
done
exit $?
But, stop doing this, and use cloud-config below which is better
Enables you to bootstrap a newly bootd VM. OpenStack’s most underrated feature, 100% YAML.
常用功能如下:
Update system on first boot
#cloud-config
package_update: true
package_upgrade: true
Configure users and groups
users:
- default
- name: foobar
gecos: ""
groups: users,adm
lock-passwd: false
passwd: 23lkjsflkas0923Da
shell: /bin/bash
sudo: "ALL=(ALL) NOPASSWD:ALL"
Enable/disable SSH password authentication
ssh_pwauth: true
Write arbitrary files
write_files:
- path: /etc/demo
permissions: '0644'
content: |
This is a demo
Config VM’s puppet client
Config VM’s chef client
Install packages
packages:
- ansible
- git
Run commands early in the boot sequence
bootcmd:
- ntpdate pool.ntp.org
Run commands late in boot sequence
runcmd:
- echo "hello world"
- ls -hS
#nova boot \
--image ubuntu-trusty-server-amd64
--key_name testkey \
--flavor m1.small \
--user-data config.yaml \
--nic net-id=443434-dsx3-2323-dssx-43343434 \
test
cloud-init 日志输出到 /var/log/cloud-init.log
Enables you deploy complete virtual environments
- CFN
Amazon CLoudFormation compatible template
- HOT
Heat Orchestration Template, 100% YAML
type: “OS::Nova::Server”
resources:
mybox:
type: "OS::Nova::Server"
properties:
name: mybox
image: ubuntu-trusty-amd64
flavor: m1.small
key_name: testkey
#heat stack-create -f stack.yaml mystack
parameters:
name:
type: string
default:
flavor:
type: string
default: m1.small
image:
type: string
default: ubuntu-trusty-amd64
key_name:
type: string
resources:
mybox
type:
properties
name: { get_param: name }
image: { get_param: image }
flavor: { get_param: flavor }
key_name: { get_param: key_name }
#heat stack-create -f stack.yaml \
-P key_name testkey mystack
mynet:
type: "OS::Neutron::Net"
properties:
name: management-net
mysub_net
type: "OS::Neutron::Subnet"
properties:
name: management-subnet
network: { get_resource: management-net }
cidr: 192.168.101.0/24
gateway_ip: 192.168.101.1
enable_dhcp: true
allocation_pools:
- start: "192..168.101.2"
end: "192.168.101.100"
Return stack values or attributes
outputs:
public_ip:
description:
value: { get_attr: [ myfloating_ip, floating_ip_address ]}
查看方式
#heat output-show mystack public_ip
常用方式
mybox:
type: "OS::Nova::Server"
properties:
name: deploy
image: { get_param: image }
flavor: { get_param: flavor }
key_name: { get_param: key_name }
networks:
- port: { get_resource: mybox_management_port }
user_data: {get_file: cloud-config.yaml }
user_data_format: RAW
but, there is a better way
Manages cloud-config directly from Heat
resources:
myconfig:
type: "OS::Heat::CloudConfig"
properties:
cloud_config:
package_update: true
package_upgrade: true
mybox:
type: "OS::Nova::Server"
properties:
name: deploy
image: { get_param: image }
flavor: { get_param: flavor }
key_name: { get_param: key_name }
networks:
- port: { get_resource: mybox_management_port }
user_data: {get_resource: myconfig }
user_data_format: RAW
Also, you can SET cloud-config parameters directly from HEAT, which is nice
parameters:
# [...]
username:
type: string
description: Additional login name
default: foobar
myconfig:
type: "OS::Heat::CloudConfig"
properties:
cloud_config:
package_update: true
package_upgrade: true
users:
- default
- name: { get_param: username }
shell: "/bin/bash"
ssh_pwauth: true