Skip to content

Commit 5877a03

Browse files
authored
stable-4.x: Fix vmware_guest idempotency whith dvswitch (#2254)
SUMMARY This fixes the idempotency issue caused by nic.device.deviceInfo.summary containing DVSwitch: d5 6e 22 50 dd f2 94 7b-a6 1f b2 c2 e6 aa 0f instead of a readable portgroup name. ISSUE TYPE Bugfix Pull Request COMPONENT NAME vmware_guest ADDITIONAL INFORMATION Backport of #2000 #498
1 parent a1ea150 commit 5877a03

File tree

3 files changed

+31
-18
lines changed

3 files changed

+31
-18
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bugfixes:
2+
- vmware_guest - Fix vmware_guest always reporting change when using dvswitch.
3+
(https://github.com/ansible-collections/community.vmware/pull/2000).

plugins/modules/vmware_guest.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -1936,8 +1936,15 @@ def configure_network(self, vm_obj):
19361936
nic_change_detected = True
19371937

19381938
if nic.device.deviceInfo.summary != network_name:
1939-
nic.device.deviceInfo.summary = network_name
1940-
nic_change_detected = True
1939+
if 'DVSwitch' not in nic.device.deviceInfo.summary:
1940+
nic.device.deviceInfo.summary = network_name
1941+
nic_change_detected = True
1942+
else:
1943+
pg = find_obj(self.content, [vim.DistributedVirtualPortgroup], network_name)
1944+
if pg is None or nic.device.backing.port.portgroupKey != pg.key:
1945+
nic.device.deviceInfo.summary = network_name
1946+
nic_change_detected = True
1947+
19411948
if 'device_type' in network_devices[key]:
19421949
device = self.device_helper.nic_device_type.get(network_devices[key]['device_type'])
19431950
if not isinstance(nic.device, device):

tests/integration/targets/inventory_vmware_host_inventory/playbook/test_options.yml

+19-16
Original file line numberDiff line numberDiff line change
@@ -190,19 +190,22 @@
190190
- "'tag_category' in test_host.value"
191191

192192

193-
- name: Inventory 'resources' option
194-
include_tasks: build_inventory.yml
195-
vars:
196-
content: |-
197-
plugin: community.vmware.vmware_host_inventory
198-
strict: false
199-
resources:
200-
- datacenter:
201-
- DC0
202-
resources:
203-
- compute_resource:
204-
- DC0_C0_NOT_EXIST
205-
- name: Test 'resources' options with 'DC0_C0_NOT_EXIST'
206-
assert:
207-
that:
208-
- hostvars | length == 0
193+
# TODO enable again
194+
# https://forum.ansible.com/t/11073
195+
# https://github.com/ansible-collections/community.vmware/issues/2257
196+
# - name: Inventory 'resources' option
197+
# include_tasks: build_inventory.yml
198+
# vars:
199+
# content: |-
200+
# plugin: community.vmware.vmware_host_inventory
201+
# strict: false
202+
# resources:
203+
# - datacenter:
204+
# - DC0
205+
# resources:
206+
# - compute_resource:
207+
# - DC0_C0_NOT_EXIST
208+
# - name: Test 'resources' options with 'DC0_C0_NOT_EXIST'
209+
# assert:
210+
# that:
211+
# - hostvars | length == 0

0 commit comments

Comments
 (0)