# looping through azure\_rm\_networkinterface\_facts

**URL:** <https://forum.ansible.com/t/looping-through-azure-rm-networkinterface-facts/31461>\
**Category:** Ansible Project\
**Created:** [October 11, 2019, 3:46pm UTC](https://forum.ansible.com/t/looping-through-azure-rm-networkinterface-facts/31461 "2019-10-11T15:46:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gregory\_Edigarov](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Gregory\_Edigarov](https://forum.ansible.com/u/Gregory_Edigarov)\
**Post date:** [October 11, 2019, 3:46pm UTC](https://forum.ansible.com/t/looping-through-azure-rm-networkinterface-facts/31461/1 "2019-10-11T15:46:18Z")

</div>

Hello,

Supposing I retrive information about interfaces like this:

- name: Get network interface details newly created hosts  
azure\_rm\_networkinterface\_facts:  
resource\_group: “{{ rg\_name }}”  
name: “{{ item }}01”  
register: azure\_networkinterfaces  
loop:
- “{{ env }}-sw1-vm”
- “{{ env }}-sw2-vm”
- “{{ env }}-sw3-vm”

how can I get their private IP’s in a loop?

i.e. I want then add them to dns zone looping through something like:

loop:

- sw1

- sw2

- sw3

or something like that, and in the zone there should be  
sw1 in a 10.0.0.4  
sw2 in a 10.0.0.5  
sw3 in a 10.0.0.6

so i only need the idea of how to loop through such an object

thank you.

---

<div class="post-metadata">

**Author:** ![Gregory\_Edigarov](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Gregory\_Edigarov](https://forum.ansible.com/u/Gregory_Edigarov)\
**Post date:** [October 14, 2019, 7:45pm UTC](https://forum.ansible.com/t/looping-through-azure-rm-networkinterface-facts/31461/2 "2019-10-14T19:45:36Z")

</div>

ok, so I am answering to myself:

the key is in these lines

- name: setting facts for hostnames and ips  
set\_fact:  
names\_ips: “{{ names\_ips|default() + [{‘name’: item.ansible\_facts.azure\_networkinterfaces[0].name|regex\_replace(‘._-(.+)-._’,‘\1’),  
‘ip’: item.ansible\_facts.azure\_networkinterfaces[0].properties.ipConfigurations[0].properties.privateIPAddress }] }}”  
loop: “{{ azure\_networkinterfaces.results }}”

took me four days figuring that names\_ips should be created as |default() first

---

<div class="post-metadata">

**Author:** ![Gregory\_Edigarov](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Gregory\_Edigarov](https://forum.ansible.com/u/Gregory_Edigarov)\
**Post date:** [October 14, 2019, 7:57pm UTC](https://forum.ansible.com/t/looping-through-azure-rm-networkinterface-facts/31461/3 "2019-10-14T19:57:41Z")

</div>

the way of doing this more efficienlty is still appreciated
