Hi Team,
Could anyone please help on below query? Thank you.
I have 2 registered variables data as example below. How to call those data over the loop?
Vars:
Cluster_data: [‘cluster1’,‘cluster2’]
Aggr_data: [‘aggr1’,‘aggr2’,]
Tasks:
- name: calling var data
<module_name>:
cluster: ?? → here, I need to use ‘Cluster_data’ list
aggregate: ?? → here, I need to use ‘Aggr_data’ list
loop: ??
Once again, thank you for your help.
utoddl
(Todd Lewis)
March 3, 2023, 10:02pm
2
Your question can be interpreted at least two ways.
Here are two answers, one of which may be what you’re looking for.
---
- name: Combining lists
hosts: localhost
gather_facts: false
vars:
cluster_data: ['cluster1','cluster2']
aggr_data: ['aggr1','aggr2',]
tasks:
- name: Combine with zip
ansible.builtin.debug:
msg: "zip: {{ ','.join(item) }}"
loop: "{{ cluster_data | zip(aggr_data) }}"
- name: Combine with product
ansible.builtin.debug:
msg: "product: {{ ','.join(item) }}"
loop: "{{ cluster_data | product(aggr_data) }}"
The output from the above playbook looks like this:
PLAY [Combining lists] *****************************
TASK [Combine with zip] ****************************
ok: [localhost] => (item=['cluster1', 'aggr1']) => {
"msg": "zip: cluster1,aggr1"
}
ok: [localhost] => (item=['cluster2', 'aggr2']) => {
"msg": "zip: cluster2,aggr2"
}
TASK [Combine with product] ************************
ok: [localhost] => (item=['cluster1', 'aggr1']) => {
"msg": "product: cluster1,aggr1"
}
ok: [localhost] => (item=['cluster1', 'aggr2']) => {
"msg": "product: cluster1,aggr2"
}
ok: [localhost] => (item=['cluster2', 'aggr1']) => {
"msg": "product: cluster2,aggr1"
}
ok: [localhost] => (item=['cluster2', 'aggr2']) => {
"msg": "product: cluster2,aggr2"
}