这个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"
}
你有什么想法?
... | map(attribute='name') | map('regex_replace', '^.*(\\d*)$', '\\1')
=>... | map(attribute='name') | map('regex_replace', '^.*(\\d*)$', '\\1')
- Zeitounator