ansible-collections / community.vmware

Ansible Collection for VMware
GNU General Public License v3.0
346 stars 334 forks source link

vmware_vm_info fails for collection 4.0.0: AttributeError: 'NoneType' object has no attribute 'ipAddress #1954

Closed wsslhllmn closed 8 months ago

wsslhllmn commented 9 months ago
SUMMARY

When using the vmware_vm_info module, to retrieve all virtual machines in a cluster, the tasks fails. This code works for collection version 3.9.0 but not for 4.0.0.

ISSUE TYPE
COMPONENT NAME

vmware_vm_info

ANSIBLE VERSION

ansible [core 2.15.0]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/runner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /home/runner/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.9.16 (main, Dec 21 2022, 10:57:18) [GCC 8.5.0 20210514 (Red Hat 8.5.0-17)] (/usr/bin/python3.9)
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION

The community collection does not appear in this output since it is retrieved from the Automation Hub at runtime using requirements.yml. Inside the container the following ones are installed:

bash-4.4# ansible-galaxy collection list

# /usr/share/ansible/collections/ansible_collections
Collection                  Version
--------------------------- -------
amazon.aws                  6.0.1
ansible.controller          4.4.0
ansible.netcommon           5.1.1
ansible.network             2.0.0
ansible.posix               1.5.4
ansible.scm                 1.0.7
ansible.security            1.1.0
ansible.snmp                1.0.1
ansible.utils               2.9.0
ansible.windows             1.14.0
ansible.yang                1.0.0
arista.eos                  6.0.1
azure.azcollection          1.14.0
cisco.asa                   4.0.1
cisco.ios                   4.6.1
cisco.iosxr                 5.0.2
cisco.nxos                  4.3.0
cloud.common                2.1.2
cloud.terraform             1.1.1
frr.frr                     2.0.2
ibm.qradar                  2.1.0
junipernetworks.junos       5.1.0
kubernetes.core             2.4.0
microsoft.ad                1.1.0
openvswitch.openvswitch     2.1.1
redhat.amq_broker           1.3.0
redhat.eap                  1.3.1
redhat.insights             1.0.7
redhat.openshift            2.3.0
redhat.redhat_csp_download  1.2.2
redhat.rhel_idm             1.10.0
redhat.rhel_system_roles    1.21.1
redhat.rhv                  2.4.2
redhat.runtimes_common      1.0.2
redhat.sap_install          1.2.1
redhat.satellite            3.10.0
redhat.satellite_operations 1.3.0
redhat.sso                  1.2.1
sap.sap_operations          1.0.4
servicenow.itsm             2.1.0
splunk.es                   2.1.0
trendmicro.deepsec          2.0.0
vmware.vmware_rest          2.3.1
vyos.vyos                   4.0.2
CONFIGURATION

ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True
CALLBACKS_ENABLED(/etc/ansible/ansible.cfg) = ['profile_tasks']
CONFIG_FILE() = /etc/ansible/ansible.cfg
DEFAULT_CALLBACK_PLUGIN_PATH(env: ANSIBLE_CALLBACK_PLUGINS) = ['/runner/artifacts/31100/callback']
DEFAULT_FORKS(env: ANSIBLE_FORKS) = 25
DEFAULT_LOAD_CALLBACK_PLUGINS(env: ANSIBLE_LOAD_CALLBACK_PLUGINS) = True
DEFAULT_STDOUT_CALLBACK(env: ANSIBLE_STDOUT_CALLBACK) = awx_display
DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = False
HOST_KEY_CHECKING(env: ANSIBLE_HOST_KEY_CHECKING) = False
INVENTORY_UNPARSED_IS_FAILED(env: ANSIBLE_INVENTORY_UNPARSED_FAILED) = True
RETRY_FILES_ENABLED(env: ANSIBLE_RETRY_FILES_ENABLED) = False
OS / ENVIRONMENT

The execution environment is based on: LABEL com.redhat.component="ubi8-minimal-container" name="ubi8-minimal" version="8.8"

bash-4.4# cat /etc/redhat-release Red Hat Enterprise Linux release 8.8 (Ootpa)

STEPS TO REPRODUCE

When using the vmware_vm_info module, to retrieve all virtual machines in a cluster, we receive the error below:

"Traceback (most recent call last):\n File \"/home/runner/.ansible/tmp/ansible-tmp-1702897038.9956489-28-276243937352167/AnsiballZ_vmware_vm_info.py\", line 107, in \n _ansiballz_main()\n File \"/home/runner/.ansible/tmp/ansible-tmp-1702897038.9956489-28-276243937352167/AnsiballZ_vmware_vm_info.py\", line 99, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"/home/runner/.ansible/tmp/ansible-tmp-1702897038.9956489-28-276243937352167/AnsiballZ_vmware_vm_info.py\", line 47, in invoke_module\n runpy.run_module(mod_name='ansible_collections.community.vmware.plugins.modules.vmware_vm_info', init_globals=dict(_module_fqn='ansible_collections.community.vmware.plugins.modules.vmware_vm_info', _modlib_path=modlib_path),\n File \"/usr/lib64/python3.9/runpy.py\", line 225, in run_module\n return _run_module_code(code, init_globals, run_name, mod_spec)\n File \"/usr/lib64/python3.9/runpy.py\", line 97, in _run_module_code\n _run_code(code, mod_globals, init_globals,\n File \"/usr/lib64/python3.9/runpy.py\", line 87, in _run_code\n exec(code, run_globals)\n File \"/tmp/ansible_community.vmware.vmware_vm_info_payload_4dn07e96/ansible_community.vmware.vmware_vm_info_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_vm_info.py\", line 475, in \n File \"/tmp/ansible_community.vmware.vmware_vm_info_payload_4dn07e96/ansible_community.vmware.vmware_vm_info_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_vm_info.py\", line 469, in main\n File \"/tmp/ansible_community.vmware.vmware_vm_info_payload_4dn07e96/ansible_community.vmware.vmware_vm_info_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_vm_info.py\", line 355, in get_virtual_machines\nAttributeError: 'NoneType' object has no attribute 'ipAddress'\n",


  - name: Get all virtual machines
    community.vmware.vmware_vm_info:
      hostname: "{{ vcenter_hostname }}"
      username: "{{ vcenter_username }}"
      password: "{{ vcenter_password }}"
      vm_type: vm
      validate_certs: "{{ validate_certs }}"
    delegate_to: localhost
    register: vm_info
    tags: always
EXPECTED RESULTS

We expect data of all virtual machines within the cluster.

ACTUAL RESULTS

"Traceback (most recent call last):\n File \"/home/runner/.ansible/tmp/ansible-tmp-1702897038.9956489-28-276243937352167/AnsiballZ_vmware_vm_info.py\", line 107, in \n _ansiballz_main()\n File \"/home/runner/.ansible/tmp/ansible-tmp-1702897038.9956489-28-276243937352167/AnsiballZ_vmware_vm_info.py\", line 99, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"/home/runner/.ansible/tmp/ansible-tmp-1702897038.9956489-28-276243937352167/AnsiballZ_vmware_vm_info.py\", line 47, in invoke_module\n runpy.run_module(mod_name='ansible_collections.community.vmware.plugins.modules.vmware_vm_info', init_globals=dict(_module_fqn='ansible_collections.community.vmware.plugins.modules.vmware_vm_info', _modlib_path=modlib_path),\n File \"/usr/lib64/python3.9/runpy.py\", line 225, in run_module\n return _run_module_code(code, init_globals, run_name, mod_spec)\n File \"/usr/lib64/python3.9/runpy.py\", line 97, in _run_module_code\n _run_code(code, mod_globals, init_globals,\n File \"/usr/lib64/python3.9/runpy.py\", line 87, in _run_code\n exec(code, run_globals)\n File \"/tmp/ansible_community.vmware.vmware_vm_info_payload_4dn07e96/ansible_community.vmware.vmware_vm_info_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_vm_info.py\", line 475, in \n File \"/tmp/ansible_community.vmware.vmware_vm_info_payload_4dn07e96/ansible_community.vmware.vmware_vm_info_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_vm_info.py\", line 469, in main\n File \"/tmp/ansible_community.vmware.vmware_vm_info_payload_4dn07e96/ansible_community.vmware.vmware_vm_info_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_vm_info.py\", line 355, in get_virtual_machines\nAttributeError: 'NoneType' object has no attribute 'ipAddress'\n",

nhojatibas commented 8 months ago

I have the same issue here.

I have a old ansible instalation, that works yet. But with a new version (python 3.11), my problem is the same registered by wsslhllmn

nhojatibas commented 8 months ago

wsslhllmn, I can solve the issue, following this : https://github.com/ansible-collections/community.vmware/pull/1919

I installed the version 4.0.1 by git (not by ansible-galaxy)

Good luck

mariolenz commented 8 months ago

I'm pretty sure this has been fixed in 4.0.1.

Please re-open this issue (or open a new one) if I'm wrong there.