How to deploy an OpenStack heat template that includes a script

Viewed 6597

The orchestration engine for OpenStack 'Heat' can deploy compute resources and configure software, known as HOT templates. There are a number of examples on github here: https://github.com/openstack/heat-templates/tree/master/hot

heat templates are written in YAML and we can deploy a template with this syntax

heat stack-create my_first_stack -f heat_1a.yaml

You can also upload the template file directly to the OpenStack dashboard. however, and here is my question, many of the templates will also include shell scripts of powershell scripts which are run after deployment - how do we upload these scripts to OpenStack for inclusion in the stack?

for example, here is the directory listing for a MicroSoft SQL server template

C:\heat-templates\hot\Windows\MSSQLServer>ls
MSSQL.ps1  MSSQL.psm1  MSSQL.yaml  Tests  heat-powershell-utils.psm1

Heat client will only take the YAML file as an argument, so how or what do we do with the scripts?

thanks, Rob.

2 Answers

Sometimes, we need need to create the script based on the parameters provided in HEAT template and execute it once Stack is created.

For this kind of requirement, we can use pattern mention below. This will create as well as execute the script once VM is up and in cloud-init phase.

services-cloud-init:
    type: OS::Heat::CloudConfig
    properties:
        cloud_config:
            timezone: {get_param: time_zone}
            write_files:
              - path: /tmp/change_password.sh
                owner: root:root
                permissions: '0777'
                content: |
                          #!/bin/bash
                          echo -e "pwd\npwd" | passwd cloud-user

              - path: /run/change_timezone.sh
                owner: root:root
                permissions: '0777'
                content: |
                          #!/bin/bash
                          ln -sf /usr/share/zoneinfo/timezone /etc/localtime

            runcmd:
              - echo "Executing change_timezone"
              - /tmp/change_timezone.sh
              - echo "Executing change_password"
              - /tmp/change_password.sh
              - reboot
            bootcmd:
              - echo "Boot Completed"
Related