From c4984a4c4c5e96b36d336b9b6b8113b006deefab Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Tue, 22 Aug 2017 13:52:51 +0530 Subject: Handle AttributeError in vmware module_utils When vm has no MAC address assigned to it. Fix handles attribute error if MAC address is not set. Fixes: #28471 Signed-off-by: Abhijeet Kasurde --- lib/ansible/module_utils/vmware.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/ansible/module_utils/vmware.py b/lib/ansible/module_utils/vmware.py index b29b0d7cd3..71adda1e82 100644 --- a/lib/ansible/module_utils/vmware.py +++ b/lib/ansible/module_utils/vmware.py @@ -238,13 +238,18 @@ def gather_vm_facts(content, vm): if not hasattr(entry, 'macAddress'): continue + mac_addr = mac_addr_dash = None + if entry.macAddress: + mac_addr_dash = entry.macAddress.replace(':', '-') + mac_addr = entry.macAddress + 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)) -- cgit v1.2.1