Skip to content

Instantly share code, notes, and snippets.

@pcn
Last active July 6, 2018 19:13
Show Gist options
  • Save pcn/989214a930fb38d682bb14e5e73a6970 to your computer and use it in GitHub Desktop.
Save pcn/989214a930fb38d682bb14e5e73a6970 to your computer and use it in GitHub Desktop.
More jinja issues witih orching
{% for node in all_minions | sort %}
    {# generate unique state IDs per target+loop iteration. #}
    {%- macro gen_id(name) -%} {{ name }}_{{ node }}_{{ loop.index }} {%- endmacro -%}
    {# XXX: an abort macro that logs to slack #}
    {# XXX: a lock-checker that can also abort between steps #}
    {%- macro gen_state(name) -%}
    {{ name }}_{{ node }}_{{ loop.index }}:
      salt.state:
        - name: {{ name }}_{{ node }}_{{ loop.index }}
        - tgt: {{ node }}
        - sls:
          - deploy_{{ deploy.app_type }}.{{ name }}
        - pillar:
            tier: {{ deploy['tier_name'] }}
            deploy_branch: {{ deploy['deploy_branch'] }}
            deploy_id: {{ deploy['deploy_id'] }}
            appenv_rev: {{ deploy['appenv_rev'] }}
    {%- endmacro -%}

    {# XXX Do a a saltutil.refresh_pillar to ensure that data in this deploy is current #}
    {{ gen_id(deploy['tier_name'] ~ "pillar_refresh") }}:
      salt.function:
        - name: saltutil.refresh_pillar
        - tgt: {{ node }}
  
    {# For each sub-action, invoke that sub-action and report #}
    {%- if deploy['deploy_actions']['artifact'] -%}
      {{ gen_state("artifact") }}
    {%- endif -%}
    {% if deploy['deploy_actions']['config'] %}
      {{ gen_state("config") }}      
    {%- endif -%}
    {% if deploy['deploy_actions']['restart'] %}
      {{ gen_state("restart") }}      
    {%- endif -%}

There's a bit more, but it results in:

 1 file changed, 3 insertions(+)
ubuntu@spacey-saltmaster-vagrant:~$ sudo salt-run state.orch orch.min_tier pillar='{"tier": "dummy", "branch": "39e5fcbd900a", "deploy_id": "pcn_test", "deploy_action": "deploy"}'
[CRITICAL] Rendering SLS 'base:orch.min_tier' failed: while constructing a mapping
  in "<unicode string>", line 25, column 7:
          salt.state:
          ^
found conflicting ID 'salt.state'
  in "<unicode string>", line 36, column 7:
          salt.state:
          ^
data:
    ----------
    ip-172-26-168-7.ec2.internal_master:
        - Rendering SLS 'base:orch.min_tier' failed: while constructing a mapping
            in "<unicode string>", line 25, column 7:
                    salt.state:
                    ^
          found conflicting ID 'salt.state'
            in "<unicode string>", line 36, column 7:
                    salt.state:
                    ^
outputter:
    highstate
retcode:
    1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment