Boot config for installing software-config agent

This defines environment files which each declare a resource type
Heat::InstallConfigAgent.

This can be used by server user_data when booting a pristine image
to install the agent required use software deployment resources in
templates.

This template can be run with downloadable Fedora images from
http://fedoraproject.org/en/get-fedora#clouds

or Ubuntu images from https://cloud-images.ubuntu.com/

Tested with Fedora-x86_64-20-20140618-sda (yum and pip)
and trusty-server-cloudimg-amd64-disk1 (pip)

Change-Id: I654561719b88c7e2a548ff6db406dd0caf3e8489
This commit is contained in:
Steve Baker 2014-09-05 15:30:23 +12:00
parent c055d5bdea
commit 426b924c41
17 changed files with 512 additions and 0 deletions

View File

@ -7,6 +7,15 @@ and hooks to configure software on servers using a variety of techniques.
Contained here are the following directories:
boot-config
-----------
This directory has environment files which each declare a resource type
Heat::InstallConfigAgent.
This can be used by server user_data when booting a pristine image
to install the agent required to use software deployment resources in
templates.
elements
--------
This contains `diskimage-builder <https://github.com/openstack/diskimage-builder>`_

View File

@ -0,0 +1,32 @@
================================================
Boot config for installing software-config agent
================================================
This directory has environment files which each declare a resource type
Heat::InstallConfigAgent.
This can be used by server user_data when booting a pristine image
to install the agent required to use software deployment resources in
templates.
The environments only install the heat-config-script hook. If other hooks are
required then define your own environment file which defines a resource
template based on one of the templates in template/
To install the agent during boot, include the following in the template:
boot_config:
type: Heat::InstallConfigAgent
server:
type: OS::Nova::Server
properties:
user_data_format: SOFTWARE_CONFIG
user_data: {get_attr: [boot_config, config]}
# ...
When creating the stack, reference the desired environment, eg:
heat stack-create -e fedora_yum_env.yaml \
-f ../example-templates/example-config-pristine-image.yaml \
deploy-to-pristine

View File

@ -0,0 +1,7 @@
# Installs software-config agent on boot for fedora with pip install
parameters:
image: Fedora-x86_64-20-20140618-sda
resource_registry:
"Heat::InstallConfigAgent": templates/install_config_agent_fedora_pip.yaml

View File

@ -0,0 +1,7 @@
# Installs software-config agent on boot for fedora with yum
parameters:
image: Fedora-x86_64-20-20140618-sda
resource_registry:
"Heat::InstallConfigAgent": templates/install_config_agent_fedora_yum.yaml

View File

@ -0,0 +1,5 @@
# Defines a Heat::InstallConfigAgent config resource which performs no config.
# This environment can be used when the image already has the required agents
# installed and configured.
resource_registry:
"Heat::InstallConfigAgent": "OS::Heat::SoftwareConfig"

View File

@ -0,0 +1,112 @@
#!/bin/bash
set -eux
# os-apply-config templates directory
oac_templates=/usr/libexec/os-apply-config/templates
mkdir -p $oac_templates/etc
# initial /etc/os-collect-config.conf
cat <<EOF >/etc/os-collect-config.conf
[DEFAULT]
command = os-refresh-config
EOF
# template for building os-collect-config.conf for polling heat
cat <<EOF >$oac_templates/etc/os-collect-config.conf
[DEFAULT]
{{^os-collect-config.command}}
command = os-refresh-config
{{/os-collect-config.command}}
{{#os-collect-config}}
{{#command}}
command = {{command}}
{{/command}}
{{#polling_interval}}
polling_interval = {{polling_interval}}
{{/polling_interval}}
{{#cachedir}}
cachedir = {{cachedir}}
{{/cachedir}}
{{#collectors}}
collectors = {{collectors}}
{{/collectors}}
{{#cfn}}
[cfn]
{{#metadata_url}}
metadata_url = {{metadata_url}}
{{/metadata_url}}
stack_name = {{stack_name}}
secret_access_key = {{secret_access_key}}
access_key_id = {{access_key_id}}
path = {{path}}
{{/cfn}}
{{#heat}}
[heat]
auth_url = {{auth_url}}
user_id = {{user_id}}
password = {{password}}
project_id = {{project_id}}
stack_id = {{stack_id}}
resource_name = {{resource_name}}
{{/heat}}
{{#request}}
[request]
{{#metadata_url}}
metadata_url = {{metadata_url}}
{{/metadata_url}}
{{/request}}
{{/os-collect-config}}
EOF
mkdir -p $oac_templates/var/run/heat-config
# template for writing heat deployments data to a file
echo "{{deployments}}" > $oac_templates/var/run/heat-config/heat-config
# os-refresh-config scripts directory
# This moves to /usr/libexec/os-refresh-config in later releases
orc_scripts=/opt/stack/os-config-refresh
for d in pre-configure.d configure.d migration.d post-configure.d; do
install -m 0755 -o root -g root -d $orc_scripts/$d
done
# os-refresh-config script for running os-apply-config
cat <<EOF >$orc_scripts/configure.d/20-os-apply-config
#!/bin/bash
set -ue
exec os-apply-config
EOF
chmod 700 $orc_scripts/configure.d/20-os-apply-config
# os-refresh-config script for running heat config hooks
cat <<EOF >$orc_scripts/configure.d/55-heat-config
$heat_config_script
EOF
chmod 700 $orc_scripts/configure.d/55-heat-config
# config hook for shell scripts
hooks_dir=/var/lib/heat-config/hooks
mkdir -p $hooks_dir
# install hook for configuring with shell scripts
cat <<EOF >$hooks_dir/script
$hook_script
EOF
chmod 755 $hooks_dir/script
# install heat-config-notify command
cat <<EOF >/usr/bin/heat-config-notify
$heat_config_notify
EOF
chmod 755 /usr/bin/heat-config-notify
# run once to write out /etc/os-collect-config.conf
os-collect-config --one-time --debug
cat /etc/os-collect-config.conf
# run again to poll for deployments and run hooks
os-collect-config --one-time --debug

View File

@ -0,0 +1,6 @@
#!/bin/bash
set -eux
pip install os-collect-config os-apply-config os-refresh-config dib-utils heat-cfntools
cfn-create-aws-symlinks

View File

@ -0,0 +1,4 @@
#!/bin/bash
set -eux
yum -y install os-collect-config os-apply-config os-refresh-config dib-utils

View File

@ -0,0 +1,5 @@
#!/bin/bash
set -eux
apt-get -y update
apt-get -y install python-pip git gcc python-dev libyaml-dev libssl-dev libffi-dev libxml2-dev libxslt1-dev

View File

@ -0,0 +1,4 @@
#!/bin/bash
set -eux
yum -y install python-pip gcc git-core python-devel libyaml-devel openssl-devel libffi-devel libxml2-devel libxslt-devel

View File

@ -0,0 +1,53 @@
#!/bin/bash
set -eux
if [[ `systemctl` =~ -\.mount ]]; then
# if there is no system unit file, install a local unit
if [ ! -f /usr/lib/systemd/system/os-collect-config.service ]; then
cat <<EOF >/etc/systemd/system/os-collect-config.service
[Unit]
Description=Collect metadata and run hook commands.
[Service]
ExecStart=/usr/bin/os-collect-config
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
cat <<EOF >/etc/os-collect-config.conf
[DEFAULT]
command=os-refresh-config
EOF
fi
# enable and start service to poll for deployment changes
systemctl enable os-collect-config
systemctl start --no-block os-collect-config
elif [[ `/sbin/init --version` =~ upstart ]]; then
if [ ! -f /etc/init/os-collect-config.conf ]; then
cat <<EOF >/etc/init/os-collect-config.conf
start on runlevel [2345]
stop on runlevel [016]
respawn
# We're logging to syslog
console none
exec os-collect-config 2>&1 | logger -t os-collect-config
EOF
fi
initctl reload-configuration
service os-collect-config start
else
echo "ERROR: only systemd or upstart supported" 1>&2
exit 1
fi

View File

@ -0,0 +1,46 @@
heat_template_version: 2014-10-16
resources:
install_python_build_env:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config: {get_file: fragments/install_python_build_env_yum.sh}
install_config_agent_pip:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config: {get_file: fragments/install_config_agent_pip.sh}
configure_config_agent:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config:
str_replace:
params:
$heat_config_script: {get_file: ../../elements/heat-config/os-refresh-config/configure.d/55-heat-config}
$hook_script: {get_file: ../../elements/heat-config-script/install.d/hook-script.py}
$heat_config_notify: {get_file: ../../elements/heat-config/bin/heat-config-notify}
template: {get_file: fragments/configure_config_agent.sh}
start_config_agent:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config: {get_file: fragments/start_config_agent.sh}
install_config_agent:
type: "OS::Heat::MultipartMime"
properties:
parts:
- config: {get_resource: install_python_build_env}
- config: {get_resource: install_config_agent_pip}
- config: {get_resource: configure_config_agent}
- config: {get_resource: start_config_agent}
outputs:
config:
value: {get_resource: install_config_agent}

View File

@ -0,0 +1,39 @@
heat_template_version: 2014-10-16
resources:
install_config_agent_yum:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config: {get_file: fragments/install_config_agent_yum.sh}
configure_config_agent:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config:
str_replace:
params:
$heat_config_script: {get_file: ../../elements/heat-config/os-refresh-config/configure.d/55-heat-config}
$hook_script: {get_file: ../../elements/heat-config-script/install.d/hook-script.py}
$heat_config_notify: {get_file: ../../elements/heat-config/bin/heat-config-notify}
template: {get_file: fragments/configure_config_agent.sh}
start_config_agent:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config: {get_file: fragments/start_config_agent.sh}
install_config_agent:
type: "OS::Heat::MultipartMime"
properties:
parts:
- config: {get_resource: install_config_agent_yum}
- config: {get_resource: configure_config_agent}
- config: {get_resource: start_config_agent}
outputs:
config:
value: {get_resource: install_config_agent}

View File

@ -0,0 +1,46 @@
heat_template_version: 2014-10-16
resources:
install_python_build_env:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config: {get_file: fragments/install_python_build_env_apt.sh}
install_config_agent_pip:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config: {get_file: fragments/install_config_agent_pip.sh}
configure_config_agent:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config:
str_replace:
params:
$heat_config_script: {get_file: ../../elements/heat-config/os-refresh-config/configure.d/55-heat-config}
$hook_script: {get_file: ../../elements/heat-config-script/install.d/hook-script.py}
$heat_config_notify: {get_file: ../../elements/heat-config/bin/heat-config-notify}
template: {get_file: fragments/configure_config_agent.sh}
start_config_agent:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config: {get_file: fragments/start_config_agent.sh}
install_config_agent:
type: "OS::Heat::MultipartMime"
properties:
parts:
- config: {get_resource: install_python_build_env}
- config: {get_resource: install_config_agent_pip}
- config: {get_resource: configure_config_agent}
- config: {get_resource: start_config_agent}
outputs:
config:
value: {get_resource: install_config_agent}

View File

@ -0,0 +1,7 @@
# Installs software-config agent on boot for ubuntu with pip install
parameters:
image: trusty-server-cloudimg-amd64-disk1
resource_registry:
"Heat::InstallConfigAgent": templates/install_config_agent_ubuntu_pip.yaml

View File

@ -0,0 +1,122 @@
heat_template_version: 2014-10-16
description: >
A template which demonstrates doing boot-time installation of the required
files for script based software deployments.
This template expects to be created with an environment which defines
the resource type Heat::InstallConfigAgent such as
../boot-config/fedora_pip_env.yaml
parameters:
key_name:
type: string
default: heat_key
flavor:
type: string
default: m1.small
image:
type: string
private_net:
type: string
default: private
public_net:
type: string
default: public
resources:
the_sg:
type: OS::Neutron::SecurityGroup
properties:
name: the_sg
description: Ping and SSH
rules:
- protocol: icmp
- protocol: tcp
port_range_min: 22
port_range_max: 22
config:
type: OS::Heat::SoftwareConfig
properties:
group: script
inputs:
- name: foo
- name: bar
outputs:
- name: result
config: |
#!/bin/sh -x
echo "Writing to /tmp/$bar"
echo $foo > /tmp/$bar
echo -n "The file /tmp/$bar contains `cat /tmp/$bar` for server $deploy_server_id during $deploy_action" > $heat_outputs_path.result
echo "Written to /tmp/$bar"
echo "Output to stderr" 1>&2
deployment:
type: OS::Heat::SoftwareDeployment
properties:
config:
get_resource: config
server:
get_resource: server
input_values:
foo: fooooo
bar: baaaaa
other_deployment:
type: OS::Heat::SoftwareDeployment
properties:
config:
get_resource: config
server:
get_resource: server
input_values:
foo: fu
bar: barmy
actions:
- CREATE
- UPDATE
- SUSPEND
- RESUME
boot_config:
type: Heat::InstallConfigAgent
server:
type: OS::Nova::Server
properties:
image: {get_param: image}
flavor: {get_param: flavor}
key_name: {get_param: key_name}
networks:
- network: {get_param: private_net}
security_groups:
- {get_resource: the_sg}
user_data_format: SOFTWARE_CONFIG
user_data: {get_attr: [boot_config, config]}
server_floating_ip_assoc:
type: OS::Neutron::FloatingIPAssociation
properties:
floatingip_id: {get_resource: floating_ip}
port_id: {get_attr: [server, addresses, {get_param: private_net}, 0, port]}
floating_ip:
type: OS::Neutron::FloatingIP
properties:
floating_network: {get_param: public_net}
outputs:
result:
value:
get_attr: [deployment, result]
stdout:
value:
get_attr: [deployment, deploy_stdout]
stderr:
value:
get_attr: [deployment, deploy_stderr]
status_code:
value:
get_attr: [deployment, deploy_status_code]
other_result:
value:
get_attr: [other_deployment, result]

View File

@ -0,0 +1,8 @@
# Defines a Heat::InstallConfigAgent config resource which performs no config.
# This environment can be used when the image already has the required agents
# installed and configured.
#
# See heat-templates/hot/software-config/boot-config for environments
# for different distros and install methods
resource_registry:
"Heat::InstallConfigAgent": "OS::Heat::SoftwareConfig"