ansible-collections / community.vmware

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

Managing DVS portgroups always show changes #1841

Open karlism opened 1 year ago

karlism commented 1 year ago
SUMMARY

Changed status is always true for tasks that manage DVS portgroups.

ISSUE TYPE
COMPONENT NAME

community.vmware.vmware_dvs_portgroup

ANSIBLE VERSION
ansible [core 2.14.3]
  config file = /home/username/.ansible.cfg
  configured module search path = ['/home/username/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.10/site-packages/ansible
  ansible collection location = /home/username/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.10.12 (main, Jun 19 2023, 16:27:15) [Clang 13.0.0 ] (/usr/local/bin/python3.10)
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION
$ ansible-galaxy collection list community.vmware 

# /usr/local/lib/python3.10/site-packages/ansible_collections
Collection       Version
---------------- -------
community.vmware 3.4.0  

# /home/username/.ansible/collections/ansible_collections
Collection       Version
---------------- -------
community.vmware 3.9.0  
CONFIGURATION
COLOR_VERBOSE(/home/username/.ansible.cfg) = cyan
CONFIG_FILE() = /home/username/.ansible.cfg
DEFAULT_HASH_BEHAVIOUR(/home/username/.ansible.cfg) = merge
DEFAULT_HOST_LIST(/home/username/.ansible.cfg) = ['/home/username/ansible/library/netbox/netbox.py']
DEFAULT_VAULT_PASSWORD_FILE(env: ANSIBLE_VAULT_PASSWORD_FILE) = /home/username/.ansible/vault_pass
INTERPRETER_PYTHON(/home/username/.ansible.cfg) = auto_silent
OS / ENVIRONMENT

OpenBSD 7.3 amd64

STEPS TO REPRODUCE
---
- hosts: "localhost"
  gather_facts: false

  tasks:
    - community.vmware.vmware_dvs_portgroup: &module_settings
        hostname: "{{ vcenter_hostname }}"
        username: "{{ vcenter_username }}"
        password: "{{ vcenter_password }}"
        validate_certs: "{{ vcenter_validate_certs }}"
        portgroup_name: "666-EXAMPLE"
        switch_name: "DEV_DVS"
        vlan_id: "666"
        port_binding: "static"
        state: present

    - community.vmware.vmware_dvs_portgroup:
        <<: *module_settings
EXPECTED RESULTS

First run of DVS portgroup configuration task should have changed status, but the second one should not as nothing has been changed.

ACTUAL RESULTS

Second run of the DVS portgroup configuration task shouldn't have any changes reported:

ansible-playbook dvs_portgroup.yml

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

TASK [community.vmware.vmware_dvs_portgroup] ******************************************
changed: [localhost]

TASK [community.vmware.vmware_dvs_portgroup] ******************************************
changed: [localhost]

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

Add to module_settings one more argument: port_allocation: elastic and try run.

karlism commented 1 year ago

@ihumster, thanks, that helped:

$ cat dvs_portgroup.yml 
---
- hosts: "localhost"
  gather_facts: false

  tasks:
    - community.vmware.vmware_dvs_portgroup: &module_settings
        hostname: "{{ vcenter_hostname }}"
        username: "{{ vcenter_username }}"
        password: "{{ vcenter_password }}"
        validate_certs: "{{ vcenter_validate_certs }}"
        portgroup_name: "666-EXAMPLE"
        switch_name: "DEV_DVS"
        vlan_id: "666"
        port_binding: "static"
        # test:
        port_allocation: "elastic"
        state: present

    - community.vmware.vmware_dvs_portgroup:
        <<: *module_settings

$ ansible-playbook dvs_portgroup.yml 

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

TASK [community.vmware.vmware_dvs_portgroup] ******************************************
ok: [localhost]

TASK [community.vmware.vmware_dvs_portgroup] ******************************************
ok: [localhost]

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

According to the documentation it should have been elastic already, is that a bug in documentation? "Will be elastic if not specified and port_binding is set to static."

ihumster commented 1 year ago

Most likely yes, there is an inaccuracy in the documentation. I'll look at the code and try to fix it in the documentation.