is there any way to simplify the below json_query? here you can see that i am trying to extract three values using three setup of queries. Since i have three items in the list the value will be generated three times corresponding to the item list. is there any way to separate the value for each item ?
ClusterName: xxxx for dv-cn-c1
DomainName: xxxx for dv-cn-c1
ClusterName: xxxx for dv-cn-c2
DomainName: xxxx for dv-cn-c2
Please see my idea
- name: "set fact for policy pkg for list of devices"
set_fact:
ClusterName: "{{ fullinvt | json_query(query1) }}"
DomainName: "{{ fullinvt | json_query(query2) }}"
PolicyName: "{{ fullinvt | json_query(query3) }}"
vars:
#w query: "ansible_facts.checkpoint_servers_gateways.objects[*].policy[].\"cluster-members-access-policy-revision\"[?name == 'dev-cn-c2'].name"
query1: "ansible_facts.checkpoint_servers_gateways.objects[?\"cluster-member-names\"[?contains(@ `{{ item }}`)]].name | [0]"
query2: "ansible_facts.checkpoint_servers_gateways.objects[?\"cluster-member-names\"[?contains(@ `{{ item }}`)]].domain.name | [0]"
query3: "ansible_facts.checkpoint_servers_gateways.objects[?\"cluster-member-names\"[?contains(@ `{{ item }}`)]].policy.\"access-policy-name\" | [0]"
with_items:
- dv-cn-c1
- dv-cn-c2
- dv-cn-4
tags: ADDLAG