merge json_query output

469 views
Skip to first unread message

Sakshi Rathore

unread,
Mar 23, 2021, 8:02:26 AM3/23/21
to Ansible Project
hello all, 

i am getting 2 array of ips from 2 different json queries in ansible-playbook. how can i merge these 2 json queries?

in below example i want to merge jmesquery and jmesquery1 

- name: master ip list from json content
  #debug: msg="{{ input | json_query(jmesquery) }}"
  copy: content="{{ input | json_query(jmesquery) }}" dest=../ip_address.txt
  vars:
    input : "{{ lookup('template', '../cluster.txt') }}"
    target: "{{ input |  json_query(jmesquery) }}"
    jmesquery: "[*].master_group[].nodes[].private_ip"

- name: worker ip list from json content
  #debug: msg="{{ input1 | json_query(jmesquery1) }}"
  copy: content="{{ input1 | json_query(jmesquery1) }}" dest=../ip_address1.txt
  vars:
    input1 : "{{ lookup('template', '../cluster.txt') }}"
    target1: "{{ input1 |  json_query(jmesquery1) }}"
    jmesquery1: "[*].node_groups[].nodes[].private_ip"

please advise.

Dick Visser

unread,
Mar 23, 2021, 8:10:56 AM3/23/21
to ansible...@googlegroups.com
What do you mean by 'merging json queries'?
I know json data structures can be merged, but queries?

For example you can merge input and input1 into a new structure, and
then have a single json_query?
Or ....?
> --
> 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 ansible-proje...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/7b967fa6-9c7a-46d5-aea9-a7123af2ac06n%40googlegroups.com.



--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

Sakshi Rathore

unread,
Mar 23, 2021, 8:15:47 AM3/23/21
to ansible...@googlegroups.com
currently i am getting output in 2 different array: (ip addresses are dummy)

['10.32.142.156', '10.32.142.153', '10.32.31.177', '10.32.31.176', '10.32.31.175', '10.32.31.180', '10.32.31.179', '10.32.143.174',
'10.32.143.173', '10.32.143.175', '10.32.141.40', '10.32.141.37', '10.32.41.155', '10.32.41.154', '10.32.41.156', '10.32.142.157', '10.32.142.161',
'10.32.142.162', '10.32.142.151', '10.32.142.160', '10.32.144.166', '10.32.144.164', '10.32.144.167', '10.32.144.173', '10.32.144.172', '10.32.50.177',
'10.32.50.176', '10.32.50.178', '10.32.141.3', '10.32.141.2', '10.32.141.7', '10.32.141.8', '10.32.141.17', '10.32.30.195', '10.32.30.196',
'10.32.30.193', '10.32.30.194', '10.32.142.194', '10.32.142.193', '10.32.141.66', '10.32.141.68', '10.32.141.103', '10.32.141.102', '10.32.40.154',
'10.32.40.155', '10.32.40.156', '10.32.51.155', '10.32.51.156', '10.32.51.157']

['10.32.142.156',
'10.32.142.153', '10.32.31.177', '10.32.31.176', '10.32.31.175', '10.32.31.180', '10.32.31.179', '10.32.143.174', '10.32.143.173', '10.32.143.175',
'10.32.141.40', '10.32.141.37', '10.32.41.155', '10.32.41.154', '10.32.41.156', '10.32.142.157', '10.32.142.161', '10.32.142.162', '10.32.142.151',
'10.32.142.160', '10.32.144.166', '10.32.144.164', '10.32.144.167', '10.32.144.173', '10.32.144.172', '10.32.50.177', '10.32.50.176', '10.32.50.178',
'10.32.141.3', '10.32.141.2', '10.32.141.7', '10.32.141.8', '10.32.141.17', '10.32.30.195', '10.32.30.196', '10.32.30.193', '10.32.30.194',
'10.32.142.194', '10.32.142.193', '10.32.141.66', '10.32.141.68', '10.32.141.103', '10.32.141.102', '10.32.40.154', '10.32.40.155', '10.32.40.156',
'10.32.51.155', '10.32.51.156', '10.32.51.157']

i would like to merge these ips into a single array. and how can i merge  input and input1?

Dick Visser

unread,
Mar 23, 2021, 10:05:29 AM3/23/21
to ansible...@googlegroups.com

Sakshi Rathore

unread,
Mar 24, 2021, 7:56:54 AM3/24/21
to ansible...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages