我在 OSX 上运行 ansible 2.4.0。以下剧本...
---
- hosts: localhost
connection: local
gather_facts: False
vars:
data:
- name: thing1
desc: I am thing 1
- name: thing2
desc: I am thing 2
tasks:
- debug: msg="{{ data|json_query(\"[1].desc\") }}"
- debug: msg="{{ data|json_query(\"[?name=='thing2'].desc\") }}"
产生以下输出:
PLAY [localhost] ***************************************************************
TASK [debug] *******************************************************************
ok: [localhost] => {
"msg": "I am thing 2"
}
TASK [debug] *******************************************************************
ok: [localhost] => {
"msg": [
"I am thing 2"
]
}
PLAY RECAP *********************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0
我的问题是,为什么在第二个调试任务中是列表([])中的输出?