匹配时的ansible过滤器列表 [英] ansible filter list when matches
本文介绍了匹配时的ansible过滤器列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 groups.all
返回包含清单中所有主机的列表,是否可以将包含唯一字符串的那些提取到另一个列表中.
With groups.all
that returns a list with all hosts in inventory, is it possible to extract the ones contains unique string into another list.
当我调试 groups.all
时,我得到以下清单,其中包含清单中的所有主机.
When I debug groups.all
I get following list with all hosts in inventory.
"groups.all": [
"host-1-unique",
"host-2",
"host-3",
"host-4-unique",
"host-5",
"host-6-unique",
"host-7"
],
在我的 main.yml 中
In my main.yml
- set_fact:
new_list: []
- set_fact: "{{ new_list }} + [ '{{ item }}' ]"
with_items: groups.all
when: 'unique' in groups.all
我得到以下结果:
{
"skipped": true,
"_ansible_no_log": false,
"skip_reason": "Conditional result was False",
"_ansible_item_result": true,
"item": "groups.all",
"changed": false
}
有谁知道为什么这个被跳过了?如何从列表中提取,返回具有唯一字符串的元素列表?
Does anyone know why this's been skipped? How do I extract from a list, that returns list of elements with unique string?
推荐答案
您可能想了解 Jinja2 过滤器(内置并提供 Ansible).
You may want to learn about Jinja2 filters (built-in and Ansible supplied).
- set_fact:
new_list: "{{ groups['all'] | select('search','unique') | list }}"
这篇关于匹配时的ansible过滤器列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文