ansible-collections / community.vmware

Ansible Collection for VMware
GNU General Public License v3.0
349 stars 336 forks source link

vmware_guest always change network port on dvs #498

Open uutest74 opened 3 years ago

uutest74 commented 3 years ago
SUMMARY

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

ISSUE TYPE
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: "ans@vsphere.local"
    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:

ansibullbot commented 3 years ago

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 commented 3 years ago

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

ansibullbot commented 3 years ago

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

usscarter commented 3 years ago

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

lshake commented 3 years ago

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:

Rylon commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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?

MallocArray commented 2 years ago

+1

malfter commented 2 years ago

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

MallocArray commented 2 years ago

Still appears to be present

@Akasurde any update?

cooling75 commented 2 years ago

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

okopop commented 1 year ago

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

mwdohmen commented 1 year ago

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

solo-untld commented 1 year ago

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

devnull-mr commented 1 year ago

I have the same issue.

Ansible: 2.15.0 community.vmware: 3.5.0 vSphere: 7.0.3

MallocArray commented 1 year ago

Any update?

ihumster commented 1 year ago

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.