# How to call registered variable data in loops?

**URL:** <https://forum.ansible.com/t/how-to-call-registered-variable-data-in-loops/37723>\
**Category:** Ansible Project\
**Created:** [March 3, 2023, 6:25pm UTC](https://forum.ansible.com/t/how-to-call-registered-variable-data-in-loops/37723 "2023-03-03T18:25:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AharonuReddy](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/aharonureddy/32/5464_2.png) [@AharonuReddy](https://forum.ansible.com/u/AharonuReddy)\
**Post date:** [March 3, 2023, 6:25pm UTC](https://forum.ansible.com/t/how-to-call-registered-variable-data-in-loops/37723/1 "2023-03-03T18:25:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [March 3, 2023, 10:02pm UTC](https://forum.ansible.com/t/how-to-call-registered-variable-data-in-loops/37723/2 "2023-03-03T22:02:09Z")

</div>

Your question can be interpreted at least two ways.  
Here are two answers, one of which may be what you’re looking for.

```auto
	---
	- 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:

```auto
	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"
	}

```
