On Thu, 26 Mar 2020 11:43:33 -0700 (PDT) jean-christophe manciot <[email protected]> wrote:
> Let’s suppose the following data structure:
> - domain_definition:
> - name: server11
> cluster: cluster1
> port: '8080'
> - name: server12
> cluster: cluster2
> port: '8090'
> - name: server21
> cluster: cluster3
> port: '9080'
> - name: server22
> cluster: cluster4
> port: '9090'
> The goal is for example to *extract the port number when
> domain_definition.name == 'server21'.*
The playbook below
- name: test with json_query 1/2
hosts: localhost
vars:
domain_definition:
- name: server11
cluster: cluster1
port: '8080'
- name: server12
cluster: cluster2
port: '8090'
- name: server21
cluster: cluster3
port: '9080'
- name: server22
cluster: cluster4
port: '9090'
tasks:
- debug:
msg: "{{ domain_definition|
json_query('[?name==`server21`].port') }}"
gives
"msg": [
"9080"
]
HTH,
-vlado
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/20200326200247.14516554%40gmail.com.
pgpH0SDtiBObx.pgp
Description: OpenPGP digital signature
