Sum1sAdmin
Sum1sAdmin

Reputation: 209

How to deploy an OpenStack heat template that includes a script

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.

Upvotes: 3

Views: 7467

Answers (2)

sauumum
sauumum

Reputation: 1788

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"

Upvotes: 1

Praveen Yalagandula
Praveen Yalagandula

Reputation: 4704

Refer to the heat's template guide: http://docs.openstack.org/developer/heat/template_guide/software_deployment.html

Essentially resources defined in yaml template files can use "get_file" directive which reads strings from specified file name. So, when you invoke heat client your MSSQL.yaml, your heat client would parse it and wherever it sees "get_file" with a file name as an argument, it then reads from that file.

Example using "get_file" from the above link:

...
the_server:
  type: OS::Nova::Server
  properties:
    # flavor, image etc
    user_data:
      str_replace:
        template: {get_file: the_server_boot.sh}
        params:
          $FOO: {get_param: foo}

Upvotes: 4

Related Questions