On Thu, 26 Mar 2020 20:02:47 +0100 Vladimir Botka <[email protected]> wrote:
>
> 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
"selectattr" below gives the same result
- debug:
msg: "{{ domain_definition|
selectattr('name', 'regex', '^server21$')|
map(attribute= 'port')|
list }}"
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/20200326201052.16b5bd67%40gmail.com.
pgpRR4F2Rqj8g.pgp
Description: OpenPGP digital signature
