vmware_vm_facts: fix the support with regular ESXi

Ensure the module still work with the ESXi where CustomFieldsManager
does not exist.

From: https://www.vmware.com/support/developer/converter-sdk/conv60_apireference/vim.CustomFieldsManager.html

    The CustomFieldsManager object is used to add and remove custom fields to
    managed entities.
    The custom fields values set on managed entities are available through the
    customValue property and through the summary objects for VirtualMachine
    and HostSystem. They are not available directly through this managed object.
    This functionality is only available through VirtualCenter.

Fixes: #56071
This commit is contained in:
Gonéri Le Bouder
2019-05-03 18:08:42 -04:00
parent 21d4e239b4
commit cf78759f5b
7 changed files with 33 additions and 18 deletions

View File

@@ -3,6 +3,15 @@
# Copyright, (c) 2018, Fedor Vompe <f.vompe@comptek.ru>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- when: vcsim is not defined
block:
- name: Get facts from a given ESXi
vmware_vm_facts:
validate_certs: false
hostname: '{{ esxi1 }}'
username: '{{ hostvars[esxi1].ansible_user }}'
password: '{{ hostvars[esxi1].ansible_password }}'
- import_role:
name: prepare_vmware_tests
vars:
@@ -20,20 +29,22 @@
register: vm_facts_0001
- debug: var=vm_facts_0001
- set_fact:
first_vm: "{{ vm_facts_0001['virtual_machines'][0] }}"
- &vm_fact_check
name: Verify if VM facts exist
assert:
that:
- first_vm.esxi_hostname is defined
- first_vm.guest_fullname is defined
- first_vm.ip_address is defined
- first_vm.mac_address is defined
- first_vm.power_state is defined
- first_vm.uuid is defined
- first_vm.vm_network is defined
- "item.esxi_hostname is defined"
- "item.guest_fullname is defined"
- "item.ip_address is defined"
- "item.mac_address is defined"
- "item.power_state is defined"
- "item.uuid is defined"
- "item.vm_network is defined"
with_items:
- "{{ vm_facts_0001.virtual_machines | json_query(query) }}"
vars:
query: "[?guest_name=='DC0_H0_VM0']"
- <<: *vm_data
name: Get facts about available vms in check mode
@@ -48,7 +59,7 @@
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
name: "{{ first_vm.guest_name }}"
name: "DC0_H0_VM0"
register: folder_path_info
- set_fact: