vmware_guest requires datacenter to display VM's facts

1,733 views
Skip to first unread message

Diego Puertas

unread,
Apr 4, 2017, 8:37:02 PM4/4/17
to Ansible Project
Hello All,

I'm using Ansible 2.3 RC2.

According to the sample comments in the code (https://github.com/ansible/ansible-modules-extras/blob/devel/cloud/vmware/vmware_guest.py), this is all I need to get a VM facts:

#
# Gather facts only
#
    - name: gather the VM facts
      vmware_guest:
        validate_certs: False
        hostname: 192.168.1.209
        username: admini...@vsphere.local
        password: vmware
        name: testvm_2
        esxi_hostname: 192.168.1.117
      register: facts

But when I run my playbook:

- name: Gather Facts about the VMs
  hosts: modify
  gather_facts: False
  connection: local
  vars_files:
  - group_vars/vault/lab_credentials.yml
  tasks:
  - name: gather the VM facts
    vmware_guest:
      validate_certs: False
      hostname: "{{ vcenter_hostname }}"
      username: "{{ vcenter_user }}"
      password: "{{ vcenter_passwd }}"
      name: "{{ guest_name }}"
      esxi_hostname: "{{ guest_esxhost }}"
    register: facts

It asks me for the datacenter name:

"No datacenter named ha-datacenter was found"

I give it the datacenter name in the playbook, but it complaints about datastore name not specified:

"Failed to find a matching datastore"


Following down down this path I realize that Ansible is trying to create a VM. Why? What am I missing? It is exactly the same code from the samples...

Kai Stian Olstad

unread,
Apr 5, 2017, 6:28:59 AM4/5/17
to ansible...@googlegroups.com
On 04.04.2017 23:01, Diego Puertas wrote:
> Hello All,
>
> I'm using Ansible 2.3 RC2.
>
> According to the sample comments in the code
> (https://github.com/ansible/ansible-modules-extras/blob/devel/cloud/vmware/vmware_guest.py),
> this is all I need to get a VM facts:

ansible-module-core and ansible-module-extras is merged in the Ansible
code so they are not in use anymore.
Please use the official documentation instead.
https://docs.ansible.com/ansible/list_of_cloud_modules.html#vmware

It's a new module that handles facts in 2.3.

--
Kai Stian Olstad

Diego Puertas

unread,
Apr 5, 2017, 11:12:32 AM4/5/17
to Ansible Project, ansible-pr...@olstad.com
OK, now I'm using the vmware_guest_facts module, which seems to be the way to gather facts now. I'm using the exact same syntax as the example, still doesn't work, Ansible asks me for the datacenter name, which is not included in the example:

- name: Gather Facts about the VMs
  hosts: modify
  gather_facts: False
  connection: local
  vars_files:
  - group_vars/vault/lab_credentials.yml
  tasks:
  - name: gather the VM facts
    vmware_guest_facts:

      validate_certs: False
      hostname: "{{ vcenter_hostname }}"
      username: "{{ vcenter_user }}"
      password: "{{ vcenter_passwd }}"
      # name: "{{ guest_name }}"
      # name: ansclient111
      uuid: 502fa037-6612-a282-a2c7-0f08bd17f75b
    register: facts

Kai Stian Olstad

unread,
Apr 5, 2017, 11:21:55 AM4/5/17
to ansible...@googlegroups.com
On 05. april 2017 17:12, Diego Puertas wrote:
> OK, now I'm using the vmware_guest_facts module, which seems to be the way
> to gather facts now. I'm using the exact same syntax as the example, still
> doesn't work, Ansible asks me for the datacenter name, which is not
> included in the example:

https://docs.ansible.com/ansible/vmware_guest_facts_module.html#options
say datacenter is required, so probably error in the example.
So just add it and see if it works.


--
Kai Stian Olstad

Diego Puertas

unread,
Apr 5, 2017, 11:26:21 AM4/5/17
to Ansible Project, ansible-pr...@olstad.com
If I give it the datacenter, then it complaints about: "msg": "Unable to gather facts for non-existing VM ansclient111"

However, if I try with vsphere_guest, it works:

- name: gather vm facts

  hosts: modify
  gather_facts: False
  connection: local
  vars_files:
  - group_vars/vault/lab_credentials.yml
  tasks:
  - name: Getting some Facts
    vsphere_guest:
          vcenter_hostname: "{{ vcenter_hostname }}"
          username: "{{ vcenter_user }}"
          password: "{{ vcenter_passwd }}"
          guest: "{{ guest_name }}"
          vmware_guest_facts: true
          validate_certs: no
    register: vmguest_facts
    tags: vmfacts
  - name: debug facts
    debug: msg="vmguest facts are {{ vmguest_facts }}"
    tags: vmfacts

Diego Puertas

unread,
Apr 5, 2017, 11:29:43 AM4/5/17
to Ansible Project, ansible-pr...@olstad.com
This is the code for the vmware_guest_facts playbook that can't find the VM:

- name: Gather Facts about the VMs
  hosts: modify
  gather_facts: False
  connection: local
  vars_files:
  - group_vars/vault/lab_credentials.yml
  tasks:
  - name: gather the VM facts
    vmware_guest_facts:
      validate_certs: False
      datacenter: "{{ vcenter_datacenter }}"

      hostname: "{{ vcenter_hostname }}"
      username: "{{ vcenter_user }}"
      password: "{{ vcenter_passwd }}"
      name: "{{ guest_name }}"
      # name: ansclient111
      # uuid: 502fa037-6612-a282-a2c7-0f08bd17f75b
    register: facts

thirsch...@gmail.com

unread,
Oct 4, 2017, 11:13:16 AM10/4/17
to Ansible Project
I can confirm everything, I have exactly the same problem.

Michael Gimm

unread,
Sep 6, 2018, 3:57:26 PM9/6/18
to Ansible Project
Hi guys

I still have this same issue even on a 2.6.3 version of Ansible and a 6.7 vSphere system
vsphere_guest works, vmware_guest_facts does not.
Any progress or hints from the group would be most welcome :0)
Thanks
Reply all
Reply to author
Forward
0 new messages