匹配时的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屋!
查看全文