1
我试图在模板中使用play_hosts
变量。ansible play_hosts模板循环
我正在尝试为wildfly设置主/从域设置。
所以我希望遍历清单组中的所有主机,而不必指定组。
这就是我想:
{%- for host in play_hosts %}
{%- if 'master' in hostvars[host][ansible_hostname + '_alias'] %}
<remote protocol="remote" host="{{ hostvars[host]['ansible_default_ipv4']['address'] }}" port="9999" />
{%- endif %}
{%- endfor %}
我得到下面的错误:
failed: [atllvjksap012d.hughestelematics.net] (item=host) => {"failed": true, "item": "host", "msg": "AnsibleUndefinedVariable: Unable to look up a name or access an attribute in template string
jinja语法是{%...%}不是{% - ...%} jinja.pocoo.org/docs/dev/templates –
你确定'ansible_hostname +'_alias''是变量名吗? –
我很确定ansible_hostname +'_alias'我在其他地方使用过这个变量。 –