We have a requirement to add a new NIC to several VMs on Vmware. To do this we are using ansible 2.9.3 and Python Version = 2.7.5
Here is the main playbook for the addition:
---
-
become: false
gather_facts: false
hosts: srvlist
tasks:
-
vmware_guest_network:
hostname: "{{ vcenter_hostname }}"
password: "{{ vcenter_password }}"
username: "{{ vcenter_username }}"
validate_certs: false
cluster: "{{ vm_cluster }}"
datacenter: "{{ vm_datacenter }}"
gather_network_info: false
name: "{{ vm_name }}"
networks:
-
device_type: vmxnet3
dvswitch_name: SWITCH1
name: "TESTPORTGROUP|TEST_APP"
start_connected: true
state: new
connected: true
delegate_to: localhost
vars:
vcenter_hostname: "any.sample.ip"
vcenter_password: mypassword
vcenter_username: administrator
vm_name: myNewDuplicatedVM
vm_cluster: ANY_CLUSTER_NAME
vm_datacenter: ANY_DATACENTER_NAME
Playbook is partially working, the issue from here is that the new NIC is not connected after the creation and we can see the properties correctly set up:
start_connected: true
state: new
connected: true
Also we can see on that the name variable inside networks uses the label/name for the appropriated portgroup: name: "TESTPORTGROUP|TEST_APP"
Remember this will be a new NIC; that means we have one already working.
Now, when I fetch for details using vmware_guest_network only to gather details from the VM it shows me a different name than expected:
ok: [vcenter_ip] => {
"vminfo": {
"changed": false,
"failed": false,
"network_data": {
"0": {
"allow_guest_ctl": true,
"connected": true,
"device_type": "VMXNET3",
"label": "Network adapter 1",
"mac_addr": "00:50:56:89:78:42",
"name": "DVSwitch: d9 27 09 50 0e ty b7 e2-91 b0 52 1d 6b 79 26 45",
"start_connected": true,
"unit_number": 7,
"wake_onlan": true
},
"1": {
"allow_guest_ctl": true,
"connected": false,
"device_type": "VMXNET3",
"label": "Network adapter 2",
"mac_addr": "00:50:56:89:a1:65",
"name": "TESTPORTGROUP|TEST_APP",
"start_connected": true,
"unit_number": 8,
"wake_onlan": true
}
}
}
The first one is the already present NIC and the second one is new one and is not connected as you can see. I don't know why is not connected and either why the name its different. I uderstand that nic stays in a disconnected state when there is an error in the customization stage but there is no errors show in vmlogs or on ansible.
I also tried using the entire, lets say, low level switch name but, as I expected, ansible fails and says that portgroup doesn't exist.
It may be a bug or I'm actually missing some configuration there.
Are you using vmware-workstation or vsphere for hosts your VMs? If you are using vsphere/vcenter, an easy way is use powerCLI to manage all vms with vsphere API. Just for add a new network card you use New-NetworkAdapter cmdlet, you can configure vs/vds, vlan, network card type, etc. Make you to take an snapshot before apply any change.
new-networkadapter -vm <vmname> -NetworkName "<Port group name>" -Type "VMXNET3" -startconnected
I had this same issue and found that the issue for me was that perl was not installed on the template/VM. Recommend installing perl on the template being used and trying again. You may find some clues in the open-vm-tools logs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With