ansible-collections / community.vmware

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

AttributeError: 'NoneType' object has no attribute 'field' when reconfiguring vm with vmware_guest #721

Closed jnm27 closed 3 years ago

jnm27 commented 3 years ago
SUMMARY

Able to create a new VM fine with vmware_guest, but when I run the same playbook again right after, it fails while "reconfiguring". I am using customvalues field, which is where it appears to be failing. This is using community version 1.8.0. If I step back to base Ansible 2.9 vmware_guest (no namespace), then it works fine. Although note that 2.9 vmware_guest always shows "changed" (it does not appear to be idempotent - please fix that also).

ISSUE TYPE
COMPONENT NAME

vmware_guest

ANSIBLE VERSION
ansible 2.9.11
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.6.8 (default, Dec  5 2019, 15:45:45) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]
CONFIGURATION
ANSIBLE_PIPELINING(/etc/ansible/ansible.cfg) = True
DEFAULT_CALLBACK_WHITELIST(/etc/ansible/ansible.cfg) = ['profile_tasks', <omit>]
DEFAULT_FORKS(/etc/ansible/ansible.cfg) = 100
DEFAULT_LOAD_CALLBACK_PLUGINS(/etc/ansible/ansible.cfg) = True
DEFAULT_LOCAL_TMP(/etc/ansible/ansible.cfg) = /tmp/.ansible_root/ansible-local-3843130le05ada
DEFAULT_STDOUT_CALLBACK(/etc/ansible/ansible.cfg) = yaml
DEFAULT_STRATEGY(/etc/ansible/ansible.cfg) = free
DEFAULT_VAULT_PASSWORD_FILE(/etc/ansible/ansible.cfg) = <omit>
DIFF_ALWAYS(/etc/ansible/ansible.cfg) = True
DIFF_CONTEXT(/etc/ansible/ansible.cfg) = 0
DISPLAY_SKIPPED_HOSTS(/etc/ansible/ansible.cfg) = False
DUPLICATE_YAML_DICT_KEY(/etc/ansible/ansible.cfg) = ignore
HOST_KEY_CHECKING(/etc/ansible/ansible.cfg) = False
INTERPRETER_PYTHON(/etc/ansible/ansible.cfg) = /usr/libexec/platform-python
LOCALHOST_WARNING(/etc/ansible/ansible.cfg) = False
MAX_FILE_SIZE_FOR_DIFF(/etc/ansible/ansible.cfg) = 10485760
OS / ENVIRONMENT

RHEL8 VMware 7.0U1 community.vmware 1.8.0

STEPS TO REPRODUCE
vmware_guest with customvalues, run once to create VM, then run once more with same parameters.
EXPECTED RESULTS

The second run succeeds and does not show "changed".

ACTUAL RESULTS
  msg: |-
    Traceback (most recent call last):
      File "/tmp/ansible_async_wrapper_payload_ab7bo1xv/ansible_async_wrapper_payload.zip/ansible/modules/utilities/logic/async_wrapper.py", line 159, in _run_module
      File "/tmp/ansible_async_wrapper_payload_ab7bo1xv/ansible_async_wrapper_payload.zip/ansible/modules/utilities/logic/async_wrapper.py", line 93, in _filter_non_json_lines
    ValueError: No start of json char found
  stderr: |-
    Traceback (most recent call last):
      File "/tmp/.ansible_root/ansible-tmp-1615878387.6764836-382128-195968160438742/AnsiballZ_vmware_guest.py", line 102, in <module>
        _ansiballz_main()
      File "/tmp/.ansible_root/ansible-tmp-1615878387.6764836-382128-195968160438742/AnsiballZ_vmware_guest.py", line 94, in _ansiballz_main
        invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
      File "/tmp/.ansible_root/ansible-tmp-1615878387.6764836-382128-195968160438742/AnsiballZ_vmware_guest.py", line 40, in invoke_module
        runpy.run_module(mod_name='ansible_collections.community.vmware.plugins.modules.vmware_guest', init_globals=None, run_name='__main__', alter_sys=True)
      File "/usr/lib64/python3.6/runpy.py", line 205, in run_module
        return _run_module_code(code, init_globals, run_name, mod_spec)
      File "/usr/lib64/python3.6/runpy.py", line 96, in _run_module_code
        mod_name, mod_spec, pkg_name, script_name)
      File "/usr/lib64/python3.6/runpy.py", line 85, in _run_code
        exec(code, run_globals)
      File "/tmp/ansible_community.vmware.vmware_guest_payload_61lt8w4t/ansible_community.vmware.vmware_guest_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_guest.py", line 3549, in <module>
      File "/tmp/ansible_community.vmware.vmware_guest_payload_61lt8w4t/ansible_community.vmware.vmware_guest_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_guest.py", line 3497, in main
      File "/tmp/ansible_community.vmware.vmware_guest_payload_61lt8w4t/ansible_community.vmware.vmware_guest_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_guest.py", line 3163, in reconfigure_vm
      File "/tmp/ansible_community.vmware.vmware_guest_payload_61lt8w4t/ansible_community.vmware.vmware_guest_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_guest.py", line 2219, in customize_customvalues
    AttributeError: 'NoneType' object has no attribute 'field'
  stderr_lines: <omitted>
ansibullbot commented 3 years ago

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibullbot commented 3 years ago

cc @Akasurde @Tomorrow9 @goneri @lparkes @nerzhul @pdellaert @pgbidkar @warthog9 click here for bot help

Akasurde commented 3 years ago

@jnm27 Thanks for reporting this issue. There was a significant change in 1.8 release related to custom values and advanced settings - https://github.com/ansible-collections/community.vmware/pull/179.

Could you please confirm if you are using a standalone ESXi deployment?

As a workaround -

diff --git a/plugins/modules/vmware_guest.py b/plugins/modules/vmware_guest.py
index 6c5b755..6326d69 100644
--- a/plugins/modules/vmware_guest.py
+++ b/plugins/modules/vmware_guest.py
@@ -2210,6 +2210,9 @@ class PyVmomiHelper(PyVmomi):
         if not self.params['customvalues']:
             return

+        if not self.content.customFieldsManager:
+            return
+
         facts = self.gather_facts(vm_obj)
         for kv in self.params['customvalues']:
             if 'key' not in kv or 'value' not in kv:
jnm27 commented 3 years ago

By standalone ESXi deployment, do you mean am I connecting directly to the ESXi host as opposed to vcenter? Yes.

Akasurde commented 3 years ago

By standalone ESXi deployment, do you mean am I connecting directly to the ESXi host as opposed to vcenter? Yes.

Yes,

customFieldManager is not available in a standalone ESXi. Can you please take a look at #179 and modify your playbook accordingly and let me know.

jnm27 commented 3 years ago

@Akasurde I tried using advanced_settings. It was successful, but it did not update the VMX file with the values I specified, neither on creation nor on reconfiguration.

Using customvalues on the base 2.9 version of vmware_guest does update the VMX file appropriately during creation.

jnm27 commented 3 years ago

Note that customvalues on the 1.8.0 version also does not create the VM with the correct VMX settings either.

Akasurde commented 3 years ago

@jnm27 Could you please provide the playbook used?

needs_info

jnm27 commented 3 years ago

With 2.9 vmware_guest customvalues: [root@ops03:/vmfs/volumes/6054c5e3-900d7846-faed-48df37da5d04/efd02] grep isolation efd02.vmx isolation.tools.unity.push.update.disable = "TRUE"

With 1.8.0 customvalues: [root@ops03:/vmfs/volumes/6054c5e3-900d7846-faed-48df37da5d04/efd02] grep isolation efd02.vmx [root@ops03:/vmfs/volumes/6054c5e3-900d7846-faed-48df37da5d04/efd02]

With 1.8.0 advanced_settings: [root@ops03:/vmfs/volumes/6054c5e3-900d7846-faed-48df37da5d04/efd02] grep isolation efd02.vmx [root@ops03:/vmfs/volumes/6054c5e3-900d7846-faed-48df37da5d04/efd02]

---> cat test_vmware_guest_no_values.yml
---
- hosts: localhost
  tasks:
    - name: Create the virtual machine on the ESXi host
      community.vmware.vmware_guest:
      #vmware_guest:
        hostname: ops03
        username: root
        password: XXXX
        validate_certs: no
        folder: /ha-datacenter/vm
        name: efd02
        state: present
        guest_id: rhel8_64Guest
        disk:
          - datastore: datastore1_ops03
            size_gb: 100
            type: thin
        hardware:
          boot_firmware: efi
          memory_mb: 8192
          num_cpu_cores_per_socket: 2
          num_cpus: 2
          scsi: paravirtual
        #customvalues:
        advanced_settings:
          - key: "isolation.tools.unity.push.update.disable"
            value: "TRUE"
Akasurde commented 3 years ago

@jnm27 I am unable to reproduce this issue with standalone ESXi and above playbook

---
- hosts: localhost
  vars_files:
    - vcenter_vars.yml
  tasks:
  - name: Create a Windows VM
    vmware_guest:
      validate_certs: False
      hostname: '{{ esxi_hostname }}'
      username: '{{ esxi_username }}'
      password: '{{ esxi_password }}'
      folder: /ha-datacenter/vm
      name: efd02
      guest_id: "windows8_64Guest"
      state: present
      disk:
        - size_mb: 512
          type: thin
          datastore: ds_200
      hardware:
        memory_mb: 4096
        num_cpus: 2
        scsi: lsilogicsas
      advanced_settings:
        - key: "isolation.tools.unity.push.update.disable"
          value: "TRUE"
[root@dhcp201-106:/vmfs/volumes/5f8545e6-2dc76dd2-6833-52540034ab9f/efd02] grep isolation efd02
.vmx
isolation.tools.unity.push.update.disable = "TRUE"

Could you please upgrade to 1.9.0?

needs_info