Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix guest info bug #27

Conversation

mikemorency
Copy link
Collaborator

SUMMARY

Fixes ACA-1564

This PR fixes an exception thrown when specifying a guest name in the guest_info module. The VM.FilterSpec function used to apply the name filter was incorrectly qualified.

Additionally, the return value from the _get_vm function can be None, a single dictionary, or a list of dictionaries. I added logic to catch non-iterable values and fix them so the following for vm in vms loop will not fail

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

guest_info

ADDITIONAL INFORMATION
---
- hosts: localhost
  gather_facts: false
  tasks:
    - name: Gather guest info
      vmware.vmware.guest_info:
        validate_certs: false
        hostname: "{{ vcenter_hostname }}"
        username: "{{ vcenter_username }}"
        password: "{{ vcenter_password }}"
        guest_name: foo

Before:

PLAY [localhost] *******************************************************************************************************************************************************************************************************************************************

TASK [Gather guest info] ***********************************************************************************************************************************************************************************************************************************
task path: /home/mikemorency/git/vmware.vmware/test.yml:5
<mikemorency> ESTABLISH LOCAL CONNECTION FOR USER: mikemorency
<mikemorency> EXEC /bin/sh -c 'echo ~mikemorency && sleep 0'
<mikemorency> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/mikemorency/.ansible/tmp `"&& mkdir "` echo /home/mikemorency/.ansible/tmp/ansible-tmp-1716471751.9657607-1985382-207808250187122 `" && echo ansible-tmp-1716471751.9657607-1985382-207808250187122="` echo /home/mikemorency/.ansible/tmp/ansible-tmp-1716471751.9657607-1985382-207808250187122 `" ) && sleep 0'
Using module file /home/mikemorency/.ansible/collections/ansible_collections/vmware/vmware/plugins/modules/guest_info.py
<mikemorency> PUT /home/mikemorency/.ansible/tmp/ansible-local-1985379jj99kqmf/tmp344d9qh4 TO /home/mikemorency/.ansible/tmp/ansible-tmp-1716471751.9657607-1985382-207808250187122/AnsiballZ_guest_info.py
<mikemorency> EXEC /bin/sh -c 'chmod u+x /home/mikemorency/.ansible/tmp/ansible-tmp-1716471751.9657607-1985382-207808250187122/ /home/mikemorency/.ansible/tmp/ansible-tmp-1716471751.9657607-1985382-207808250187122/AnsiballZ_guest_info.py && sleep 0'
<mikemorency> EXEC /bin/sh -c '/home/mikemorency/miniconda3/envs/vmware.vmware/bin/python /home/mikemorency/.ansible/tmp/ansible-tmp-1716471751.9657607-1985382-207808250187122/AnsiballZ_guest_info.py && sleep 0'
<mikemorency> EXEC /bin/sh -c 'rm -f -r /home/mikemorency/.ansible/tmp/ansible-tmp-1716471751.9657607-1985382-207808250187122/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/home/mikemorency/.ansible/tmp/ansible-tmp-1716471751.9657607-1985382-207808250187122/AnsiballZ_guest_info.py", line 107, in <module>
    _ansiballz_main()
  File "/home/mikemorency/.ansible/tmp/ansible-tmp-1716471751.9657607-1985382-207808250187122/AnsiballZ_guest_info.py", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/mikemorency/.ansible/tmp/ansible-tmp-1716471751.9657607-1985382-207808250187122/AnsiballZ_guest_info.py", line 47, in invoke_module
    runpy.run_module(mod_name='ansible_collections.vmware.vmware.plugins.modules.guest_info', init_globals=dict(_module_fqn='ansible_collections.vmware.vmware.plugins.modules.guest_info', _modlib_path=modlib_path),
  File "/home/mikemorency/miniconda3/envs/vmware.vmware/lib/python3.10/runpy.py", line 209, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/home/mikemorency/miniconda3/envs/vmware.vmware/lib/python3.10/runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/home/mikemorency/miniconda3/envs/vmware.vmware/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_vmware.vmware.guest_info_payload_lbnlkypm/ansible_vmware.vmware.guest_info_payload.zip/ansible_collections/vmware/vmware/plugins/modules/guest_info.py", line 175, in <module>
  File "/tmp/ansible_vmware.vmware.guest_info_payload_lbnlkypm/ansible_vmware.vmware.guest_info_payload.zip/ansible_collections/vmware/vmware/plugins/modules/guest_info.py", line 170, in main
  File "/tmp/ansible_vmware.vmware.guest_info_payload_lbnlkypm/ansible_vmware.vmware.guest_info_payload.zip/ansible_collections/vmware/vmware/plugins/modules/guest_info.py", line 117, in get_guest_info
  File "/tmp/ansible_vmware.vmware.guest_info_payload_lbnlkypm/ansible_vmware.vmware.guest_info_payload.zip/ansible_collections/vmware/vmware/plugins/modules/guest_info.py", line 143, in _get_vm
  File "/home/mikemorency/miniconda3/envs/vmware.vmware/lib/python3.10/site-packages/vmware/vapi/bindings/stub.py", line 443, in __getattr__
    return getattr(self._stub_factory, name)
  File "/home/mikemorency/miniconda3/envs/vmware.vmware/lib/python3.10/site-packages/vmware/vapi/bindings/stub.py", line 413, in __getattribute__
    result = object.__getattribute__(self, name)
AttributeError: 'StubFactory' object has no attribute 'VM'
fatal: [mikemorency]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/home/mikemorency/.ansible/tmp/ansible-tmp-1716471751.9657607-1985382-207808250187122/AnsiballZ_guest_info.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/home/mikemorency/.ansible/tmp/ansible-tmp-1716471751.9657607-1985382-207808250187122/AnsiballZ_guest_info.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/mikemorency/.ansible/tmp/ansible-tmp-1716471751.9657607-1985382-207808250187122/AnsiballZ_guest_info.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.vmware.vmware.plugins.modules.guest_info', init_globals=dict(_module_fqn='ansible_collections.vmware.vmware.plugins.modules.guest_info', _modlib_path=modlib_path),\n  File \"/home/mikemorency/miniconda3/envs/vmware.vmware/lib/python3.10/runpy.py\", line 209, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/home/mikemorency/miniconda3/envs/vmware.vmware/lib/python3.10/runpy.py\", line 96, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/home/mikemorency/miniconda3/envs/vmware.vmware/lib/python3.10/runpy.py\", line 86, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_vmware.vmware.guest_info_payload_lbnlkypm/ansible_vmware.vmware.guest_info_payload.zip/ansible_collections/vmware/vmware/plugins/modules/guest_info.py\", line 175, in <module>\n  File \"/tmp/ansible_vmware.vmware.guest_info_payload_lbnlkypm/ansible_vmware.vmware.guest_info_payload.zip/ansible_collections/vmware/vmware/plugins/modules/guest_info.py\", line 170, in main\n  File \"/tmp/ansible_vmware.vmware.guest_info_payload_lbnlkypm/ansible_vmware.vmware.guest_info_payload.zip/ansible_collections/vmware/vmware/plugins/modules/guest_info.py\", line 117, in get_guest_info\n  File \"/tmp/ansible_vmware.vmware.guest_info_payload_lbnlkypm/ansible_vmware.vmware.guest_info_payload.zip/ansible_collections/vmware/vmware/plugins/modules/guest_info.py\", line 143, in _get_vm\n  File \"/home/mikemorency/miniconda3/envs/vmware.vmware/lib/python3.10/site-packages/vmware/vapi/bindings/stub.py\", line 443, in __getattr__\n    return getattr(self._stub_factory, name)\n  File \"/home/mikemorency/miniconda3/envs/vmware.vmware/lib/python3.10/site-packages/vmware/vapi/bindings/stub.py\", line 413, in __getattribute__\n    result = object.__getattribute__(self, name)\nAttributeError: 'StubFactory' object has no attribute 'VM'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

PLAY RECAP *************************************************************************************************************************************************************************************************************************************************
mikemorency : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

After:

PLAY [localhost] *******************************************************************************************************************************************************************************************************************************************

TASK [Gather guest info] ***********************************************************************************************************************************************************************************************************************************
task path: /home/mikemorency/git/vmware.vmware/test.yml:5
<mikemorency> ESTABLISH LOCAL CONNECTION FOR USER: mikemorency
<mikemorency> EXEC /bin/sh -c 'echo ~mikemorency && sleep 0'
<mikemorency> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/mikemorency/.ansible/tmp `"&& mkdir "` echo /home/mikemorency/.ansible/tmp/ansible-tmp-1716472909.6809666-1987625-162051415794280 `" && echo ansible-tmp-1716472909.6809666-1987625-162051415794280="` echo /home/mikemorency/.ansible/tmp/ansible-tmp-1716472909.6809666-1987625-162051415794280 `" ) && sleep 0'
Using module file /home/mikemorency/.ansible/collections/ansible_collections/vmware/vmware/plugins/modules/guest_info.py
<mikemorency> PUT /home/mikemorency/.ansible/tmp/ansible-local-1987622x82681yw/tmpqfvl1a5c TO /home/mikemorency/.ansible/tmp/ansible-tmp-1716472909.6809666-1987625-162051415794280/AnsiballZ_guest_info.py
<mikemorency> EXEC /bin/sh -c 'chmod u+x /home/mikemorency/.ansible/tmp/ansible-tmp-1716472909.6809666-1987625-162051415794280/ /home/mikemorency/.ansible/tmp/ansible-tmp-1716472909.6809666-1987625-162051415794280/AnsiballZ_guest_info.py && sleep 0'
<mikemorency> EXEC /bin/sh -c '/home/mikemorency/miniconda3/envs/vmware.vmware/bin/python /home/mikemorency/.ansible/tmp/ansible-tmp-1716472909.6809666-1987625-162051415794280/AnsiballZ_guest_info.py && sleep 0'
<mikemorency> EXEC /bin/sh -c 'rm -f -r /home/mikemorency/.ansible/tmp/ansible-tmp-1716472909.6809666-1987625-162051415794280/ > /dev/null 2>&1 && sleep 0'
ok: [mikemorency] => {
    "changed": false,
    "guests": [
        {
            "family": "LINUX",
            "full_name": {
                "args": "[]",
                "default_message": "Other 5.x Linux (64-bit)",
                "id": "vmsg.guestos.other5xLinux64Guest.label",
                "localized": "None",
                "params": "None"
            },
            "host_name": "foo-virtual-machine",
            "ip_address": "10.10.10.10",
            "name": "OTHER_5X_LINUX_64"
        }
    ],
    "invocation": {
        "module_args": {
            "guest_name": "foo",
            "guest_password": null,
            "guest_username": null,
            "hostname": "redacted",
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "port": 443,
            "protocol": "https",
            "proxy_host": null,
            "proxy_port": null,
            "username": "redacted",
            "validate_certs": false
        }
    }
}

PLAY RECAP *************************************************************************************************************************************************************************************************************************************************
mikemorency : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

@machacekondra machacekondra merged commit d979b28 into ansible-collections:main May 28, 2024
9 checks passed
@mikemorency mikemorency deleted the mm-bugfix/ACA-1564-guest-info-vm-name-exc branch May 28, 2024 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants