我想获取已定义接口类型的地址列表。我在这里
找到了一些信息。
这是我的剧本:
- name: Test JMESPath
hosts: localhost
gather_facts: no
vars:
interfaces:
- name: em0
address: 10.127.37.89/29
- name: bge0
address: 10.112.171.81/28
- name: bge1
address: 10.112.171.65/28
- name: bge2
address: 10.112.171.97/28
tasks:
- name: JMESPath query
set_fact:
result: "{{ interfaces | json_query(query) }}"
vars:
query: "[?name.contains(@, 'bge')].address"
- debug:
var: result
Run Code Online (Sandbox Code Playgroud)
我想得到:
[
"10.112.171.81/28",
"10.112.171.65/28",
"10.112.171.97/28"
]
Run Code Online (Sandbox Code Playgroud)
它可以在 JMESPath 网站上运行,但我的剧本失败了:
Run Code Online (Sandbox Code Playgroud)ansible-playbook play-testJMESPath.yml [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost …