Vmware_guest cannot find network

---
- hosts: localhost
  gather_facts: false
  vars_files:
    - ./vcenter_vault.yml

  tasks:
    - name: Create a virtual machine
      community.vmware.vmware_guest:
        hostname: "{{ vcenter_hostname }}"
        username: "{{ vcenter_username }}"
        password: "{{ vcenter_password }}"
        validate_certs: no
        datacenter: attic
        datastore: ds1
        folder: /lab
        name: test_vm_0001
        state: poweredon
        guest_id: rockylinux_64Guest
        cluster: esxi.local
        disk:
        - size_gb: 120
          type: thin
        hardware:
          memory_mb: 4096
          num_cpus: 2
          scsi: paravirtual
        networks:
        - name: pg_vmnet_lab
          ip: 10.26.10.43
          netmask: 255.255.255.0
          device_type: vmxnet3
        wait_for_ip_address: yes
      delegate_to: localhost
      register: deploy_vm

I verified that datacenter, folder, cluster are all correct. The network name exists, too.
When I run a guest_info on an existing vm, I can actually see those same values returned.

I can find several results online with this error message, except they are either old bugs which have been resolved, or mistakes in datacenter name, missing cluster name. I verified those are correct.

Does anyone have any ideas why this might fail?

Hi,

Could you also share the error message / output ?

For now, here are a few things you could check from module documentation page:

  • All parameters and VMware object names are case sensitive.

    (from here)

  • The type, ip, netmask, gateway, domain, dns_servers options don’t set to a guest when creating a blank new virtual machine. They are set by the customization via vmware-tools. If you want to set the value of the options to a guest, you need to clone from a template with installed OS and vmware-tools(also Perl when Linux).

    (from here)

  • When specifying distributed virtual portgroup make sure given esxi_hostname or cluster is associated with it.

    (from here)

  • This requires vmware-tools (vmtoolsd) to properly work after creation.

    vmware-tools needs to be installed on the given virtual machine in order to work with this parameter.

    (from here)

Also, is ‘vmnet_lab’ the actual network name, or is it a placeholder ? I’ve seen issues on Github hinting the issues came from a name containing IPv4 chars.

1 Like

Hi,

Adding also the version of ansible, vmware community Collection version, and version of vmware/esxi.

I had some issue in the past with very old collection and old ansible.

1 Like

Thanks for the elaborate replies! Appreciate the help.

I sure can:

╰─ ansible-playbook deploy_vm.yml                                                                                                                                                    ─╯

PLAY [localhost] ***********************************************************************************************************************************************************************

TASK [Create a virtual machine] ********************************************************************************************************************************************************
Thursday 09 November 2023  16:21:49 +0100 (0:00:00.050)       0:00:00.050 ***** 
fatal: [localhost]: FAILED! => {
    "changed": false
}

MSG:

Network 'pg_vmnet_lan' does not exist.

PLAY RECAP *****************************************************************************************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

Playbook run took 0 days, 0 hours, 0 minutes, 0 seconds
Thursday 09 November 2023  16:21:49 +0100 (0:00:00.461)       0:00:00.512 ***** 
=============================================================================== 
Create a virtual machine -------------------------------------------------------------------------------------------------------------------------------------------------------- 0.46s

Oke, I’ll remove it. I just want to point out the examples on the official Ansible documentation include those parameters too (which I litterally copy/pasted as a starting point).

I refer to a port group on a standard virtual switch. I tried my playbook with either cluster or esxi_hostname specified.

It is actually pg_vmnet_lab, pg_vmnet_lan or pg_vmnet_storage. Those are the actual portgroup names as seen in vCenter. All on a standard vSwitch.

Ansible version:

╰─ ansible --version                                                                                                                                                                 ─╯
ansible [core 2.15.5]
  config file = /Users/bor/git/ansible/pr_manage_pb/ansible.cfg
  configured module search path = ['/Users/bor/git/ansible/pr_manage_pb/modules']
  ansible python module location = /opt/homebrew/Cellar/ansible/8.5.0_1/libexec/lib/python3.11/site-packages/ansible
  ansible collection location = /Users/bor/git/ansible/pr_manage_pb/collections
  executable location = /opt/homebrew/bin/ansible
  python version = 3.11.6 (main, Oct  2 2023, 13:45:54) [Clang 15.0.0 (clang-1500.0.40.1)] (/opt/homebrew/Cellar/ansible/8.5.0_1/libexec/bin/python)
  jinja version = 3.1.2
  libyaml = True

Collections list with versions:

╰─ ansible-galaxy collection list                                                                                                                                                    ─╯

# /Users/bor/git/ansible/pr_manage_pb/collections/ansible_collections
Collection                    Version
----------------------------- -------
ansibleguy.opnsense           1.2.7  

# /opt/homebrew/Cellar/ansible/8.5.0_1/libexec/lib/python3.11/site-packages/ansible_collections
Collection                    Version
----------------------------- -------
amazon.aws                    6.5.0  
ansible.netcommon             5.2.0  
ansible.posix                 1.5.4  
ansible.utils                 2.11.0 
ansible.windows               1.14.0 
arista.eos                    6.1.2  
awx.awx                       22.7.0 
azure.azcollection            1.18.1 
check_point.mgmt              5.1.1  
chocolatey.chocolatey         1.5.1  
cisco.aci                     2.7.0  
cisco.asa                     4.0.2  
cisco.dnac                    6.7.5  
cisco.intersight              1.0.27 
cisco.ios                     4.6.1  
cisco.iosxr                   5.0.3  
cisco.ise                     2.5.16 
cisco.meraki                  2.16.5 
cisco.mso                     2.5.0  
cisco.nso                     1.0.3  
cisco.nxos                    4.4.0  
cisco.ucs                     1.10.0 
cloud.common                  2.1.4  
cloudscale_ch.cloud           2.3.1  
community.aws                 6.3.0  
community.azure               2.0.0  
community.ciscosmb            1.0.6  
community.crypto              2.15.1 
community.digitalocean        1.24.0 
community.dns                 2.6.2  
community.docker              3.4.9  
community.fortios             1.0.0  
community.general             7.5.0  
community.google              1.0.0  
community.grafana             1.5.4  
community.hashi_vault         5.0.0  
community.hrobot              1.8.1  
community.libvirt             1.3.0  
community.mongodb             1.6.3  
community.mysql               3.7.2  
community.network             5.0.0  
community.okd                 2.3.0  
community.postgresql          2.4.3  
community.proxysql            1.5.1  
community.rabbitmq            1.2.3  
community.routeros            2.10.0 
community.sap                 1.0.0  
community.sap_libs            1.4.1  
community.skydive             1.0.0  
community.sops                1.6.6  
community.vmware              3.10.0 
community.windows             1.13.0 
community.zabbix              2.1.0  
containers.podman             1.10.3 
cyberark.conjur               1.2.2  
cyberark.pas                  1.0.23 
dellemc.enterprise_sonic      2.2.0  
dellemc.openmanage            7.6.1  
dellemc.powerflex             1.9.0  
dellemc.unity                 1.7.1  
f5networks.f5_modules         1.26.0 
fortinet.fortimanager         2.2.1  
fortinet.fortios              2.3.2  
frr.frr                       2.0.2  
gluster.gluster               1.0.2  
google.cloud                  1.2.0  
grafana.grafana               2.2.3  
hetzner.hcloud                1.16.0 
hpe.nimble                    1.1.4  
ibm.qradar                    2.1.0  
ibm.spectrum_virtualize       1.12.0 
infinidat.infinibox           1.3.12 
infoblox.nios_modules         1.5.0  
inspur.ispim                  1.3.0  
inspur.sm                     2.3.0  
junipernetworks.junos         5.3.0  
kubernetes.core               2.4.0  
lowlydba.sqlserver            2.2.1  
microsoft.ad                  1.3.0  
netapp.aws                    21.7.0 
netapp.azure                  21.10.0
netapp.cloudmanager           21.22.0
netapp.elementsw              21.7.0 
netapp.ontap                  22.7.0 
netapp.storagegrid            21.11.1
netapp.um_info                21.8.0 
netapp_eseries.santricity     1.4.0  
netbox.netbox                 3.14.0 
ngine_io.cloudstack           2.3.0  
ngine_io.exoscale             1.1.0  
ngine_io.vultr                1.1.3  
openstack.cloud               2.1.0  
openvswitch.openvswitch       2.1.1  
ovirt.ovirt                   3.2.0  
purestorage.flasharray        1.21.0 
purestorage.flashblade        1.14.0 
purestorage.fusion            1.6.0  
sensu.sensu_go                1.14.0 
servicenow.servicenow         1.0.6  
splunk.es                     2.1.0  
t_systems_mms.icinga_director 1.33.1 
telekom_mms.icinga_director   1.34.1 
theforeman.foreman            3.14.0 
vmware.vmware_rest            2.3.1  
vultr.cloud                   1.10.0 
vyos.vyos                     4.1.0  
wti.remote                    1.0.5  

ESXi & vSphere:
Hypervisor: VMware ESXi, 8.0.2, 22380479
vCenter Details: Version: 8.0.2, Build: 22617221

Can you share the run with highr verbosity, just to show us What was the module invocation?

Just - vvvv

Thanks

P. S. It’s strange beacuse on my company modules works well, the only differance is that we start from a template with vmware tools already installed.

1 Like
╰─ ansible-playbook -vvvv deploy_vm.yml
ansible-playbook [core 2.15.5]
  config file = /Users/bor/git/ansible/pr_manage_pb/ansible.cfg
  configured module search path = ['/Users/bor/git/ansible/pr_manage_pb/modules']
  ansible python module location = /opt/homebrew/Cellar/ansible/8.5.0_1/libexec/lib/python3.11/site-packages/ansible
  ansible collection location = /Users/bor/git/ansible/pr_manage_pb/collections
  executable location = /opt/homebrew/bin/ansible-playbook
  python version = 3.11.6 (main, Oct  2 2023, 13:45:54) [Clang 15.0.0 (clang-1500.0.40.1)] (/opt/homebrew/Cellar/ansible/8.5.0_1/libexec/bin/python)
  jinja version = 3.1.2
  libyaml = True
Using /Users/bor/git/ansible/pr_manage_pb/ansible.cfg as config file
setting up inventory plugins
Loading collection ansible.builtin from 
host_list declined parsing /Users/bor/git/ansible/pr_manage_pb/inventory.ini as it did not pass its verify_file() method
script declined parsing /Users/bor/git/ansible/pr_manage_pb/inventory.ini as it did not pass its verify_file() method
auto declined parsing /Users/bor/git/ansible/pr_manage_pb/inventory.ini as it did not pass its verify_file() method
yaml declined parsing /Users/bor/git/ansible/pr_manage_pb/inventory.ini as it did not pass its verify_file() method
Parsed /Users/bor/git/ansible/pr_manage_pb/inventory.ini inventory source with ini plugin
Loading collection community.vmware from /opt/homebrew/Cellar/ansible/8.5.0_1/libexec/lib/python3.11/site-packages/ansible_collections/community/vmware
redirecting (type: callback) ansible.builtin.debug to ansible.posix.debug
Loading collection ansible.posix from /opt/homebrew/Cellar/ansible/8.5.0_1/libexec/lib/python3.11/site-packages/ansible_collections/ansible/posix
redirecting (type: callback) ansible.builtin.debug to ansible.posix.debug
Loading callback plugin ansible.posix.debug of type stdout, v2.0 from /opt/homebrew/Cellar/ansible/8.5.0_1/libexec/lib/python3.11/site-packages/ansible_collections/ansible/posix/plugins/callback/debug.py
redirecting (type: callback) ansible.builtin.timer to ansible.posix.timer
redirecting (type: callback) ansible.builtin.profile_tasks to ansible.posix.profile_tasks
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
Loading callback plugin ansible.posix.timer of type aggregate, v2.0 from /opt/homebrew/Cellar/ansible/8.5.0_1/libexec/lib/python3.11/site-packages/ansible_collections/ansible/posix/plugins/callback/timer.py
Loading callback plugin ansible.posix.profile_tasks of type aggregate, v2.0 from /opt/homebrew/Cellar/ansible/8.5.0_1/libexec/lib/python3.11/site-packages/ansible_collections/ansible/posix/plugins/callback/profile_tasks.py

PLAYBOOK: deploy_vm.yml *******************************************************************************************
Positional arguments: deploy_vm.yml
verbosity: 4
connection: smart
timeout: 10
become_method: sudo
tags: ('all',)
inventory: ('/Users/bor/git/ansible/pr_manage_pb/inventory.ini',)
forks: 5
1 plays in deploy_vm.yml
Trying secret FileVaultSecret(filename='/Users/bor/git/ansible/.pr_manage_pb_vaultpass') for vault_id=default
Read vars_file './vcenter_vault.yml'
Trying secret FileVaultSecret(filename='/Users/bor/git/ansible/.pr_manage_pb_vaultpass') for vault_id=default
Read vars_file './vcenter_vault.yml'
Trying secret FileVaultSecret(filename='/Users/bor/git/ansible/.pr_manage_pb_vaultpass') for vault_id=default
Read vars_file './vcenter_vault.yml'

PLAY [localhost] **************************************************************************************************
Trying secret FileVaultSecret(filename='/Users/bor/git/ansible/.pr_manage_pb_vaultpass') for vault_id=default
Read vars_file './vcenter_vault.yml'
Trying secret FileVaultSecret(filename='/Users/bor/git/ansible/.pr_manage_pb_vaultpass') for vault_id=default
Read vars_file './vcenter_vault.yml'
Trying secret FileVaultSecret(filename='/Users/bor/git/ansible/.pr_manage_pb_vaultpass') for vault_id=default
Read vars_file './vcenter_vault.yml'

TASK [Create a virtual machine] ***********************************************************************************
task path: /Users/bor/git/ansible/pr_manage_pb/deploy_vm.yml:8
Saturday 11 November 2023  20:50:39 +0100 (0:00:00.051)       0:00:00.051 ***** 
Trying secret FileVaultSecret(filename='/Users/bor/git/ansible/.pr_manage_pb_vaultpass') for vault_id=default
Read vars_file './vcenter_vault.yml'
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: bor
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /tmp/$USER/ansible `"&& mkdir "` echo /tmp/$USER/ansible/ansible-tmp-1699732239.532284-2072-173201278915607 `" && echo ansible-tmp-1699732239.532284-2072-173201278915607="` echo /tmp/$USER/ansible/ansible-tmp-1699732239.532284-2072-173201278915607 `" ) && sleep 0'
Using module file /opt/homebrew/Cellar/ansible/8.5.0_1/libexec/lib/python3.11/site-packages/ansible_collections/community/vmware/plugins/modules/vmware_guest.py
<localhost> PUT /Users/bor/.ansible/tmp/ansible-local-2069_a0fnsza/tmpd_y7bae_ TO /private/tmp/bor/ansible/ansible-tmp-1699732239.532284-2072-173201278915607/AnsiballZ_vmware_guest.py
<localhost> EXEC /bin/sh -c 'chmod u+x /tmp/bor/ansible/ansible-tmp-1699732239.532284-2072-173201278915607/ /tmp/bor/ansible/ansible-tmp-1699732239.532284-2072-173201278915607/AnsiballZ_vmware_guest.py && sleep 0'
<localhost> EXEC /bin/sh -c '/opt/homebrew/Cellar/ansible/8.5.0_1/libexec/bin/python /tmp/bor/ansible/ansible-tmp-1699732239.532284-2072-173201278915607/AnsiballZ_vmware_guest.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /tmp/bor/ansible/ansible-tmp-1699732239.532284-2072-173201278915607/ > /dev/null 2>&1 && sleep 0'
fatal: [localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "advanced_settings": [],
            "annotation": null,
            "cdrom": [],
            "cluster": "esxi.internal.borsdomain.net",
            "convert": null,
            "customization": {
                "autologon": null,
                "autologoncount": null,
                "dns_servers": null,
                "dns_suffix": null,
                "domain": null,
                "domainadmin": null,
                "domainadminpassword": null,
                "existing_vm": null,
                "fullname": null,
                "hostname": null,
                "hwclockUTC": null,
                "joindomain": null,
                "joinworkgroup": null,
                "orgname": null,
                "password": null,
                "productid": null,
                "runonce": null,
                "script_text": null,
                "timezone": null
            },
            "customization_spec": null,
            "customvalues": [],
            "datacenter": "attic",
            "datastore": "nfs_ds_data",
            "delete_from_inventory": false,
            "disk": [
                {
                    "autoselect_datastore": null,
                    "controller_number": null,
                    "controller_type": null,
                    "datastore": null,
                    "disk_mode": null,
                    "filename": null,
                    "size": null,
                    "size_gb": 120,
                    "size_kb": null,
                    "size_mb": null,
                    "size_tb": null,
                    "type": "thin",
                    "unit_number": null
                }
            ],
            "encryption": {
                "encrypted_ft": null,
                "encrypted_vmotion": null
            },
            "esxi_hostname": null,
            "folder": "/lab",
            "force": false,
            "guest_id": "rockylinux_64Guest",
            "hardware": {
                "boot_firmware": null,
                "cpu_limit": null,
                "cpu_reservation": null,
                "cpu_shares": null,
                "cpu_shares_level": null,
                "hotadd_cpu": null,
                "hotadd_memory": null,
                "hotremove_cpu": null,
                "iommu": null,
                "max_connections": null,
                "mem_limit": null,
                "mem_reservation": null,
                "mem_shares": null,
                "mem_shares_level": null,
                "memory_mb": 4096,
                "memory_reservation_lock": null,
                "nested_virt": null,
                "num_cpu_cores_per_socket": null,
                "num_cpus": 2,
                "scsi": "paravirtual",
                "secure_boot": null,
                "version": null,
                "virt_based_security": null,
                "vpmc_enabled": null
            },
            "hostname": "vcenter.internal.borsdomain.net",
            "is_template": false,
            "linked_clone": false,
            "name": "test_vm_0001",
            "name_match": "first",
            "networks": [
                {
                    "device_type": "vmxnet3",
                    "name": "pg_vmnet_lan"
                }
            ],
            "nvdimm": {
                "label": null,
                "size_mb": 1024,
                "state": null
            },
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "port": 443,
            "proxy_host": null,
            "proxy_port": null,
            "resource_pool": null,
            "snapshot_src": null,
            "state": "poweredon",
            "state_change_timeout": 0,
            "template": null,
            "use_instance_uuid": false,
            "username": "ansible@vsphere.local",
            "uuid": null,
            "validate_certs": false,
            "vapp_properties": [],
            "wait_for_customization": false,
            "wait_for_customization_timeout": 3600,
            "wait_for_ip_address": false,
            "wait_for_ip_address_timeout": 300
        }
    }
}

MSG:

Network 'pg_vmnet_lan' does not exist.

PLAY RECAP ********************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

Playbook run took 0 days, 0 hours, 0 minutes, 0 seconds
Saturday 11 November 2023  20:50:39 +0100 (0:00:00.483)       0:00:00.534 ***** 
=============================================================================== 
Create a virtual machine ----------------------------------------------------------------------------------- 0.48s
/Users/bor/git/ansible/pr_manage_pb/deploy_vm.yml:8 ----------------------------------------------------------


User used have permisison to see and use all network?have you tried starting from template?

Thanks

Its a permissions issue.

The ansible@vsphere.local is (incorrectly I suppose) created as an Administrator btw, but when I removed the network section, figuring I’d create without it and add it afterwards, I got this:

pyVmomi.VmomiSupport.vim.fault.NoPermission: (vim.fault.NoPermission) {
   dynamicType = <unset>,
   dynamicProperty = (vmodl.DynamicProperty) [],
   msg = 'Permission to perform this operation was denied.',
   faultCause = <unset>,
   faultMessage = (vmodl.LocalizableMessage) [],
   object = 'vim.Folder:group-v2002',
   privilegeId = 'VirtualMachine.Inventory.Create',
   missingPrivileges = (vim.fault.NoPermission.EntityPrivileges) [
      (vim.fault.NoPermission.EntityPrivileges) {
         dynamicType = <unset>,
         dynamicProperty = (vmodl.DynamicProperty) [],
         entity = 'vim.Folder:group-v2002',
         privilegeIds = (str) [
            'VirtualMachine.Inventory.Create'

I then replaced with the default Administrator@vsphere.local and it created it without issue.

That initial error message was just stupid and put me on the wrong track.

Thanks for the help, appreciate it :smiley:

1 Like

Great to know, so set it to solution because someone can have same issue.

And yes vmware community is very “poor” in error message.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.