ansible-collections / cisco.nxos

Ansible Network Collection for Cisco NXOS
GNU General Public License v3.0
115 stars 109 forks source link

[nxos_prefix_lists] Fix idempotency issues caused by IP prefix notation discrepancies #894

Open Miyoshi-Ryota opened 1 week ago

Miyoshi-Ryota commented 1 week ago
SUMMARY

Fixed an issue where idempotency was not maintained due to discrepancies in the notation of IP prefixes. By introducing the ipaddress module to standardize prefixes, we ensure that the playbook and running-config prefixes are compared accurately, preventing unnecessary configuration changes.

For example, previously, a playbook specifying prefix: ::0/ and a running-config showing ipv6 prefix-list plist1 seq 10 permit 0::/0, or a playbook specifying prefix: 10.0.0.8/24 and a running-config showing ip prefix-list plist2 seq 10 permit 10.0.0.0/24, would result in unnecessary changes. With this update, such discrepancies are handled, maintaining idempotency and ensuring existing configurations are not repeatedly deleted and re-added.

Supplementary Information: The notation you enter in configure terminal and the notation in the show run output may differ on Nexus devices. Therefore, a simple text comparison could break idempotency.

An example is shown below.

# conf t
(config)# ipv6 prefix-list plist1 seq 10 permit ::/0
(config)# ip prefix-list plist2 seq 10 permit 10.0.0.8/24
(config)# exit
# show run | inc plist 
ip prefix-list plist2 seq 10 permit 10.0.0.0/24
ipv6 prefix-list plist1 seq 10 permit 0::/0
ISSUE TYPE
COMPONENT NAME

nxos_prefix_lists

ADDITIONAL INFORMATION

Before this change, when I executed the playbook below multiple times, the result would always be changed, and plist1 would be deleted and added each time.

- hosts: all
  gather_facts: no
  vars:
    ansible_connection: network_cli
    ansible_user: "hoo"
    ansible_password: "bar"
    ansible_network_os: cisco.nxos.nxos
  tasks:
    - name: prefixlists_always_changed
      cisco.nxos.nxos_prefix_lists:
        state: "overridden"
        config:
          - afi: ipv6
            prefix_lists:
            - entries:
              - action: permit
                prefix: ::0/0
                sequence: 10
              name: "plist1"