Deploying OVA to a folder in standalone ESXi datastore fails

Hi,

I’m trying to deply OVA to a folder in the datastore using Ansible but it fais even though the folder exists.

Inventory

[dc:children]
server1

[server1]
eur ansible_host=192.168.9.61

[server1:vars]
dstore1=DC_Disk1_VM

Vars File

vms1:
  - vm_name1: "DC-EDG-RTR1"
    ovapath1: "/root/VyOS_20250624_0020.ova"
  - vm_name1: "DC-EDG-RTR2"
    ovapath1: "/root/VyOS_20250624_0020.ova"

Playbook

---
- name: Deploy OVA to ESXi host
  hosts: eur
  gather_facts: false

  vars_files:
    - vars_eur_vms.yml

  tasks:
    - name: Deploy OVA
      vmware_deploy_ovf:
        hostname: "{{ ansible_host }}"
        username: "{{ ansible_user }}"
        password: "{{ ansible_password }}"
        datacenter: "ha-datacenter"
        datastore: "{{ dstore1 }}"
        folder: "{{ dstore1 }}/VMS"
        networks:
          "Network 1": "{{ net1 }}"
          "Network 2": "{{ net2 }}"
        ovf: "{{ item.ovapath1 }}"
        name: "{{ item.vm_name1 }}"
        validate_certs: no
      loop: "{{ vms1 }}"
      delegate_to: localhost

Error

failed: [eur -> localhost] (item={'vm_name1': 'DC-EDG-RTR1', 'ovapath1': '/root/VyOS_20250624_0020.ova'}) => {"ansible_loop_var": "item", "changed": false, "item": {"ovapath1": "/root/VyOS_20250624_0020.ova", "vm_name1": "DC-EDG-RTR1"}, "msg": "Unable to find the specified folder DC_Disk1_VM/vm/VMS"}
failed: [eur -> localhost] (item={'vm_name1': 'DC-EDG-RTR2', 'ovapath1': '/root/VyOS_20250624_0020.ova'}) => {"ansible_loop_var": "item", "changed": false, "item": {"ovapath1": "/root/VyOS_20250624_0020.ova", "vm_name1": "DC-EDG-RTR2"}, "msg": "Unable to find the specified folder DC_Disk1_VM/vm/VMS"}

I have tried "[DC_Disk1_VM]/VMS" and ha-datacenter/vm/VMS as well but that too does not work

But a VM deployed to the root of datastore that I attach ISO to form a folder in the same datastore, it works fine.

changed: [eur -> localhost] => (item={'vm_name2': 'DC-VBR', 'isofile2': '[DC_Disk1_VM]/ISO/Server_2022_x64_VL_20348.1487_Unattended.iso'})

Any thoughts what might be the issue here..

The error occurs because the folder parameter in vmware_deploy_ovf refers to the VM folder within the vCenter inventory, not a folder in the datastore. Since you’re using a standalone ESXi host (not vCenter), folders like ha-datacenter/vm/VMS don’t actually exist unless manually created via the vSphere UI. To fix this, either omit the folder parameter or ensure the target folder exists under the host’s inventory structure—not just in the datastore filesystem.

Thanks @jhonnmick

The error occurs because the folder parameter in vmware_deploy_ovf refers to the VM folder within the vCenter inventory, not a folder in the datastore.

Thanks for clsarifying the above, in that case I’ll try to unregister the VM, moves its files to the right directory and re-register it, will see how it goes..

That was the issue, and I resorted to Unregistering the VM, Move the VM folders to where I want to via Shell, and then Re-register the VM in ESXi via vim-cmd..

This works as expected but the code is inefficient as I have to write the same code 3 times to work it with 2 different sets of VMs in vars_eur_vms.yml file..

vars_eur_vms.yml

vms1:
  - vm_name1: "DC-EDG-RTR1"
    ovapath1: "/root/VyOS_20250624_0020.ova"
  - vm_name1: "DC-EDG-RTR2"
    ovapath1: "/root/VyOS_20250624_0020.ova"

vms2:
  - vm_name2: "DC-ADDC"
    isofile2: "[test] Server_2022_x64_VL_20348.1487_Unattended.iso"
  - vm_name2: "DC-GRF"
    isofile2: "[test] Rocky-9.5-x86_64-minimal.iso"

Playbook

- name: REGISTE VM
  hosts: eur
  gather_facts: false

  vars:
    vmdirs1: "{{ item.vm_name1 }}"
    vmdirs2: "{{ item.vm_name2 }}"
    vmdirs3: "{{ item.vm_name3 }}"

  vars_files:
    - vars_eur_vms.yml

  tasks:
    - name: REGISTER VM
      ansible.builtin.shell:
        cmd: /bin/vim-cmd solo/registervm /vmfs/volumes/test/VM/"{{ vmdirs1 }}"/"{{ vmdirs1 }}".vmx
      loop: "{{ vms1 }}"
      become: true # Required if moving folders requires root privileges

I’m unsure how to loop vm_name1 in vms1 and vm_name2 in vms2 in the below command without writing the code twice..

cmd: /bin/vim-cmd solo/registervm /vmfs/volumes/test/VM/"{{ vmdirs1 }}"/"{{ vmdirs1 }}".vmx
loop: "{{ vms1 }}"