ansible filter with json_query

爷,独闯天下 提交于 2019-12-12 05:28:50

问题


I write this:

- 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

Am I doing something wrong?


回答1:


You should filter resulting list, not original hash: * | [?ansible_host=='192.168.168.21']

P.S. you usually don't want to use var option of debug module to print Jinja statements, use msg instead.



来源:https://stackoverflow.com/questions/45297569/ansible-filter-with-json-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!