gpt4 book ai didi

ansible - 如何解决模板运行时错误: no test named 'equalto' in Ansible?

转载 作者:行者123 更新时间:2023-12-02 00:14:38 29 4
gpt4 key购买 nike

Ansible v2.2.1.0

我有一个收集项目信息的任务,并且我为该任务设置了一个寄存器。比如我用jq来解析一个JSON文件,

hello.json
----------
{
"name" : "hello file",
"english" : "hello",
"spanish" : "hola",
"german" : "wie gehts"
}

- name: parse the hello.json file
shell: |
jq -r '.{{ item }}' < hello.json
register: hellos
with_items:
- english
- spanish
- german

- debug: var=hellos

调试显示

ok: [localhost] => {
"hellos": {
"changed": true,
"msg": "All items completed",
"results": [
{
# snipped
"item": "english",
"stdout" : "hello",
# snipped
},
{
# snipped
"item": "spanish",
"stdout" : "hola",
# snipped
},
{
# snipped
"item": "german",
"stdout" : "wie gehts",
# snipped
}
]
}
}

现在,如果我想获取 hellos 寄存器的标准输出值,我尝试了这个

- name: Display hello messages
debug: msg="{{ hellos.results | selectattr("item","equalto",item) | map(attribute="stdout") | first }} worlld"
with_items:
- english
- spanish
- german

我明白了

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TemplateRuntimeError: no test named 'equalto'
fatal: [localhost]: FAILED! => {"failed": true, "msg": "Unexpected failure during module execution.", "stdout": ""}

我基本上是在第二个调试任务中解析“item”的 hellos 寄存器并获取其“stdout”属性。我的错误在哪里?

最佳答案

你在这里做了一些非常奇怪的事情。我确信您原来的任务可以更容易地解决。

但是要回答您的问题“为什么 equalto 找不到过滤器?”:更新 Jinja2。

检查pip list | grep Jinja2 .
equalto是在ver.1中介绍的。 2.8.

关于ansible - 如何解决模板运行时错误: no test named 'equalto' in Ansible?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44660161/

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