本文介绍了使用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']

P.S.您通常不想使用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过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 12:25