diff --git a/changelogs/fragments/403_fix_vmware_guest_info.yml b/changelogs/fragments/403_fix_vmware_guest_info.yml new file mode 100644 index 000000000..1392d62c4 --- /dev/null +++ b/changelogs/fragments/403_fix_vmware_guest_info.yml @@ -0,0 +1,2 @@ +minor_changes: +- vmware_guest_info - Fix get tags API call (https://github.com/ansible-collections/community.vmware/issues/403). diff --git a/plugins/modules/vmware_guest_info.py b/plugins/modules/vmware_guest_info.py index f2bde6482..d9da3d9ea 100644 --- a/plugins/modules/vmware_guest_info.py +++ b/plugins/modules/vmware_guest_info.py @@ -293,10 +293,11 @@ def main(): " - https://code.vmware.com/web/sdk/60/vcloudsuite-python") vm_rest_client = VmwareTag(module) + dynamic_obj = DynamicID(type='VirtualMachine', id=vm._moId) instance.update( tags=vm_rest_client.get_vm_tags(vm_rest_client.tag_service, vm_rest_client.tag_association_svc, - vm_mid=vm._moId) + vm_mid=dynamic_obj) ) module.exit_json(instance=instance) except Exception as exc: diff --git a/tests/integration/targets/vmware_tag/tasks/tag_manager_ops.yml b/tests/integration/targets/vmware_tag/tasks/tag_manager_ops.yml index 14158cfca..66e5c7cde 100644 --- a/tests/integration/targets/vmware_tag/tasks/tag_manager_ops.yml +++ b/tests/integration/targets/vmware_tag/tasks/tag_manager_ops.yml @@ -53,6 +53,22 @@ that: - tag_manager_ops.changed + - name: Get tags from a virtual machine + vmware_guest_info: + hostname: "{{ vcenter_hostname }}" + username: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + validate_certs: no + name: "{{ vm_name }}" + register: r + + - name: Check if tag information is available + assert: + that: + - not r.changed + - r['instance']['tags'] is defined + - "{{ Tag_Name[0] in r['instance']['tags'] }}" + - <<: *tag_assign name: Add tags to a virtual machine again