带有 json_query 的 ansible 过滤器 [英] ansible filter with json_query
本文介绍了带有 json_query 的 ansible 过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是这样写的:
- name: test for seed
debug:
var: hostvars|json_query("*.ansible_host")
它会打印每个主机.但这不会过滤主机:
And it prints every host. But this does not filter hosts:
- name: test for seed
debug:
var: hostvars|json_query("*[?ansible_host=='192.168.56.101']")
它只是打印一个空列表,而我确定这个主机存在.这是相关的库存行:
It just prints an empty list, while I'm sure this host exists. This is the relevant inventory line:
[build-servers]
build-server ansible_host=192.168.56.101
我做错了什么吗?
推荐答案
您应该过滤结果列表,而不是原始哈希:* |[?ansible_host=='192.168.168.21']
You should filter resulting list, not original hash: * | [?ansible_host=='192.168.168.21']
附言您通常不想使用 debug
模块的 var
选项来打印 Jinja 语句,而是使用 msg
.
P.S. you usually don't want to use var
option of debug
module to print Jinja statements, use msg
instead.
这篇关于带有 json_query 的 ansible 过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文