Open msilveirabr opened 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?
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
COLLECTION VERSION
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
ACTUAL RESULTS
instance dictionary containing null value hw_guest_id when called immediately after a snapshot revert.