Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vmware_guest always change network port on dvs #498

Open
uutest74 opened this issue Nov 13, 2020 · 18 comments · May be fixed by #1997
Open

vmware_guest always change network port on dvs #498

uutest74 opened this issue Nov 13, 2020 · 18 comments · May be fixed by #1997
Labels
bug This issue/PR relates to a bug cloud module module needs_verified Needs to reproduced before processing plugins plugin (any type) python3 waiting_on_contributor Needs help. Feel free to engage to get things unblocked

Comments

@uutest74
Copy link

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:

@ansibullbot
Copy link

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
Copy link

@ansibullbot ansibullbot added bug This issue/PR relates to a bug cloud module module needs_triage Needs a first human triage before being processed. plugins plugin (any type) python3 labels Jan 15, 2021
@ansibullbot
Copy link

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

@Akasurde Akasurde added needs_verified Needs to reproduced before processing waiting_on_contributor Needs help. Feel free to engage to get things unblocked and removed needs_triage Needs a first human triage before being processed. labels Jan 27, 2021
@usscarter
Copy link
Contributor

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

@lshake
Copy link

lshake commented May 3, 2021

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
Copy link

Rylon commented May 18, 2021

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
Copy link

Rylon commented May 18, 2021

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
Copy link

Rylon commented May 20, 2021

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
Copy link
Contributor

+1

@malfter
Copy link

malfter commented Mar 9, 2022

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

@MallocArray
Copy link
Contributor

Still appears to be present

@Akasurde any update?

@cooling75
Copy link

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
Copy link

okopop commented Oct 24, 2022

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

@mwdohmen
Copy link

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
Copy link

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
Copy link
Contributor

I have the same issue.

Ansible: 2.15.0
community.vmware: 3.5.0
vSphere: 7.0.3

@MallocArray
Copy link
Contributor

Any update?

@ihumster
Copy link
Collaborator

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.

@tvarohohlavy tvarohohlavy linked a pull request Feb 9, 2024 that will close this issue
Yannik added a commit to Yannik/community.vmware that referenced this issue Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug cloud module module needs_verified Needs to reproduced before processing plugins plugin (any type) python3 waiting_on_contributor Needs help. Feel free to engage to get things unblocked
Projects
None yet
Development

Successfully merging a pull request may close this issue.