looping through azure_rm_networkinterface_facts

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.

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

the way of doing this more efficienlty is still appreciated