vsphere_guest gather_vmware_facts not returing ip addresses of vms running in esx hypervisor v5.5.0

1,354 views
Skip to first unread message

Earl Robinson

unread,
Dec 29, 2014, 2:58:59 PM12/29/14
to ansible...@googlegroups.com
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

Rich Brantingham

unread,
Oct 2, 2015, 7:45:10 AM10/2/15
to Ansible Project
Did you manage to solve this?

I'm running into the same problem, except the response I get from vmware_guest_facts contains the correct field (ipaddress), it's just populated with 'null'.

Any pointers appreciated.

Federico Alaimo

unread,
Dec 22, 2016, 12:26:25 PM12/22/16
to Ansible Project
Hello, 
I'm having the same issue here. Any solutions found? 
Thanks!

Payal Singh

unread,
Mar 22, 2017, 9:29:40 AM3/22/17
to Ansible Project
Same issue....Any solution?

daan

unread,
Mar 23, 2017, 12:07:39 PM3/23/17
to Ansible Project
Looking at vmware_gather_facts, about to be introduced in 2.3 (there is an rc1 tag if you are adventurous), Im doing something like this:

---
- name: Discover vSphere guest
  hosts: localhost
  tasks:
  - name: Gather instance facts
    vmware_guest_facts:
      hostname: "{{ ansible_env.VMWARE_SERVER }}"
      validate_certs: false
      username: "{{ ansible_env.VMWARE_USERNAME }}"
      password: "{{ ansible_env.VMWARE_PASSWORD }}"
      datacenter: "{{ nsible_env.VMWARE_DATACENTER }}"
      name: "{{ guest_name }}"
    register: instance_facts
    until: instance_facts != -1
    changed_when: false
    retries: 30
    delay: 2

  - name: Fail when no running instances are found
    fail:
      msg: "No running instances named {{ guest_name }} found!"
    when:  instance_facts.instance.ipv4 == "None"

  - name: Add vSphere host to inventory
    add_host:
      name: "{{ instance_facts.instance.ipv4 }}"
      groups: vsphere_hosts

- name: Do stuff
  gather_facts: true
  hosts: vsphere_hosts

  tasks:



Reply all
Reply to author
Forward
0 new messages