I working on a saltstack state which should add url to windows environment variables according to host region and environment type. I have defined following pillar file:
host: myhost-uat-ln
url_mapping:
http://test-uat-ln.com:
environment:
- UAT
- STAGE
region: LN
http://test-prod-ln.com:
environment:
- PROD
region: LN
http://test-uat-ny.com:
environment:
- UAT
- STAGE
region: NY
http://test-prod-ny.com:
environment:
- PROD
region: NY
My state is defined in following way:
{% set host = pillar ['host'] | replace('-','_') | lower %}
{% set region = pillar['host'].split('-')[-1] %}
{% set env = pillar['host'].split('-')[-2] %}
{% for url, url_args in salt['pillar.get']('url_mapping', {}).iteritems() %}
{% for env_arg in url_args['environment'] %}
{% if env_arg in env and url_args['region'] == region %}
Set url {{ url }} for host {{ host }}:
environ.setenv:
- name: HOST_URL_MAPPING
- value: {{ url }}/{{ host }}
- permanent: HKLM
{% endif %}
{% endfor %}
{% endfor%}
Problem is when I am trying to execute it via saltstack I am getting:
failed: Jinja error: argument of type 'StrictUndefined' is not iterable
{% if env_arg in env and url_args['region'] == region %} <=====================
I have checked variables and it looks like all are defined as list. Can someone please tell me what I'm doing wrong?
I found my problem. I was overriding host pillar when executing state from command line: myhost_uat_ln that's why it was not working.