Nic blank with Windows VM creation in specific environment

Hi folks,

I’m new to the Ansible community so pardon any beginner questions or lack there of :). I have a dev VMware environment 8u3, where I’m able to create a VM, set a nic, IP, join the domain etc, no issues. This same playbook in my prod environment (same version of VMware), doesn’t assign a nic to it. Once I manually do it, the playbook completes and life is good. I’ve tried a bunch of different stuff but I can’t figure out the issue. I’m getting plenty of errors, and breadcrumbs but am lost what to try next. From what I keep seeing, the template needs to have a nic connected and it does, but every time, it can’t assign the nic. Any ideas of something to try?

- name: Create VM
  community.vmware.vmware_guest:
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    validate_certs: "{{ vcenter_validate_certs }}"
    datacenter: "{{ datacenter }}"
    cluster: "{{ cluster }}"
    folder: "{{ vm_folder }}"
    name: "{{ vm_name }}"
    template: "{{ vm_template }}"
    state: poweredon
    hardware:
      memory_mb: "{{ vm_memory }}"
      num_cpus: "{{ vm_cpus }}"
    networks:
      - name: "{{ network }}"
        device_type: vmxnet3
        start_connected: true
        type: static
        ip: "{{ vm_ip }}"
        netmask: "{{ vm_netmask }}"
        gateway: "{{ vm_gateway }}"
        force: true
    wait_for_ip_address: yes
    wait_for_customization: yes
    customization:
     joindomain: "{{ domain_name | default(omit) }}"
     domainadmin: "{{ domain_admin_user | default(omit) }}"
     domainadminpassword: "{{ domain_admin_password | default(omit) }}"
     domain_ou: "{{ domain_ou | default(omit) }}"
     dns_servers: >-
       {{ [vm_dns1, vm_dns2] | select('defined') | list if domain_name is defined else omit }}
    annotation: "{{ vm_description | default('') }}"
  register: newvm

One more thing I just learned which may help, is that when I choose a network to assign the new machine is a traditional vlan backed network it assigns the nic, nice that are nsxt backed it doesn’t assign

I would guess that the module is unable to find the network you are trying to assign to the nic, and just skipping it.
Based on your second post, I’d guess the module was not written with nsx networks in mind

Thanks for the reply. The name is for sure right, since when I type it in wrong, I get an error saying it can’t find the network. It seems to be related to being part of a NSX network, but Im not sure the best approach here. I was assuming someone else ran into this before and could offer advice :slight_smile:

I think you’re right there. This module is quite old, and I’m pretty sure we haven’t tested this with NSX. On the other hand it shouldn’t make a difference if a portgroup is backed by NSX or not.

But I’m not really sure. At the end of the day, this module is a mess. It wants to do too many things at once, and this makes it hard to fix stuff. Apart from everything else, there are nearly 4k lines of code! That’s far too much…

Not to put too fine a point on this: If I (the maintainer of community.vmware) say I don’t understand it, that’s definitionally is a problem.

hahah oh boy, when you see there’s 4k lines of code what are you referring to?

The source code for the module you are using, community.vmware/plugins/modules/vmware_guest.py at main · ansible-collections/community.vmware · GitHub

Gotcha! Again sorry for the newby questions, should I be leveraging a different module for some of the basic VM creation and configuration I’m looking to do? Nothing crazy as you can see from the playbook.

That is the main module for managing VMs, but you do have other options.

You could use that module to create the VM, then use a different module to manage the NIC and apply customizations. There’s a customization module in VMware.vmware_rest Vmware.Vmware_Rest — Ansible Community Documentation

And there’s a community module to manage nics, community.vmware.vmware_guest_network module – Manage network adapters of specified virtual machine in given vCenter infrastructure — Ansible Community Documentation

There’s a module in vmware_rest to create/manage VMs too but I would not recommend it. There is a new module to manage VMs under development in vmware.vmware which will supersede the VMware.vmware_rest one.

That new module should be able to do the nic management you want, but it’s not production ready yet and customization will likely not be included. I’m the developer so you can try it out (at your own risk) and if nsx networks still don’t work, let me know and I can try to add support