Unable to solve issue with vmware.vmware.deploy_content_library_template module

I am running into an issue with the vmware.vmware.deploy_content_library_template module in my playbook.

Brief summary of how its being used:
I have an Azure Devops pipeline that runs the playbook via an ansible container in our Azure. The container is running:
Anisble core v2.18.6
Python v3.12.11
Aiohttp v3.12.9
community.vmware v5.6.0
vmware.vmware v1.11.0
VMware vSphere Automation SDK for Python v1.87.0

The specific module is displayed below:

    - name: Deploy VM from OVF Template
      vmware.vmware.deploy_content_library_template:
        hostname: '{{ vcenter_hostname }}'
        username: '{{ vcenter_username }}'
        password: '{{ vcenter_password }}'
        validate_certs: false
        library_item_name: "{{ ovf_template }}"
        library_name: "{{ content_library }}"
        vm_name: "{{ vm_name }}"
        datacenter: "{{ datacenter }}"
        datastore: "{{ vm_datastore }}"
        esxi_host: "{{ esx_hostname }}"
        cluster: "{{ cluster }}"
        vm_folder: "{{ vmfolder }}"
      register: deploy_result
      when: not reconfigure and vm_exist is undefined

The error I am experiencing is here with sensitive variables marked out:

fatal: [localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "cluster": null,
            "datacenter": "Plzen",
            "datastore": "************",
            "datastore_cluster": null,
            "esxi_host": "***********",
            "hostname": "***************",
            "library_id": null,
            "library_item_id": null,
            "library_item_name": "*********************",
            "library_name": "****************",
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "port": 443,
            "power_on_after_deploy": false,
            "proxy_host": null,
            "proxy_port": null,
            "proxy_protocol": "https",
            "resource_pool": null,
            "username": "*************************",
            "validate_certs": false,
            "vm_folder": "/Plzen/vm",
            "vm_name": "***********"
        }
    },
    "msg": "Unable to find folder with absolute path Plzen/vm"
}

I have confirmed the file path using the community.vmware.vmware_folder_info module and the community.vmware.vmware_vm_info module on other running VMS on the host.

This is a recent issue as prior to this, we were using an older version of ansible and utilizing the now deprecated community.vmware.vmware_content_deploy_template module. With everything updated to make use of newly added modules, I am running into this issue and cant get past this task in my playbook.

I have tried various different ways of file path naming as well as exluding defining the variable entirely but all have come back with this same error. All tasks prior to this one execute with no issue.

Any help would be greatly appreciated as I am at a loss with what the issue could be.

Just to clarify: Your datacenter is named Plzen and you want to deploy the OVF directly there. Not into any specific folder?

In that case, maybe just omit the vm_folder parameter. According to the documentation it’s not required.

cc @mikemorency

That is correct and it is also something I’ve already tried. No matter if I omit the parameter, set it statically, set it as a variable and define the variable in my group cars. They all result in the same case of unable to find the folder which is odd because other modules find the folder without issue.

Have you tried other vmware.vmware modules and they find the folder OK, or just other modules from other collections?
The inventory path is also case sensitive, I think.

Can you try using the lookup plugins as a sanity check? Something like this playbook, feel free to redact whatever in the output:

---
- hosts: localhost
  gather_facts: false
  vars:
    conn:
      vcenter_hostname:
      vcenter_username:
      vcenter_password:
      vcenter_validate_certs: false
  tasks:
    - debug:
        var: lookup('vmware.vmware.moid_from_path', item, **conn)
      loop:
        - '/'
        - '/Plzen'
        - '/Plzen/'
        - '/Plzen/vm'
1 Like

For the record: Unable to solve issue with vmware.vmware.deploy_content_library_template module

ATM it looks like this might be a bug somewhere in the code, so I suggest to continue the discussion in the issue you’ve opened on GitHub :backhand_index_pointing_up:

Sorry, trying to get this for you but having to modify it for my pipeline as secrets are retrieved from KV and then passed by the pipeline to the ansible server. Bear with me.

Alright so as stated, I had to modify it a little bit to work in the pipeline but essentially I made it into its own task file.

Task file is here:

---
- block:
    - name: Include variables
      ansible.builtin.include_vars:
        file: "group_vars/{{ vsensor_hostname }}.yml"

    - name: Debug vmware.vmware
      debug:
        var: lookup('vmware.vmware.moid_from_path', item, hostname="{{ vcenter_hostname }}", username="{{ vcenter_username }}", password="{{ vcenter_password }}" )
      loop:
        - '/'
        - '/Plzen'
        - '/Plzen/'
        - '/Plzen/vm'

and just for confirmation, I checked the server and ran

ansible-galaxy collection list

This returned the following

# /usr/local/lib/python3.12/site-packages/ansible_collections
Collection                               Version
---------------------------------------- -------
amazon.aws                               9.5.0
ansible.netcommon                        7.2.0
ansible.posix                            1.6.2
ansible.utils                            5.1.2
ansible.windows                          2.8.0
arista.eos                               10.1.1
awx.awx                                  24.6.1
azure.azcollection                       3.3.1
check_point.mgmt                         6.4.0
chocolatey.chocolatey                    1.5.3
cisco.aci                                2.11.0
cisco.asa                                6.1.0
cisco.dnac                               6.31.3
cisco.intersight                         2.1.0
cisco.ios                                9.2.0
cisco.iosxr                              10.3.1
cisco.ise                                2.10.0
cisco.meraki                             2.21.1
cisco.mso                                2.10.0
cisco.nxos                               9.4.0
cisco.ucs                                1.16.0
cloud.common                             4.1.0
cloudscale_ch.cloud                      2.4.1
community.aws                            9.3.0
community.ciscosmb                       1.0.10
community.crypto                         2.26.1
community.digitalocean                   1.27.0
community.dns                            3.2.4
community.docker                         4.6.0
community.general                        10.7.0
community.grafana                        2.2.0
community.hashi_vault                    6.2.0
community.hrobot                         2.3.0
community.library_inventory_filtering_v1 1.1.1
community.libvirt                        1.3.1
community.mongodb                        1.7.9
community.mysql                          3.13.0
community.network                        5.1.0
community.okd                            4.0.1
community.postgresql                     3.14.1
community.proxysql                       1.6.0
community.rabbitmq                       1.4.0
community.routeros                       3.6.0
community.sap_libs                       1.4.2
community.sops                           2.0.5
community.vmware                         5.6.0
community.windows                        2.4.0
community.zabbix                         3.3.0
containers.podman                        1.16.3
cyberark.conjur                          1.3.3
cyberark.pas                             1.0.35
dellemc.enterprise_sonic                 2.5.1
dellemc.openmanage                       9.12.0
dellemc.powerflex                        2.6.0
dellemc.unity                            2.0.0
f5networks.f5_modules                    1.35.0
fortinet.fortimanager                    2.9.1
fortinet.fortios                         2.4.0
google.cloud                             1.5.3
grafana.grafana                          5.7.0
hetzner.hcloud                           4.3.0
hitachivantara.vspone_block              3.4.1
ibm.qradar                               4.0.0
ibm.spectrum_virtualize                  2.0.0
ibm.storage_virtualize                   2.7.3
ieisystem.inmanage                       3.0.0
infinidat.infinibox                      1.4.5
infoblox.nios_modules                    1.8.0
inspur.ispim                             2.2.3
junipernetworks.junos                    9.1.0
kaytus.ksmanage                          2.0.0
kubernetes.core                          5.3.0
kubevirt.core                            2.2.2
lowlydba.sqlserver                       2.6.1
microsoft.ad                             1.9.0
microsoft.iis                            1.0.2
netapp.cloudmanager                      21.24.0
netapp.ontap                             22.14.0
netapp.storagegrid                       21.14.0
netapp_eseries.santricity                1.4.1
netbox.netbox                            3.21.0
ngine_io.cloudstack                      2.5.0
openstack.cloud                          2.4.1
ovirt.ovirt                              3.2.0
purestorage.flasharray                   1.34.1
purestorage.flashblade                   1.20.0
sensu.sensu_go                           1.14.0
splunk.es                                4.0.0
telekom_mms.icinga_director              2.2.2
theforeman.foreman                       4.2.0
vmware.vmware                            1.11.0
vmware.vmware_rest                       4.7.0
vultr.cloud                              1.13.0
vyos.vyos                                5.0.0
wti.remote                               1.0.10

but the pipeline returned with this error:

TASK [dark_trace_sensor : Debug vmware.vmware] *********************************
task path: /home/ansible/ansible_playbooks/ansible/roles/dark_trace_sensor/tasks/debug.yml:34
Loading collection vmware.vmware from /usr/local/lib/python3.12/site-packages/ansible_collections/vmware/vmware
fatal: [localhost]: FAILED! => {
    "msg": "lookup plugin (vmware.vmware.moid_from_path) not found"
}

PLAY RECAP *********************************************************************

So now I’m at a loss at how that plugin isnt found when vmware.vmware is installed.

The lookup plugin is in version 2.1.0, so you will need to install that version

sorry, been a long week lol. Totally overlooked that.

No worries, I did too :slight_smile:

Alright so keep in mind that in the target vSphere, there are many different datacenters so this command happening to return multiple entries for ‘/’ is expected. What is interesting though is that it doesn’t seem to locate any folders starting with Plzen as the datacenter.

TASK ********** : Get VM MOIDs from paths] *****************************
task path: /home/ansible/ansible_playbooks/ansible/roles/*********/tasks/debug.yml:7
Loading collection vmware.vmware from /home/ansible/.ansible/collections/ansible_collections/vmware/vmware
ok: [localhost] => (item=/) => {
    "msg": "group-d64,group-d65,group-d72,group-d71,group-d73"
}
ok: [localhost] => (item=/Plzen) => {
    "msg": []
}
ok: [localhost] => (item=/Plzen/) => {
    "msg": []
}
ok: [localhost] => (item=/Plzen/vm) => {
    "msg": []
}

This has me wondering why community.vmware is able to see folders but vmware.vmware doesnt seem to be seeing them.

I believe objects with moid ‘group-’ are folders too, whereas datacenters are ‘datacenter-’

I’ll have to double check that though

yeah I think you are correct, which has me wondering if something is messed up with the file paths on that specific datacenter. I can try and check with PowerCLI but may have to get with my infrastructure team to look further into it.