diff --git a/hot/software-config/README.rst b/hot/software-config/README.rst index 6066cea2..4603acb0 100644 --- a/hot/software-config/README.rst +++ b/hot/software-config/README.rst @@ -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 `_ diff --git a/hot/software-config/boot-config/README.rst b/hot/software-config/boot-config/README.rst new file mode 100644 index 00000000..4568b31a --- /dev/null +++ b/hot/software-config/boot-config/README.rst @@ -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 diff --git a/hot/software-config/boot-config/fedora_pip_env.yaml b/hot/software-config/boot-config/fedora_pip_env.yaml new file mode 100644 index 00000000..d29a0d09 --- /dev/null +++ b/hot/software-config/boot-config/fedora_pip_env.yaml @@ -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 \ No newline at end of file diff --git a/hot/software-config/boot-config/fedora_yum_env.yaml b/hot/software-config/boot-config/fedora_yum_env.yaml new file mode 100644 index 00000000..29aee8bb --- /dev/null +++ b/hot/software-config/boot-config/fedora_yum_env.yaml @@ -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 \ No newline at end of file diff --git a/hot/software-config/boot-config/none_env.yaml b/hot/software-config/boot-config/none_env.yaml new file mode 100644 index 00000000..91d130cd --- /dev/null +++ b/hot/software-config/boot-config/none_env.yaml @@ -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" \ No newline at end of file diff --git a/hot/software-config/boot-config/templates/fragments/configure_config_agent.sh b/hot/software-config/boot-config/templates/fragments/configure_config_agent.sh new file mode 100644 index 00000000..42e1d3a3 --- /dev/null +++ b/hot/software-config/boot-config/templates/fragments/configure_config_agent.sh @@ -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 </etc/os-collect-config.conf +[DEFAULT] +command = os-refresh-config +EOF + +# template for building os-collect-config.conf for polling heat +cat <$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 <$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 <$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 <$hooks_dir/script +$hook_script +EOF +chmod 755 $hooks_dir/script + +# install heat-config-notify command +cat </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 diff --git a/hot/software-config/boot-config/templates/fragments/install_config_agent_pip.sh b/hot/software-config/boot-config/templates/fragments/install_config_agent_pip.sh new file mode 100644 index 00000000..1c1a849c --- /dev/null +++ b/hot/software-config/boot-config/templates/fragments/install_config_agent_pip.sh @@ -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 diff --git a/hot/software-config/boot-config/templates/fragments/install_config_agent_yum.sh b/hot/software-config/boot-config/templates/fragments/install_config_agent_yum.sh new file mode 100644 index 00000000..dc76499e --- /dev/null +++ b/hot/software-config/boot-config/templates/fragments/install_config_agent_yum.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -eux + +yum -y install os-collect-config os-apply-config os-refresh-config dib-utils diff --git a/hot/software-config/boot-config/templates/fragments/install_python_build_env_apt.sh b/hot/software-config/boot-config/templates/fragments/install_python_build_env_apt.sh new file mode 100644 index 00000000..8ac9ccd6 --- /dev/null +++ b/hot/software-config/boot-config/templates/fragments/install_python_build_env_apt.sh @@ -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 \ No newline at end of file diff --git a/hot/software-config/boot-config/templates/fragments/install_python_build_env_yum.sh b/hot/software-config/boot-config/templates/fragments/install_python_build_env_yum.sh new file mode 100644 index 00000000..87542ad0 --- /dev/null +++ b/hot/software-config/boot-config/templates/fragments/install_python_build_env_yum.sh @@ -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 diff --git a/hot/software-config/boot-config/templates/fragments/start_config_agent.sh b/hot/software-config/boot-config/templates/fragments/start_config_agent.sh new file mode 100644 index 00000000..d37fe301 --- /dev/null +++ b/hot/software-config/boot-config/templates/fragments/start_config_agent.sh @@ -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 </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 </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 </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 + + + + diff --git a/hot/software-config/boot-config/templates/install_config_agent_fedora_pip.yaml b/hot/software-config/boot-config/templates/install_config_agent_fedora_pip.yaml new file mode 100644 index 00000000..844222d5 --- /dev/null +++ b/hot/software-config/boot-config/templates/install_config_agent_fedora_pip.yaml @@ -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} diff --git a/hot/software-config/boot-config/templates/install_config_agent_fedora_yum.yaml b/hot/software-config/boot-config/templates/install_config_agent_fedora_yum.yaml new file mode 100644 index 00000000..db35c09e --- /dev/null +++ b/hot/software-config/boot-config/templates/install_config_agent_fedora_yum.yaml @@ -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} diff --git a/hot/software-config/boot-config/templates/install_config_agent_ubuntu_pip.yaml b/hot/software-config/boot-config/templates/install_config_agent_ubuntu_pip.yaml new file mode 100644 index 00000000..b8d39504 --- /dev/null +++ b/hot/software-config/boot-config/templates/install_config_agent_ubuntu_pip.yaml @@ -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} diff --git a/hot/software-config/boot-config/ubuntu_pip_env.yaml b/hot/software-config/boot-config/ubuntu_pip_env.yaml new file mode 100644 index 00000000..6c1c6ec2 --- /dev/null +++ b/hot/software-config/boot-config/ubuntu_pip_env.yaml @@ -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 \ No newline at end of file diff --git a/hot/software-config/example-templates/example-config-pristine-image.yaml b/hot/software-config/example-templates/example-config-pristine-image.yaml new file mode 100644 index 00000000..8ebcae13 --- /dev/null +++ b/hot/software-config/example-templates/example-config-pristine-image.yaml @@ -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] \ No newline at end of file diff --git a/hot/software-config/example-templates/example-config-pristine-image_env.yaml b/hot/software-config/example-templates/example-config-pristine-image_env.yaml new file mode 100644 index 00000000..7030db44 --- /dev/null +++ b/hot/software-config/example-templates/example-config-pristine-image_env.yaml @@ -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" \ No newline at end of file