StrinctUndefined 类型的 saltstack jinja 错误参数不可迭代
saltstack jinja error argument of type StrinctUndefined is not iterable
我正在处理一个 saltstack 状态,它应该根据主机区域和环境类型将 url 添加到 windows 环境变量。我定义了以下支柱文件:
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
我的状态定义如下:
{% 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%}
问题是当我尝试通过 saltstack 执行它时我得到:
failed: Jinja error: argument of type 'StrictUndefined' is not iterable
{% if env_arg in env and url_args['region'] == region %} <=====================
我检查了变量,看起来所有变量都定义为列表。有人可以告诉我我做错了什么吗?
我发现了我的问题。从命令行执行状态时,我覆盖了主机支柱:myhost_uat_ln 这就是它不起作用的原因。
我正在处理一个 saltstack 状态,它应该根据主机区域和环境类型将 url 添加到 windows 环境变量。我定义了以下支柱文件:
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
我的状态定义如下:
{% 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%}
问题是当我尝试通过 saltstack 执行它时我得到:
failed: Jinja error: argument of type 'StrictUndefined' is not iterable
{% if env_arg in env and url_args['region'] == region %} <=====================
我检查了变量,看起来所有变量都定义为列表。有人可以告诉我我做错了什么吗?
我发现了我的问题。从命令行执行状态时,我覆盖了主机支柱:myhost_uat_ln 这就是它不起作用的原因。