Hi Sebastien,
I try with a loop but the result it’s the same. Only add one of both. Learn05 (.232.141)
The loop:
`
-
name: DEBUG Show inventory_hostname
debug: msg=“inventory_hostname {{inventory_hostname}}”
-
name: Add_host with Loop
add_host:
name: “{{item.value.ipv4}}”
groups: in-memory-vms
ansible_ssh_host: “{{item.value.ipv4}}”
ansible_distribution: “CentOS”
ansible_system: “Linux”
ansible_ssh_private_key_file: /root/.ssh/ansible.pem
with_dict: “{{ instance_facts }}”
when: item.key in [‘instance’]
changed_when: false
`
When execute the new playbook, only added learn05, but the debug in “TASK [vmware : DEBUG Show inventory_hostname]” show two hosts.
In the common role I added a debug line “TASK [common : debug]” to show all groups outside of vmware role. If you can see the in-memory-vms group have only one IP learn05 (.232.141)
[root@learn01 ansible]# ./createvm.yml
`
PLAY [centos-vms] ***********************************************************************************************************************************************************************************************************************
TASK [vmware : include_tasks] ***********************************************************************************************************************************************************************************************************
included: /var/adm/ssoo/opt/ansible/roles/vmware/tasks/create_vms_from_template.yml for learn05, learn06
TASK [vmware : Create VM from Template] *************************************************************************************************************************************************************************************************
changed: [learn06 → localhost]
changed: [learn05 → localhost]
TASK [vmware : Espera asignacion de IP via DHCP] ****************************************************************************************************************************************************************************************
Pausing for 60 seconds
(ctrl+C then ‘C’ = continue early, ctrl+C then ‘A’ = abort)
ok: [learn05]
TASK [vmware : Gather instance facts] ***************************************************************************************************************************************************************************************************
ok: [learn06]
ok: [learn05]
TASK [vmware : DEBUG Show inventory_hostname] *******************************************************************************************************************************************************************************************
ok: [learn05] => {
“msg”: “inventory_hostname learn05”
}
ok: [learn06] => {
“msg”: “inventory_hostname learn06”
}
TASK [vmware : Add_host with Loop] ******************************************************************************************************************************************************************************************************
ok: [learn05] => (item={‘key’: u’instance’, ‘value’: {u’hw_name’: u’learn05’, u’hw_power_status’: u’poweredOn’, u’hw_processor_count’: 1, u’hw_memtotal_mb’: 256, u’module_hw’: True, u’snapshots’: , u’customvalues’: {}, u’hw_guest_full_name’: u’CentOS 4/5/6/7 (64-bit)‘, u’hw_interfaces’: [u’eth0’], u’hw_guest_id’: u’centos64Guest’, u’current_snapshot’: None, u’ipv6’: None, u’guest_tools_version’: u’10249’, u’hw_eth0’: {u’macaddress’: u’00:50:56:81:16:fe’, u’addresstype’: u’assigned’, u’macaddress_dash’: u’00-50-56-81-16-fe’, u’label’: u’Network adapter 1’, u’ipaddresses’: [u’50.0.232.141’], u’summary’: u’DVSwitch: 79 24 01 50 c4 9c af f0-ce 89 4a 9a 00 1a d2 e8’}, u’hw_product_uuid’: u’4201f0a4-fa12-f243-a715-227d401193bf’, u’annotation’: u’‘, u’guest_tools_status’: u’guestToolsRunning’, u’ipv4’: u’50.0.232.141’}})
skipping: [learn05] => (item={‘key’: ‘attempts’, ‘value’: 1})
skipping: [learn05] => (item={‘key’: ‘changed’, ‘value’: False})
skipping: [learn05] => (item={‘key’: u’failed’, ‘value’: False})
PLAY [in-memory-vms] ********************************************************************************************************************************************************************************************************************
TASK [common : debug] *******************************************************************************************************************************************************************************************************************
ok: [50.0.232.141] => {
“groups”: {
“all”: [
“learn05”,
“learn06”,
“taurus”,
“learn01”,
“learn02”,
“learn03”,
“learn04”,
“50.0.232.141”
],
“centos-vms”: [
“learn05”,
“learn06”
],
“in-memory-vms”: [
“50.0.232.141”
],
“solaris”: [
“taurus”
],
“ungrouped”:
}
}
…
…
…
PLAY RECAP ******************************************************************************************************************************************************************************************************************************
50.0.232.141 : ok=14 changed=0 unreachable=0 failed=0
learn05 : ok=6 changed=1 unreachable=0 failed=0
learn06 : ok=4 changed=1 unreachable=0 failed=0
`