0
votes

I'm playing around with Ansible VMWare Modules and tried to get all the Information from ESXi Hosts from a vCenter.

With the Module vmware_host_facts it should be possible.

But when I run a Playbook with the following configuration, I only get the Information of one Host back - and not all. In this vCenter there are about 20 Hosts.

Playbook:

- name: Gather vmware host facts
  vmware_host_facts:
    hostname: vCenter_IP
    username: username
    password: password
  register: host_facts
  delegate_to: localhost

In the Documentation it tells me, that the hostname can also be a vCenter IP.

Resource: http://docs.ansible.com/ansible/latest/modules/vmware_host_facts_module.html#vmware-host-facts

Is that module not the correct one to gather all host information from a vCenter? Or is there a "hidden trick", which I am missing?

Thanks a lot!

Kind regards, M

2

2 Answers

1
votes

I got an answer on another resource. https://github.com/ansible/ansible/issues/43187

Basically you have to add the Hostnames as a list to the Task.

Example:

       - name: Gather vmware host facts
         vmware_host_facts:
         hostname: "{{ item.esxi_hostname }}"
         username: "{{ item.esxi_user }}"
         password: "{{ item.esxi_pass }}"
         validate_certs: no
      register: host_facts
      delegate_to: localhost
      with_items:
         - {esxi_hostname: hostname_1, esxi_user: username_host_1, esxi_pass: pass_host_1}
         - {esxi_hostname: hostname_2, esxi_user: username_host_2, esxi_pass: pass_host_2}

These Hostnames you can gather with another module - vmware_vm_facts. Here you can get the Hostnames from. I will update this with an example playbook in the near future.

0
votes

I use this module with these options, so far I have one issue if I put vcenter address it only give me first Esxi output.

- name: Somethign.
  vmware_host_facts:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_user }}'
    password: '{{ vcenter_pass }}'
    validate_certs: no
  register: all_cluster_hosts_facts
  delegate_to: localhost
- debug: var=all_cluster_hosts_facts