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
On Friday, October 11, 2019 at 6:46:18 PM UTC+3, Gregory Edigarov wrote:
>
> 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.
>
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/a2ec6ec2-a34a-4b35-834e-3fb3536f1d6c%40googlegroups.com.