From a0b4462aea1a3294d69dc487b02c22cddf08d9cd Mon Sep 17 00:00:00 2001 From: Matthieu Fronton Date: Mon, 7 May 2018 12:20:34 +0200 Subject: [PATCH] vmware_guest: cast vlan to int or str when relevant (#39726) `network['vlan']` should be a VLAN ID Integers passed around using jinja variable references are converted to strings (see # 9362) The # 32738 PR should allow using 'NativeType' in ansible Explicitly converting to integer will make the module works as expected with or without the NativeType support `network['vlan']` can also be a VLAN NAME (fallback) Explicitly converting to string will make the module works as expected with or without the NativeType support --- lib/ansible/modules/cloud/vmware/vmware_guest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/cloud/vmware/vmware_guest.py b/lib/ansible/modules/cloud/vmware/vmware_guest.py index e984c5031d..f52b87e12e 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_guest.py +++ b/lib/ansible/modules/cloud/vmware/vmware_guest.py @@ -1004,10 +1004,10 @@ class PyVmomiHelper(PyVmomi): dvps = self.cache.get_all_objs(self.content, [vim.dvs.DistributedVirtualPortgroup]) for dvp in dvps: if hasattr(dvp.config.defaultPortConfig, 'vlan') and \ - dvp.config.defaultPortConfig.vlan.vlanId == network['vlan']: + dvp.config.defaultPortConfig.vlan.vlanId == int(network['vlan']): network['name'] = dvp.config.name break - if dvp.config.name == network['vlan']: + if dvp.config.name == str(network['vlan']): network['name'] = dvp.config.name break else: