March 01, 2016

OpenStack OS::Heat::CloudConfig OS::Heat::MultipartMime

Debugging OpenStack Heat Template with OS:Heat:CloudConfig resources in OS::Heat::MultipartMime where only the last config was executed.   This was pretty frustrating to figure out what was happening.   If I rearranged the order, only the last config would execute.  It was clear that expected behavior was a trap.  Using an example from OpenStack Heat Templates to illustrate proper usage I can illustrate what was happening and what to fix.

I have seen other folks use OS::Heat::SoftwareConfig and then echo their settings to a file to avoid this programming pitfall.   The result is less readable, messy code.   I knew I was missing something and after a lot of reading and studying templates I found the solution.

How to make sure all the OS::Heat::CloudConfig resources are executed using OS::Heat::MultipartMime

Using an example from OpenStack Heat Templates to illustrate proper usage I can illustrate what was happening and what to fix.

Example snippet:

five_init:
  # this resource demonstrates multiple cloud-config resources
  # with a merge_how strategy
  type: OS::Heat::CloudConfig
  properties:
    cloud_config:
      merge_how: 'dict(recurse_array,no_replace)+list(append)'
      write_files:
      - path: /tmp/five
      content: |
       The five is bar
       look what happens if you take out the merge_how
       and you will see that all the configs in
       server_init do not execute
server_init:
  type: OS::Heat::MultipartMime
  properties:
  parts:
  - config: {get_resource: one_init}
  - config: {get_resource: two_init}
  # referencing another OS::Heat::MultipartMime resource will result
  # in each part of that resource being appended to this one.
  - config: {get_resource: three_four_init}
  type: multipart
  - config: {get_resource: five_init}</pre>

The key is the “merge_how” setting in OS::Heat::CloudConfig that makes this work, otherwise the new “- config” would replace the previous OS::Heat::CloudConfig resource.    By adding the “merge_how” setting we can override this behavior and append the setting.   For each of the configs in the OS::Heat::MultipartMime I had to make sure “merge_how” was added.  You can read more about merge_how in the cloud_init docs