When using the gather_vmware_facts option in the vsphere_guest module :
$cat vmguest_facts.yml
---
- hosts: all
gather_facts: false
tasks:
- name: get vmguest facts
delegate_to: localhost
vsphere_guest:
vmware_guest_facts: true
vcenter_hostname: vmware
username: "{{ hostvars[inventory_hostname].ansible_vsphere_user }}"
password: "{{ hostvars[inventory_hostname].ansible_vsphere_pass }}"
guest: vmguest
register: vmguset_facts
tags: vmfacts
- name: debug facts
debug: msg="vmguest facts are {{ vmguest_facts }}"
tags: vmfacts
I get output that looks like:
$ ansible-playbook -i hosts -l vmware vmguest_facts.yml
PLAY [vmware]
*****************************************************************
TASK: [get vmguest facts]
*****************************************************
ok: [192.168.x.y -> localhost]
TASK: [debug facts]
***********************************************************
ok: [192.168.x.y] => {
"msg": "vmguest facts are {'invocation': {'module_name':
u'vsphere_guest', 'module_args': ''}, u'changed': False, u'ansible_facts':
{u'hw_name': u'vmguest', u'hw_processor_count': 2, u'hw_memtotal_mb': 2048,
u'module_hw': True, u'hw_guest_full_name': u'Ubuntu Linux (64-bit)',
u'hw_guest_id': u'ubuntu64Guest', u'hw_eth0': {u'macaddress':
u'00:0c:1f:7c:b7:1a', u'label': u'Network adapter 1', u'addresstype':
u'generated', u'summary': u'VM Network', u'macaddress_dash':
u'00-0c-1f-7c-b7-1a'}, u'hw_product_uuid':
u'564df381-ef59-9100-3c11-ba2c29cf4bfe'}}"
}
PLAY RECAP
********************************************************************
192.168.x.y : ok=2 changed=0 unreachable=0 failed=0
which excludes the ip addresses of the vm guest. However when using
pysphere directly:
$cat facts.py
#!/usr/bin/python
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
from pysphere import VIServer
server = VIServer()
server.connect("192.168.x.y", "user", "password")
vm1 = server.get_vm_by_name("vmguest")
print vm1.get_property('net')
I get all ip addresses of the vm:
$ ./facts.py
[{'ip_addresses': ['192.168.x.z', 'fc00:::3a8e:54b4:4137:9b95',
'fe80::20c:2aff:fecf:9bf1'], 'connected': True, 'network': 'VM Network',
'mac_address': '00:0c:1f:7c:b7:1a'}]
Any ideas on why the ip addresses are not returned by vmware_guest_facts?
I'm hoping to capture the guest ip address to provision services in the
guest os.
sample code is here: https://github.com/earlrob/ansible-vsphere_guest_facts
Thanks,
Earl
--
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/712cae89-3e79-4e17-96f2-734af06f01db%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.