community.vmware icon indicating copy to clipboard operation
community.vmware copied to clipboard

vmware_guest always change network port on dvs

Open uutest74 opened this issue 4 years ago • 18 comments

SUMMARY

vmware_guest task always in changed state because module change network of vm and it reconnects to distributed switch port

ISSUE TYPE
  • Bug Report
COMPONENT NAME

vmware_guest networks

ANSIBLE VERSION
ansible 2.9.15
CONFIGURATION
HOST_KEY_CHECKING(/root/ansible.cfg) = False
INVENTORY_ENABLED(/root/ansible.cfg) = ['host_list', 'script', 'auto', 'yaml', 'ini', 'toml', 'vmware_vm_inventory']
OS / ENVIRONMENT

CentOS Linux release 8.1.1911 (Core) Python 3.6.8 vCenter 6.5 ESXi 6.5

STEPS TO REPRODUCE

Any simple playbook with vm creation. For example:

---
- hosts: localhost
  connection: local
  vars:
    vcenter_hostname: "vcenter-05"
    vcenter_username: "[email protected]"
    vcenter_password: "pass"
    datacenter: "vDC-01"
  tasks:
    - name:  Clone a virtual machine from Linux template and customize
      vmware_guest:
        hostname: "{{ vcenter_hostname }}"
        username: "{{ vcenter_username }}"
        password: "{{ vcenter_password }}"
        validate_certs:  False
        datacenter: "{{ datacenter }}"
        state: present
        folder: Test/TEST
        template: "TEMPLATE-CENTOS78-64-PACKER"
        name: "test-ans"
        cluster: "vCL-15-TEST"
        datastore: "ds-05"
        networks:
          - name: VLAN0002-vDS-01
            device_type: vmxnet3
            dvswitch_name: vDS-01

start this playbook 2+ times

EXPECTED RESULTS
PLAY [localhost] ************************************************************************************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************************************************************************************
ok: [localhost]

TASK [Clone a virtual machine from Linux template and customize] ************************************************************************************************************************
ok: [localhost]

PLAY RECAP ******************************************************************************************************************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
ACTUAL RESULTS

PLAY [localhost] ************************************************************************************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************************************************************************************
ok: [localhost]

TASK [Clone a virtual machine from Linux template and customize] ************************************************************************************************************************
changed: [localhost]

PLAY RECAP ******************************************************************************************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

In vSphere i see reconfigure event every time i start playbook

Reconfigured test-ans on esxi-075 in vDC-01. Modified: config.hardware.device(4000).backing.port.portKey: "4828" -> "4823"; config.hardware.device(4000).backing.port.connectionCookie: 1926530792 -> 2069119207; Added: Deleted:

uutest74 avatar Nov 13 '20 07:11 uutest74

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibullbot avatar Jan 15 '21 16:01 ansibullbot

cc @Akasurde @Tomorrow9 @goneri @lparkes @nerzhul @pdellaert @pgbidkar @warthog9 click here for bot help

ansibullbot avatar Jan 15 '21 16:01 ansibullbot

Files identified in the description:

  • [plugins/modules/vmware_guest.py](https://github.com/['ansible-collections/amazon.aws', 'ansible-collections/community.aws', 'ansible-collections/community.vmware']/blob/main/plugins/modules/vmware_guest.py)

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibullbot avatar Jan 15 '21 23:01 ansibullbot

I have verified the same in my environment. When I clone the VM, the NIC is modified, and causing a brief hiccup.

usscarter avatar Mar 24 '21 18:03 usscarter

Also verified on vSphere 6.7 with ansible 2.10.8 and community.vmware 1.9.0, also ansible 2.11.0 and community.vmware 1.9.1-dev8.

Reconfigured test100.lab.shakey.org on esx1.lab.shakey.org in Datacenter. Modified: config.hardware.device(4000).backing.port.portKey: "212" -> "211"; config.hardware.device(4000).backing.port.connectionCookie: 865024454 -> 982707693; Added: Deleted:

lshake avatar May 03 '21 15:05 lshake

I have this exact same issue. Always the portKey and connectionCookie are changed.

In my case every time I run the playbook the port key alternates between two values, but it is always changed.

Rylon avatar May 18 '21 17:05 Rylon

Update: I've pinpointed the problem to the check on line 1985 of vmware_guest.py: https://github.com/ansible-collections/community.vmware/blob/main/plugins/modules/vmware_guest.py#L1985-L1987

I added some debug logging to this section to figure out exactly what comparison was being made. I then ran my playbook and could see that the value of nic.device.deviceInfo.summary was DVSwitch: d5 6e 22 50 dd f2 94 7b-a6 1f b2 c2 e6 aa 0f but the value of network_name was the name of the DVSwitch, in our case dvs-test-switch-01.

This means the comparison fails, and nic.device.deviceInfo.summary gets updated to match the contents of network_name and nic_change_detected gets set to True, ultimately this causes an unnecessary config change to be made via self.configspec.deviceChange.append(nic) on line 2084.

I'll continue investigating tomorrow to see if this can be solved.

Rylon avatar May 18 '21 17:05 Rylon

I haven't made much progress, from what I can tell the name just isn't available from the network devices attached to the VM. I think we'd need to see if what looks like the DVSwitch UUID we do get back can be matched to the right UUID in a list of all DVSwitches, and use that to lookup the name to see if it is correct?

Rylon avatar May 20 '21 10:05 Rylon

+1

MallocArray avatar Feb 18 '22 18:02 MallocArray

Also verified on vSphere 7.0.2 with ansible 2.12.2 and community.vmware 2.1.0

malfter avatar Mar 09 '22 10:03 malfter

Still appears to be present

@Akasurde any update?

MallocArray avatar Jun 13 '22 13:06 MallocArray

I stumbled across this issue now too. With vSphere 6.5 it was working, on another vCenter with 7.0.3 it occurs. Ansible version 2.9.9 Collection version 2.5.0

cooling75 avatar Jul 04 '22 14:07 cooling75

Still the same: collection: 3.0.0 vsphere: 6.7 ansible-core: 2.13.5

okopop avatar Oct 24 '22 18:10 okopop

Hi, total noob here, feel free to ignore.

I have what I belive is the same issue, but for me the problem went away when I used "state: poweredon" instead of "state: present" on the vmware_guest. I have no clue why this makes a differense, but it does for me.

vSphere: 7.0.3 Ansible: 2.10.8

mwdohmen avatar Oct 30 '22 23:10 mwdohmen

Hi, total noob here, feel free to ignore.

I have what I belive is the same issue, but for me the problem went away when I used "state: poweredon" instead of "state: present" on the vmware_guest. I have no clue why this makes a differense, but it does for me.

vSphere: 7.0.3 Ansible: 2.10.8

It is not solution. Your playbook with state "powerdon" will check only VM powered on or exists, but won't check and reconfigure VM hardware if VM is already exists. https://docs.ansible.com/ansible/latest/collections/community/vmware/vmware_guest_module.html#parameter-state

solo-untld avatar Apr 11 '23 08:04 solo-untld

I have the same issue.

Ansible: 2.15.0 community.vmware: 3.5.0 vSphere: 7.0.3

devnull-mr avatar May 18 '23 19:05 devnull-mr

Any update?

MallocArray avatar Sep 11 '23 16:09 MallocArray

It is obvious that this module is not idempotent in the part of the code responsible for the network. Unfortunately, there are currently few maintainers working on the collection and it will take a lot of time to correct this non-idempotent behavior.

If I can reproduce the problem and have time, I will look into this problem.

ihumster avatar Sep 11 '23 16:09 ihumster