From ef13f0f3890be5c51790094c7764a8245c45f6b6 Mon Sep 17 00:00:00 2001 From: Lemar Carthens Date: Tue, 16 May 2017 11:47:49 -0400 Subject: [PATCH] vmware_guest: Fix VM creation when adding a network device without a MAC address (#24138) * vmware_guest: Fix VM creation when adding a network device without a MAC address * Provide python2.4 compatibility --- lib/ansible/module_utils/vmware.py | 10 ++++++++-- lib/ansible/modules/cloud/vmware/vmware_guest.py | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/ansible/module_utils/vmware.py b/lib/ansible/module_utils/vmware.py index 5bec0600ba..592d35d05e 100644 --- a/lib/ansible/module_utils/vmware.py +++ b/lib/ansible/module_utils/vmware.py @@ -238,13 +238,19 @@ def gather_vm_facts(content, vm): if not hasattr(entry, 'macAddress'): continue + if entry.macAddress: + mac_addr = entry.macAddress + mac_addr_dash = mac_addr.replace(':', '-') + else: + mac_addr = mac_addr_dash = None + factname = 'hw_eth' + str(ethernet_idx) facts[factname] = { 'addresstype': entry.addressType, 'label': entry.deviceInfo.label, - 'macaddress': entry.macAddress, + 'macaddress': mac_addr, 'ipaddresses': net_dict.get(entry.macAddress, None), - 'macaddress_dash': entry.macAddress.replace(':', '-'), + 'macaddress_dash': mac_addr_dash, 'summary': entry.deviceInfo.summary, } facts['hw_interfaces'].append('eth' + str(ethernet_idx)) diff --git a/lib/ansible/modules/cloud/vmware/vmware_guest.py b/lib/ansible/modules/cloud/vmware/vmware_guest.py index 3dc9ed59d8..4afb8f2d70 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_guest.py +++ b/lib/ansible/modules/cloud/vmware/vmware_guest.py @@ -399,7 +399,6 @@ class PyVmomiDeviceHelper(object): (device_type, device_infos['name'])) nic.device.wakeOnLanEnabled = True - nic.device.addressType = 'assigned' nic.device.deviceInfo = vim.Description() nic.device.deviceInfo.label = device_label nic.device.deviceInfo.summary = device_infos['name'] @@ -408,7 +407,10 @@ class PyVmomiDeviceHelper(object): nic.device.connectable.allowGuestControl = True nic.device.connectable.connected = True if 'mac' in device_infos: + nic.device.addressType = 'assigned' nic.device.macAddress = device_infos['mac'] + else: + nic.device.addressType = 'generated' return nic