这本ansible playbook 很管用
---
- hosts: localhost
gather_facts: False
vars:
jq: "[?contains(name, 'Pizza')]"
json: |
[{
"name": "Ted's Sub Shop - 720895714701",
"templateid": "24632"
},
{
"name": "Ted's Pizza - 720895714702",
"templateid": "24663"
}]
tasks:
- name: DEBUG
debug:
msg: "{{ json | from_json | json_query(jq) }}"
它返回以下内容
ok: [localhost] => {
"msg": [
{
"name": "Ted's Pizza - 720895714702",
"templateid": "24663"
}
]
}
我需要更进一步,当name
的值包含Pizza
时,我需要它只返回末尾的12位数字.因此,返回输出将如下所示
ok: [localhost] => {
"msg": "720895714702"
}
思想?