Uploaded image for project: 'Ansible Cloud Automation'
  1. Ansible Cloud Automation
  2. ACA-1612

[vmware.vmware_rest/387] KeyError exception in build_full_device_list

XMLWordPrintable

    • False
    • Hide

      None

      Show
      None
    • False

      https://github.com/ansible-collections/vmware.vmware_rest/issues/387

              1. SUMMARY
                I get a Python KeyError exception. Please catch this error and provide a useful error message.

      ```
      TASK [Add second disk (REST)] ******************************************************************************************************************************************************************************************
      fatal: [grohmann-src-168]: FAILED! => changed=false
      msg:

      • 2-
        File "/usr/lib64/python3.10/runpy.py", line 196, in _run_module_as_main
        return _run_code(code, main_globals, None,
      • 2-
        File "/usr/lib64/python3.10/runpy.py", line 86, in _run_code
        exec(code, run_globals)
      • 2-
        File "/tmp/ansible_vmware.vmware_rest.vcenter_vm_hardware_disk_payload_qx_9n8yt/ansible_vmware.vmware_rest.vcenter_vm_hardware_disk_payload.zip/ansible_collections/cloud/common/plugins/module_utils/turbo/server.py", line 395, in <module>
      • 2-
        File "/tmp/ansible_vmware.vmware_rest.vcenter_vm_hardware_disk_payload_qx_9n8yt/ansible_vmware.vmware_rest.vcenter_vm_hardware_disk_payload.zip/ansible_collections/cloud/common/plugins/module_utils/turbo/server.py", line 372, in start
      • 2-
        File "/usr/lib64/python3.10/asyncio/base_events.py", line 603, in run_forever
        self._run_once()
      • 2-
        File "/usr/lib64/python3.10/asyncio/base_events.py", line 1899, in _run_once
        handle._run()
      • 2-
        File "/usr/lib64/python3.10/asyncio/events.py", line 80, in _run
        self._context.run(self._callback, *self._args)
      • 2-
        File "/tmp/ansible_vmware.vmware_rest.vcenter_vm_hardware_disk_payload_qx_9n8yt/ansible_vmware.vmware_rest.vcenter_vm_hardware_disk_payload.zip/ansible_collections/cloud/common/plugins/module_utils/turbo/server.py", line 342, in handle
      • 2-
        File "/tmp/ansible_vmware.vmware_rest.vcenter_vm_hardware_disk_payload_qx_9n8yt/ansible_vmware.vmware_rest.vcenter_vm_hardware_disk_payload.zip/ansible_collections/cloud/common/plugins/module_utils/turbo/server.py", line 297, in run_as_module
      • -
        Traceback (most recent call last):
        File "/tmp/ansible_vmware.vmware_rest.vcenter_vm_hardware_disk_payload_qx_9n8yt/ansible_vmware.vmware_rest.vcenter_vm_hardware_disk_payload.zip/ansible_collections/cloud/common/plugins/module_utils/turbo/server.py", line 201, in run
        File "/tmp/ansible_vmware.vmware_rest.vcenter_vm_hardware_disk_payload_qx_9n8yt/ansible_vmware.vmware_rest.vcenter_vm_hardware_disk_payload.zip/ansible_collections/vmware/vmware_rest/plugins/modules/vcenter_vm_hardware_disk.py", line 333, in main
        result = await entry_point(module, session)
        File "/tmp/ansible_vmware.vmware_rest.vcenter_vm_hardware_disk_payload_qx_9n8yt/ansible_vmware.vmware_rest.vcenter_vm_hardware_disk_payload.zip/ansible_collections/vmware/vmware_rest/plugins/modules/vcenter_vm_hardware_disk.py", line 358, in entry_point
        return await func(module.params, session)
        File "/tmp/ansible_vmware.vmware_rest.vcenter_vm_hardware_disk_payload_qx_9n8yt/ansible_vmware.vmware_rest.vcenter_vm_hardware_disk_payload.zip/ansible_collections/vmware/vmware_rest/plugins/modules/vcenter_vm_hardware_disk.py", line 386, in _create
        _json = await exists(
        File "/tmp/ansible_vmware.vmware_rest.vcenter_vm_hardware_disk_payload_qx_9n8yt/ansible_vmware.vmware_rest.vcenter_vm_hardware_disk_payload.zip/ansible_collections/vmware/vmware_rest/plugins/module_utils/vmware_rest.py", line 369, in exists
        full_devices = await build_full_device_list(session, per_id_url, devices)
        File "/tmp/ansible_vmware.vmware_rest.vcenter_vm_hardware_disk_payload_qx_9n8yt/ansible_vmware.vmware_rest.vcenter_vm_hardware_disk_payload.zip/ansible_collections/vmware/vmware_rest/plugins/module_utils/vmware_rest.py", line 294, in build_full_device_list
        value = device_list["value"]
        KeyError: 'value'
        ```

      I extended to code locally to print the content of the `device_list` structure.

      ```
      284 async def build_full_device_list(session, url, device_list):
      285 import asyncio
      286
      287 device_ids = []
      288
      289 if isinstance(device_list, list):
      290 value = device_list
      291 else: # 7.0.2 <
      292 s=open('/tmp/error.txt', mode='w')
      293 import pprint; pprint.pprint(device_list, stream=s)
      294 value = device_list["value"]
      295 for i in value:
      296 # Content library returns string

      {"value": "library_id"}

      297 if isinstance(i, str):
      298 device_ids.append
      299 continue
      300 fields = list(i.values())
      301 if len(fields) != 1:
      302 # The list already comes with all the details
      303 return device_list
      304 device_ids.append(fields[0])
      305
      306 tasks = [
      307 asyncio.ensure_future(get_device_info(session, url, _id)) for _id in device_ids
      308 ]
      309
      310 return [await i for i in tasks]
      ```

      ```

      1. cat /tmp/error.txt
        Unknown macro: {'error_type'}

        ```

              1. ISSUE TYPE
      • Bug Report
              1. COMPONENT NAME
                vmware_rest.vcenter_vm_hardware_disk
              1. ANSIBLE VERSION
                <!--- Paste verbatim output from "ansible --version" between quotes -->
                ```paste below
                ansible --version
                ansible [core 2.13.7]
                config file = /home/i10122719/Projects/ansible-sles-upgrade/ansible.cfg
                configured module search path = ['/home/i10122719/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
                ansible python module location = /home/i10122719/virtualenv/lib64/python3.10/site-packages/ansible
                ansible collection location = /home/i10122719/.ansible/collections:/usr/share/ansible/collections
                executable location = /home/i10122719/virtualenv/bin/ansible
                python version = 3.10.8 (main, Oct 28 2022, 17:28:32) [GCC]
                jinja version = 3.1.2
                libyaml = True
                ```
              1. COLLECTION VERSION
                ```paste below
      1. ansible-galaxy collection list | grep vmware
        community.vmware 2.10.1
        vmware.vmware_rest 2.2.0
        community.vmware 2.10.1
        vmware.vmware_rest 2.2.0
        community.vmware 3.2.0
        ```
              1. CONFIGURATION
                <!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes -->
                ```paste below
                CACHE_PLUGIN(/home/carsten/Projects/upgrade/ansible.cfg) = jsonfile
                CACHE_PLUGIN_CONNECTION(/home/carsten/Projects/upgrade/ansible.cfg) = ./facts
                CACHE_PLUGIN_TIMEOUT(/home/carsten/Projects/upgrade/ansible.cfg) = 28800
                DEFAULT_GATHERING(/home/carsten/Projects/upgrade/ansible.cfg) = smart
                DEFAULT_HOST_LIST(/home/carsten/Projects/upgrade/ansible.cfg) = ['/home/carsten/Projects/upgrade/hosts']
                DEFAULT_ROLES_PATH(/home/carsten/Projects/upgrade/ansible.cfg) = ['/home/carsten/Projects/upgrade/roles']
                DEFAULT_STDOUT_CALLBACK(/home/carsten/Projects/upgrade/ansible.cfg) = yaml
                HOST_KEY_CHECKING(/home/carsten/Projects/upgrade/ansible.cfg) = False
                INTERPRETER_PYTHON(/home/carsten/Projects/upgrade/ansible.cfg) = auto_silent
                ```
              1. OS / ENVIRONMENT
      • OS

      ```

      1. cat /etc/os-release
        NAME="SLES"
        VERSION="15-SP4"
        VERSION_ID="15.4"
        PRETTY_NAME="SUSE Linux Enterprise Server 15 SP4"
        ID="sles"
        ID_LIKE="suse"
        ANSI_COLOR="0;32"
        CPE_NAME="cpe:/o:suse:sles:15:sp4"
        DOCUMENTATION_URL="https://documentation.suse.com/"
        ```
      • vSphere: `vSphere Client version 7.0.3.01100`
      • Hypervisor: `VMware ESXi, 6.7.0, 17700523`
              1. STEPS TO REPRODUCE
                <!--- Describe exactly how to reproduce the problem, using a minimal test-case -->

      <!--- Paste example playbooks or commands between quotes below -->
      ```yaml

      • name: Add second disk (REST)
        block:
      • name: Add second disk (REST)
        vmware.vmware_rest.vcenter_vm_hardware_disk:
        vcenter_hostname: '{{ vcenter_hostname }}'
        vcenter_username: '{{ vcenter_username }}'
        vcenter_password: '{{ vcenter_password }}'
        vcenter_validate_certs: no
        vm: myvm1
        type: SATA
        new_vmdk:
        capacity: 5 * 1024 * 1024 * 1024
        register: my_new_disk
        ```

              Unassigned Unassigned
              gosriniv@redhat.com Gomathi selvi Srinivasan
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: