gpt4 book ai didi

匹配时的ansible过滤器列表

转载 作者:行者123 更新时间:2023-12-02 09:16:00 25 4
gpt4 key购买 nike

groups.all返回包含 list 中所有主机的列表,是否可以将包含唯一字符串的列表提取到另一个列表中。

当我调试时 groups.all我得到以下 list ,其中包含库存中的所有主机。

"groups.all": [
"host-1-unique",
"host-2",
"host-3",
"host-4-unique",
"host-5",
"host-6-unique",
"host-7"
],

在我的 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
}

有谁知道为什么这被跳过了?
如何从返回具有唯一字符串的元素列表的列表中提取?

最佳答案

您可能想了解 Jinja2 filters (内置和 Ansible 提供)。

- set_fact:
new_list: "{{ groups['all'] | select('search','unique') | list }}"

关于匹配时的ansible过滤器列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47172265/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com