ansible-collections / netapp.ontap

Ansible collection to support NetApp ONTAP configuration.
https://galaxy.ansible.com/netapp/ontap
GNU General Public License v3.0
51 stars 34 forks source link

na_ontap_broadcast_domain doesnt correctly modifying a broadcast domain's ports using REST #210

Open hashi825 opened 1 month ago

hashi825 commented 1 month ago

Summary

When providing a broadcast domain that already contains existing ports and requires adding new ports, using REST will add ALL ports to the REST Patch request due to this statement which prevents actually only returning the ports to add https://github.com/ansible-collections/netapp.ontap/blob/78486a16018f1c3f1d8cf133f6f4b0b39ba4bcb9/plugins/modules/na_ontap_broadcast_domain.py#L586-L599

https://github.com/ansible-collections/netapp.ontap/blob/78486a16018f1c3f1d8cf133f6f4b0b39ba4bcb9/plugins/modules/na_ontap_broadcast_domain.py#L466-L474

ports_to_add provides the correct list of ports to add get_ports_rest then checks self.desired_ports which contains all ports found from the ports parameter of the module. This causes the module to send a patch request to api/network/ethernet/ports that essentially removes/readds ports that were already in the broadcast domain.

Removing the if statement seems to provide the desired behaviour.

Component Name

na_ontap_broadcast_domain

Ansible Version

$ ansible --version
ansible [core 2.15.0]
  config file = ##/ansible.cfg
  configured module search path = ['/home/##/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = ##/venv/lib64/python3.9/site-packages/ansible
  ansible collection location = ##
  executable location = ##/bin/ansible
  python version = 3.9.18 (main, Jan  4 2024, 00:00:00) [GCC 11.4.1 20230605 (Red Hat 11.4.1-2)] (##/venv/bin/python3.9)
  jinja version = 3.1.2
  libyaml = True

ONTAP Collection Version

Collection            Version
--------------------- -------
ansible.posix         1.5.4  
community.general     7.2.0  
community.hashi_vault 4.2.0  
netapp.ontap          22.11.0
netbox.netbox         3.13.0

ONTAP Version

##::> version
NetApp Release 9.13.1P7: Wed Jan 24 16:17:54 UTC 2024

Playbook

- name: Modify broadcast domain
      gather_facts: false
      # Use local host for delegation
    connection: local
    hosts: all
    vars_prompt:
    - name: ontap_username
      prompt: Enter username for ontap_username
      private: false
    - name: ontap_password
      prompt: Enter password
      private: true
    vars:
        broadcast_domains:
          - name: cluster_mgmt
            mtu: 1500
            ports:
             - srva001ppa1:a0a-111
             - srva001ppa1:a1a-111
             - srva001ppa2:a0a-111
             - srva001ppa2:a1a-111
             - srva001ppa3:a0a-111
             - srva001ppa3:a1a-111
             - srva001ppa4:a0a-111
             - srva001ppa4:a1a-111
             - srva001ppa5:a0a-111
             - srva001ppa5:a1a-111
             - srva001ppa6:a0a-111
             - srva001ppa6:a1a-111
             - srva001ppa7:a0a-111
             - srva001ppa7:a1a-111
             - srva001ppa7:a2a-111
             - srva001ppa8:a0a-111
             - srva001ppa8:a1a-111
             - srva001ppa8:a2a-111

        tasks:
        - name: Create Broadcast Domains
          netapp.ontap.na_ontap_broadcast_domain:
            state: present
            name: "{{ item.name }}"
            mtu: "{{ item.mtu }}"
            ports: "{{ item.ports }}"
            ipspace: Default
            hostname: "{{ inventory_hostname }}"
            username: "{{ ontap_username }}"
            password: "{{ ontap_password }}"
            https: true
            validate_certs: false
          with_items: "{{ broadcast_domains }}"
          when: broadcast_domains != None

Steps to Reproduce

- name: Create Broadcast Domains
  netapp.ontap.na_ontap_broadcast_domain:
    state: present
    name: "{{ item.name }}"
    mtu: "{{ item.mtu }}"
    ports: "{{ item.ports }}"
    ipspace: Default
    hostname: "{{ inventory_hostname }}"
    username: "{{ ontap_username }}"
    password: "{{ ontap_password }}"
    https: true
    validate_certs: "{{ ontap_validate_certs }}"
  with_items: "{{ broadcast_domains }}"
  when: broadcast_domains != None

Expected Results

Expected that module will only add MISSING broadcast domain ports and not try and PATCH existing ports.

Actual Results

msg: 'calling: network/ethernet/ports/fbec63a4-af37-11eb-b786-00a098dc46e4: got {''message'': ''Port "###:a1a-111" cannot be used because it is currently the home port or current port of a LIF.'', ''code'': ''1377608''}.'
csahu1 commented 1 month ago

hi @hashi825, Results shown above mentions about the error i.e. the port cannot be used because it is currently the home port or the current port of a LIF. Can you please refer to the below KB and try running this module again? https://kb.netapp.com/on-prem/ontap/OHW/OHW-KBs/Unable_to__add_a_port_to_broadcast_domain

hashi825 commented 1 month ago

hi @hashi825, Results shown above mentions about the error i.e. the port cannot be used because it is currently the home port or the current port of a LIF. Can you please refer to the below KB and try running this module again? https://kb.netapp.com/on-prem/ontap/OHW/OHW-KBs/Unable_to__add_a_port_to_broadcast_domain

Hey @csahu1 thats not the issue, the module is attempting to remove existing ports in the broadcast domain instead of adding the missing ports. I've pointed the problem out in the code. This doesn't happen when using the module in ZAPI as the ZAPI call in this situation would add ports where as the REST function uses a PATCH request which would run on the existing ports in the list resulting in attempting to remove the ports.