Seeking Guidance with the vmware_guest Module

Ive only resently started using Ansible (about 3 weeks). Ive gotten the hang of the basics; however, im having some challanges with deploying a VM and getting it to domain join. The error seems to reference domain_ou which im specifying and the OU does exist. The account im using is a domain admin as well.

If i remove all the domain join related stuff the VM deploys without issue. I suspect that it may be formating? Ive searched just about every where and tried different methods but same results.

Here is the playbook:

---
- name: Create a new VM from a template
  hosts: localhost
  gather_facts: false
  tasks:
    - name: Deploy VM from template "{{ vm_template }}"
      community.vmware.vmware_guest:
        hostname: "{{ vcenter_hostname }}"
        username: "{{ vcenter_username }}"
        password: "{{ vcenter_password }}"
        validate_certs: false
        name: "{{ vm_hostname }}"
        template: "{{ vm_template }}"
        datacenter: "{{ vcenter_datacenter }}"
        cluster: "{{ vm_dest }}"
        datastore: "{{ vm_datastore }}"
        convert: thin
        folder: "{{ vm_folder }}"
        annotation: "{{ vm_notes }} "
        state: "{{ vm_pstate }}"
        networks:
          - name: "{{ vm_network }}"
            connected: true
            start_connected: yes
            device_type: vmxnet3
            ip: "{{ vm_address }}"
            netmask: "{{ vm_netmask }}"
            gateway: "{{ vm_gateway }}"
            dns_suffix: myplayground.com
            domain: myplayground.com
            dns_servers:
              - "{{ dns_server1 }}"
              - "{{ dns_server2 }}"
            wait_for_ip_address: true
        customization:
          autologon: true
          autologoncount: 1
          fullname: LocalAdmin
          hostname: "{{ vm_hostname }}"
          domain: myplayground.com
          joindomain: myplayground.com
          domain_ou: "OU=AnsibleTest,OU=TargetOU,OU=TO,OU=PATH,DC=MYPLAYGROUND,DC=COM"
          domainadmin: "{{ domain_admin }}"
          domainadminpassword: "{{ domain_adminpass }}"
          orgname: AnsibLab
          password: "{{ vcenter_password }}"
          productid: 'NPPR9-FWDCX-D2C8J-H872K-2YT43'
          timezone: '004'
        wait_for_customization: true

I get this error when attempting to domain join:

{
“module_stdout”: “”,
“module_stderr”: “Traceback (most recent call last):\n File "/usr/local/lib/python3.11/site-packages/pyVmomi/VmomiSupport.py", line 463, in GetPropertyInfo\n while name not in type._propInfo:\n ^^^^^^^^^^^^^^\nAttributeError: type object ‘object’ has no attribute ‘_propInfo’\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File "/home/runner/.ansible/tmp/ansible-tmp-1744309730.6326966-25-43156245065951/AnsiballZ_vmware_guest.py", line 107, in \n _ansiballz_main()\n File "/home/runner/.ansible/tmp/ansible-tmp-1744309730.6326966-25-43156245065951/AnsiballZ_vmware_guest.py", line 99, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File "/home/runner/.ansible/tmp/ansible-tmp-1744309730.6326966-25-43156245065951/AnsiballZ_vmware_guest.py", line 47, in invoke_module\n runpy.run_module(mod_name=‘ansible_collections.community.vmware.plugins.modules.vmware_guest’, init_globals=dict(_module_fqn=‘ansible_collections.community.vmware.plugins.modules.vmware_guest’, _modlib_path=modlib_path),\n File "", line 226, in run_module\n File "", line 98, in _run_module_code\n File "", line 88, in _run_code\n File "/tmp/ansible_community.vmware.vmware_guest_payload_79q0j9el/ansible_community.vmware.vmware_guest_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_guest.py", line 3682, in \n File "/tmp/ansible_community.vmware.vmware_guest_payload_79q0j9el/ansible_community.vmware.vmware_guest_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_guest.py", line 3671, in main\n File "/tmp/ansible_community.vmware.vmware_guest_payload_79q0j9el/ansible_community.vmware.vmware_guest_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_guest.py", line 3052, in deploy_vm\n File "/tmp/ansible_community.vmware.vmware_guest_payload_79q0j9el/ansible_community.vmware.vmware_guest_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_guest.py", line 2380, in customize_vm\n File "/usr/local/lib/python3.11/site-packages/pyVmomi/VmomiSupport.py", line 663, in setattr\n CheckField(self._GetPropertyInfo(name), val)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File "/usr/local/lib/python3.11/site-packages/pyVmomi/VmomiSupport.py", line 468, in GetPropertyInfo\n raise AttributeError(name)\nAttributeError: domainOU\n”,
“exception”: “Traceback (most recent call last):\n File "/usr/local/lib/python3.11/site-packages/pyVmomi/VmomiSupport.py", line 463, in GetPropertyInfo\n while name not in type._propInfo:\n ^^^^^^^^^^^^^^\nAttributeError: type object ‘object’ has no attribute ‘_propInfo’\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File "/home/runner/.ansible/tmp/ansible-tmp-1744309730.6326966-25-43156245065951/AnsiballZ_vmware_guest.py", line 107, in \n _ansiballz_main()\n File "/home/runner/.ansible/tmp/ansible-tmp-1744309730.6326966-25-43156245065951/AnsiballZ_vmware_guest.py", line 99, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File "/home/runner/.ansible/tmp/ansible-tmp-1744309730.6326966-25-43156245065951/AnsiballZ_vmware_guest.py", line 47, in invoke_module\n runpy.run_module(mod_name=‘ansible_collections.community.vmware.plugins.modules.vmware_guest’, init_globals=dict(_module_fqn=‘ansible_collections.community.vmware.plugins.modules.vmware_guest’, _modlib_path=modlib_path),\n File "", line 226, in run_module\n File "", line 98, in _run_module_code\n File "", line 88, in _run_code\n File "/tmp/ansible_community.vmware.vmware_guest_payload_79q0j9el/ansible_community.vmware.vmware_guest_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_guest.py", line 3682, in \n File "/tmp/ansible_community.vmware.vmware_guest_payload_79q0j9el/ansible_community.vmware.vmware_guest_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_guest.py", line 3671, in main\n File "/tmp/ansible_community.vmware.vmware_guest_payload_79q0j9el/ansible_community.vmware.vmware_guest_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_guest.py", line 3052, in deploy_vm\n File "/tmp/ansible_community.vmware.vmware_guest_payload_79q0j9el/ansible_community.vmware.vmware_guest_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_guest.py", line 2380, in customize_vm\n File "/usr/local/lib/python3.11/site-packages/pyVmomi/VmomiSupport.py", line 663, in setattr\n CheckField(self._GetPropertyInfo(name), val)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File "/usr/local/lib/python3.11/site-packages/pyVmomi/VmomiSupport.py", line 468, in GetPropertyInfo\n raise AttributeError(name)\nAttributeError: domainOU\n”,
“msg”: “MODULE FAILURE\nSee stdout/stderr for the exact error”,
“rc”: 1,
“_ansible_no_log”: false,
“changed”: false,
“_ansible_delegated_vars”: {
“ansible_host”: “localhost”,
“ansible_port”: null,
“ansible_user”: “root”,
“ansible_connection”: “local”
}
}

Here is what Grok thinks about it…

# Fixing the Ansible Playbook Error for VMware VM Domain Join

The error you're encountering in your Ansible playbook is related to the `customization` section of the `vmware_guest` module, specifically with the `domain_ou` parameter. The traceback indicates an `AttributeError: domainOU`, which suggests that the `domain_ou` parameter is not recognized by the underlying VMware API or the Ansible module.

## Root Cause

The `vmware_guest` module relies on the `pyVmomi` library to interact with VMware vSphere. The error occurs because `domain_ou` (or its camelCase variant `domainOU`) is not a valid property in the `CustomizationSpec` object used by `pyVmomi` for VM customization. The correct parameter to specify an Organizational Unit (OU) for domain joining is `ou`, not `domain_ou`.

## Fix

Update the `customization` section in your playbook to use `ou` instead of `domain_ou`. Below is the corrected portion of your playbook:

```yaml
customization:
  autologon: true
  autologoncount: 1
  fullname: LocalAdmin
  hostname: "{{ vm_hostname }}"
  domain: myplayground.com
  joindomain: myplayground.com
  ou: "OU=AnsibleTest,OU=TargetOU,OU=TO,OU=PATH,DC=MYPLAYGROUND,DC=COM"  # Changed from domain_ou to ou
  domainadmin: "{{ domain_admin }}"
  domainadminpassword: "{{ domain_adminpass }}"
  orgname: AnsibLab
  password: "{{ vcenter_password }}"
  productid: 'NPPR9-FWDCX-D2C8J-H872K-2YT43'
  timezone: '004'

Explanation
The ou parameter specifies the Organizational Unit in the Active Directory where the VM’s computer account will be placed after joining the domain.

The domain_ou parameter you used does not exist in the vmware_guest module’s customization spec, which is why the error occurs when pyVmomi tries to set this attribute.

Additional Notes
Validate Variables: Ensure all variables (e.g., domain_admin, domain_adminpass, vm_hostname, etc.) are defined in your inventory, group vars, or passed via -e in the Ansible command. Undefined variables can cause other failures.

Credentials: Double-check that domainadmin and domainadminpassword have sufficient privileges to join the VM to the domain and place it in the specified OU.

Network Configuration: Ensure the dns_servers, vm_address, vm_netmask, and vm_gateway are correctly configured, as domain joining requires proper DNS resolution.

Debugging: If the issue persists, run the playbook with verbose output (ansible-playbook -vvv) to get more detailed logs.

Testing the Fix
After making the change, rerun the playbook with the following command:
bash

ansible-playbook your_playbook.yml -vvv

If the VM deploys and joins the domain successfully, the task should complete without the AttributeError.

This does not work unfortunately. The supported parameter per the documentation is domain_ou. If i do switch to ou: then the playbook immediately fails due to that parameter.

This is where im stuck. The documentation stated to enter the value as “LDAP Path” which ive done…but doesnt work. I then switched to DN as shown in active directory and it doesnt work. Both return an error that is similar to what I included in the post.

Oh I also want to add that I omitted the domain_ou parameter and get the same error, even though the docummentation states that its not required.

Does it work if you remove the “customization” block? In other words, can you successfully deploy a plain VM from template, without any customization?

It’s a little bit hard to decipher your error message because it was not pasted in original form and in code block so it’s messed up. Anyway, this looks like a bug. Some incompatibility between Python/pyvmomi and vCenter API perhaps.

What version of Ansible, pyvmomi, community.vmware collection and VMware vCenter are you using?

I had some weird issues with vCenter 8.0.3 compared to 8.0.2.

What pyVmomi version are you using?

edit:
"/usr/local/lib/python3.11/site-packages/pyVmomi/VmomiSupport.py", line 468, in GetPropertyInfo\n raise AttributeError(name)\nAttributeError: domainOU looks like pyVmomi doesn’t know this attribute. Since the documentation says domain_ou works for vSphere 8.0U2 and above, I guess you probably also need pyvmomi 8.0.2.0 or later.

And just to make this clear: You are running vSphere 8.0U2+?

For the record: This has been implemented here.

If i remove the joindomain parameter I am able to deploy the VM successfully without issue, and I am able to include any others well. If I omit the domain_ou and just include the joindomain i still get the same error.

I am running vCenter 8u3d and the ESXi is also 8u3d. The VM version is 21 and vmtools on the template is also on the latest, 12.5.1

I am running a trial of Ansible Automation Platform 2.5 and im running from there using the prebuilt execution environments so ill have to check. I do believe it had ansible core 2.14.17 but i could be mistaken. Thank you for the reply!

I think we don’t support ansible-core < 2.17. But I don’t think that’s the problem here.

ATM it looks like a (too) old pyvmomi version to me. Although this is just an educated guess.

Thank you for the reply! It sounds like my issue may possible be with the pyvmomi version then. I am running the latest version and build on vSphere. The vcsa is at 8u3d and the esxi is also 8u3d.

excuse my ignorance, but this would be on the execution environment correct?

edit: i am using ansible automation platform 2.5 which is Redhats latest build. I didnt deviate much from their defaults so I will have to check on if i can get support from them.