Ask Your Question
1

Use a Heat condition to exclude item from list

asked 2019-04-17 16:54:23 -0500

dlbewley gravatar image

Can I use a condition to exclude a part from the list of configs ina MultipartMime resource?

GOAL, If parameter 'playbook_repo' is empty string then: do not create certain resources, and do not include certain SoftwareConfig in MultipartMime user-data.

I'm trying to make my template flexible and reusable, but maybe I'm trying to be too clever.

  • Custom resources snippet follows:
  resource_registry:
    Custom::OS::Heat::SoftwareConfig::Playbook-Runner: ../user-data/playbook-runner.yaml
    Custom::OS::Nova::Keypair::NSA: ssh/group/nsa.yaml
    Custom::OS::Nova::Server::With-Volume: server/with-volume.yaml
  • Heat template test-servers.yaml follows:
  heat_template_version: queens
  parameters:
    ...
  resources:
    servers:
      type: OS::Heat::ResourceGroup
      depends_on:
        - router_internal_interface
      properties:
        count: { get_param: instance_count }
        resource_def:
          type: Custom::OS::Nova::Server::With-Volume
          properties:
            ...
  • Custom::OS::Nova::Server::With-Volume: server/with-volume.yaml snippet follows:
  heat_template_version: queens
  parameters:
    ...
    playbook_repo:
      type: string
      label: Playbook git repo
      description: Playbook to checkout and run via cloud-init user_data
      default: ''

  conditions:
    playbook_included:
      not:
        equals:
        - get_param: playbook_repo
        - ''

  resources:
    ssh_keys_admins:
      type: Custom::OS::Nova::Keypair::NSA

    # GOAL optionally do not create this:
    playbook_waitcondition_handle:
      type: OS::Heat::WaitConditionHandle
      condition: playbook_included

    # GOAL optionally do not create this:
    playbook_waitcondition:
      type: OS::Heat::WaitCondition
      condition: playbook_included
      properties:
        handle: { get_resource: playbook_waitcondition_handle }
        count: 1
        timeout: 600

    # GOAL optionally do not create this:
    playbook_runner:
      type: Custom::OS::Heat::SoftwareConfig::Playbook-Runner
      condition: playbook_included
      properties:
        playbook_notify_heat: { get_attr: [ playbook_waitcondition_handle, 'curl_cli' ] }

    server_init:
      type: OS::Heat::MultipartMime
      properties:
        parts:
        - config: { get_attr: [ssh_keys_admins, resource.cloud_config_ssh] }
        # GOAL optionally do not include the following part:
        - config: { get_attr: [playbook_runner, resource.playbook_runner] }

    instance:
      type: OS::Nova::Server
      properties:
        name: { get_param: instance_name }
        image: { get_param: image }
        flavor: { get_param: flavor }
        key_name: { get_param: key }
        networks:
          - port: { get_resource: server_port }
        user_data_format: RAW
        user_data:
          get_resource: server_init
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2019-04-18 07:35:27 -0500

zaneb gravatar image

Yes, you can using the if macro (you're already correctly creating the resources conditionally). I'm not 100% sure it's possible without some duplication, but this should certainly work:

server_init:
  type: OS::Heat::MultipartMime
  properties:
    parts:
      if:
        - playbook_included
        - - config: { get_attr: [ssh_keys_admins, resource.cloud_config_ssh] }
          - config: { get_attr: [playbook_runner, resource.playbook_runner] }
        - - config: { get_attr: [ssh_keys_admins, resource.cloud_config_ssh] }
edit flag offensive delete link more

Comments

1

I guess this creates an empty mime blob but works.

server_init:
    type: OS::Heat::MultipartMime
    properties:
      parts:
        - config: ...
        - if: [ playbook_included, config: { get_attr: [playbook_runner, resource.playbook_runner] }, config: '' ]
dlbewley gravatar imagedlbewley ( 2019-04-19 13:38:41 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2019-04-17 16:54:23 -0500

Seen: 51 times

Last updated: Apr 18