ansible-collections / community.vmware

Ansible Collection for VMware
GNU General Public License v3.0
348 stars 339 forks source link

vmware_guest_tools_wait should wait for instance.hw_guest_id #1458

Open msilveirabr opened 2 years ago

msilveirabr commented 2 years ago
SUMMARY

I believe that vmware_guest_tools_wait should wait until instance.hw_guest_id is not null ( ansible test "is not none" ). In a lab playbook I built, I got a loop of VM snapshot restore ( instead of deploying clone ), followed by vmware_guest_info to get hw_guest_id to use in a when statement, and started to get inconsistent results from subsequent vmware_guest_file_operation and / or vmware_vm_shell ( copy generated template to configure vm guest networking ). The guest VMs hw_guest_id should always be returned as windows9Server64Guest in this lab setup.

I spent a LONG time (days) narrowing this down the issue to the "instance" dictionary returned from these modules. Unfortunately, I don't have the time to spend trying to create a PR right now ( I have other PR for sendkeys here waiting for me to find some time to merge with ALT keys ).

Is it possible to configure a VM wihtout declaring guest_id? If not (AFAIK), then vmware_guest_tools_wait and possibly vmware_guest_info should both wait "until hw_guest_id is not null" before returning instance dict.

Or at leat there should be some parameter like "wait_for_guest_id" to toggle a loop to wait for hw_guest_id to be correctly populated!?

I'm not sure about "hw_guest_full_name", but "hw_guest_id" should not depend on vmware tools, it's already in the vmx file... this issue might be upstream, not sure how this instance dict is populated.

How often I get caught by this? Not sure... sometimes my tests turned to be 2 out of 5, other times 1 out of 10.... It happens at least once in every loop of my tests. And I believe others might be "just about" to get bitten by this issue.

ISSUE TYPE
COMPONENT NAME

vmware_guest_tools_wait vmware_guest_info

ANSIBLE VERSION
ansible [core 2.12.7]
  config file = /home/livreti/playbooks/windows-domain/ansible.cfg
  configured module search path = ['/home/livreti/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.10/site-packages/ansible
  ansible collection location = /home/livreti/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.10.6 (main, Aug  2 2022, 00:00:00) [GCC 12.1.1 20220507 (Red Hat 12.1.1-1)]
  jinja version = 3.0.3
  libyaml = True
COLLECTION VERSION
# /home/livreti/.ansible/collections/ansible_collections
Collection       Version
---------------- -------
community.vmware 2.8.0  
CONFIGURATION
OS / ENVIRONMENT

guest OS : Windows 2019 ansible host: Fedora Core 36

STEPS TO REPRODUCE

loop a revert to latest snapshot with subsequent calls to vmware_guest_tools_wait and vmware_guest_info.

EXPECTED RESULTS

instance dictionary containing correct hw_guest_id

            "hw_guest_full_name": "Microsoft Windows Server 2016 or later (64-bit)",
            "hw_guest_ha_state": null,
            "hw_guest_id": "windows9Server64Guest",
ACTUAL RESULTS

instance dictionary containing null value hw_guest_id when called immediately after a snapshot revert.

            "hw_guest_full_name": "",
            "hw_guest_ha_state": null,
            "hw_guest_id": null,
msilveirabr commented 2 years ago

OK, vmware_guest_tools_wait will obviously fail when waiting for a powered-off VM. But, vmware_guest_info also fails to return hw_guest_id of powered-off VMs...

- name: Gather VM info
  delegate_to: localhost
  community.vmware.vmware_guest_info:
    validate_certs: "{{ vsphere_validate_certs }}"
    hostname: "{{ vsphere_hostname }}"
    username: "{{ vsphere_username }}"
    password: "{{ vsphere_password }}"
    datacenter: "{{ vsphere_datacenter }}"
    name: "{{ vm_name }}"
  register: vm_info
  until: vm_info.instance.hw_guest_id is not none
  retries: 6
  delay: 10
TASK [vsphere : Gather VM info] *************************************************************************************************************************
Tuesday 13 September 2022  00:42:23 -0300 (0:00:00.123)       0:00:04.151 ***** 
FAILED - RETRYING: [vcenter.localdomain -> localhost]: Gather VM info (6 retries left).
FAILED - RETRYING: [vcenter.localdomain -> localhost]: Gather VM info (5 retries left).
FAILED - RETRYING: [vcenter.localdomain -> localhost]: Gather VM info (4 retries left).
FAILED - RETRYING: [vcenter.localdomain -> localhost]: Gather VM info (3 retries left).
FAILED - RETRYING: [vcenter.localdomain -> localhost]: Gather VM info (2 retries left).
FAILED - RETRYING: [vcenter.localdomain -> localhost]: Gather VM info (1 retries left).

Isn't vmware_guest_info supposed to return hw_guest_id on a poweredoff VM?