Skip to content

Instantly share code, notes, and snippets.

@pcn
Created July 6, 2018 17:34
Show Gist options
  • Save pcn/7bb902d1b5a25601d5eabfbbf56e0ae4 to your computer and use it in GitHub Desktop.
Save pcn/7bb902d1b5a25601d5eabfbbf56e0ae4 to your computer and use it in GitHub Desktop.
Not getting my pillar data
This is in the orch state:
```
{{ gen_id("artifact") }}:
salt.state:
- tgt: {{ node }}
- sls:
- deploy_{{ deploy.app_type }}.artifact
- pillar:
tier: {{ deploy['tier_name'] }}
deploy_branch: {{ deploy['deploy_branch'] }}
deploy_id: {{ deploy['deploy_id'] }}
appenv_rev: {{ deploy['appenv_rev'] }
```
This is in a jinja file invoked by the `deploy_smarty.artifact` state, invoked above:
Here:
```
{%- from "deploy-helper/master-deploy-macro.jinja" import create_deploy_type -%}
{%- set deploy_branch = salt['pillar.get']('deploy_branch', 'master') -%}
{%- set appenv_rev = salt['pillar.get']('appenv_rev', 'master') -%}
{%- set deploy_id = salt['pillar.get']('deploy_id') -%}
{%- set deploy_action = salt['pillar.get']('deploy_action') -%}
{%- set tier = salt['grains.get']('ec2_tags:Tier') -%}
{% set deploy = create_deploy_type( tier,
deploy_branch, appenv_rev, deploy_id, deploy_action,
salt['pillar.items']() ) | load_json %}
```
Which invokes a macro in master-deploy-macro.jinja:
```
{# On the saltmaster, call this macro to create context. #}
{%- macro create_deploy_type(tier_name, deploy_branch, appenv_rev, deploy_id, deploy_action, use_pillars) -%}
{%- set mapped_type = use_pillars["tier_to_app_type_map"][tier_name] -%}
{%- set deploy_type = use_pillars['deploy_map'][mapped_type] -%}
{# On the saltmaster, we won't have a minion context so the tier will be gotten from the #}
{# pillar info that was provided #}
{# for targeting a tier, while on minions they will be the tier #}
{%- do salt.log.error("create_deploy_type " ~ deploy_type) -%}
{%- set deploy_type = use_pillars['deploy_map'][mapped_type] -%}
{%- if not deploy_branch -%}
{%- set deploy_branch = use_pillars.get('deploy_branch', 'master') -%}
{%- endif -%}
{%- if not appenv_rev -%}
{%- set appenv_rev = use_pillars.get('appenv_rev', 'master') -%}
{%- endif -%}
{%- if not deploy_id -%}
{%- set deploy_id = use_pillars.get('deploy_id') -%}
{%- endif -%}
{%- if not deploy_action -%}
{% set deploy_action = use_pillars.get('deploy_action', 'deploy') -%}
{%- endif -%}
{%- set appenv_path = deploy_type['app_environs']['path'] -%}
{%- set releases_path = appenv_path ~ "/" ~ mapped_type ~ "/" ~ "releases" ~ "/" ~ deploy_id -%}
{%- set shared_path = appenv_path ~ "/" ~ mapped_type ~ "/" ~ "shared" -%}
{%- set current_path = appenv_path ~ "/" ~ mapped_type -%}
{# Check for the existence of the needed variables #}
{%- if not deploy_type -%}
{{ salt.test.exception("deploy_type isn't defined!!") }}
{%- endif -%}
{%- if not deploy_id -%}
{{ salt.test.exception("deploy_id isn't defined!!") }}
{%- endif -%}
[...]
```
It fails on "deploy_id isn't defined"
@gtmanfred
Copy link

    {{ gen_id("artifact") }}:
      salt.state:
        - tgt: {{ node }}
        - sls:
          - deploy_{{ deploy.app_type }}.artifact
        - pillar:
            tier: {{ deploy['tier_name'] }}
            deploy_branch: {{ deploy['deploy_branch'] }}
            deploy_id: {{ deploy['deploy_id'] }}
            appenv_rev: {{ deploy['appenv_rev'] }

@gtmanfred
Copy link

This is what yours renders too.

{
  "{{\"gen_id(\\\"artifact\\\")\"=>nil}=>nil}": {
    "salt.state": [
      {
        "tgt": {
          "{\"node\"=>nil}": null
        }
      },
      {
        "sls": [
          "deploy_{{ deploy.app_type }}.artifact"
        ]
      },
      {
        "pillar": null,
        "tier": "deploy['tier_name'] }}",
        "deploy_branch": "deploy['deploy_branch'] }}",
        "deploy_id": "deploy['deploy_id'] }}",
        "appenv_rev": "deploy['appenv_rev'] }"
      }
    ]
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment