merge json_query output

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.

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 ....?

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?

https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#selecting-from-sets-or-lists-set-theory

thanks for the advice :slight_smile: