数组/目录列表上的Ansible循环匹配
我有一个这样的数组数组/目录列表上的Ansible循环匹配,ansible,ansible-2.x,ansible-template,Ansible,Ansible 2.x,Ansible Template,我有一个这样的数组 our_domains: - domain: www.example.com urls: - { path: '/' } - { path: '/test1' } - domain: www.example2.com urls: - { path: '/' } - { path: '/test2' } 在一个模板中,我想在给定的域上进行匹配,然后循环URL的内容 e、 g 我确信FOR循环将正常工作,因
our_domains:
- domain: www.example.com
urls:
- { path: '/' }
- { path: '/test1' }
- domain: www.example2.com
urls:
- { path: '/' }
- { path: '/test2' }
在一个模板中,我想在给定的域上进行匹配,然后循环URL的内容
e、 g
我确信FOR循环将正常工作,因为它在代码中其他地方的类似上下文中工作
我只是在努力获得域名上的条件匹配
任何帮助都将不胜感激
谢谢您似乎想为
我们的\u域
列表的每个元素执行模板
任务
您只需从语句中删除值
,如果
语句中的剩余值看起来很好:
{% if item.domain == 'www.example2.com' %}
{% for item_url in item.urls %}
service_description http://anotherwebsite.com{{ item_url['path'] }}
{% endfor %}
{% endif %}
另一方面,如果您打算只生成一个文件,则应使用此模板(在前面的代码中添加了一个for循环):
{% if item.domain == 'www.example2.com' %}
{% for item_url in item.urls %}
service_description http://anotherwebsite.com{{ item_url['path'] }}
{% endfor %}
{% endif %}
{% for item in our_domains %}
{% if item.domain == 'www.example2.com' %}
{% for item_url in item.urls %}
service_description http://anotherwebsite.com{{ item_url['path'] }}
{% endfor %}
{% endif %}
{% endfor %}