CiscoDevNet / ansible-dcnm

Apache License 2.0
47 stars 37 forks source link

dcnm_image_policy: overridden state should replace rather than merge image policy configurations #347

Open allenrobel opened 2 days ago

allenrobel commented 2 days ago

Community Note

Ansible Version and collection version

(.venv) arobel@AROBEL-M-G793 dcnm % ansible-galaxy collection list | grep dcnm
cisco.dcnm                               3.6.0
(.venv) arobel@AROBEL-M-G793 dcnm %
ansible [core 2.17.5]
  config file = /Users/arobel/.ansible.cfg
  configured module search path = ['/Users/arobel/repos/ansible_dev/dcnm_fabric/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/arobel/repos/ndfc-python/.venv/lib/python3.12/site-packages/ansible
  ansible collection location = /Users/arobel/repos/ansible/collections
  executable location = /Users/arobel/repos/ndfc-python/.venv/bin/ansible
  python version = 3.12.4 (main, Jun  6 2024, 18:26:44) [Clang 15.0.0 (clang-1500.3.9.4)] (/Users/arobel/repos/ndfc-python/.venv/bin/python)
  jinja version = 3.1.4
  libyaml = True

DCNM version

Affected module(s)

Ansible Playbook

---
- name: dcnm_image_policy override
  hosts: ndfc
  tasks:
    - name: override image policy KR5M
      cisco.dcnm.dcnm_image_policy:
        state: overridden
        config:
        - name: KR5M
          agnostic: false
          description: "KR5M overridden"
          epld_image: n9000-epld.10.2.5.M.img
          platform: N9K
          release: 10.2.5_nxos64-cs_64bit
          type: PLATFORM
      register: result

    - debug:
        var: result

Debug Output

Expected Behavior

The above playbook should replace the image policy configuration to match the playbook.

Actual Behavior

After running the above playbook, the image policy configuration is not changed.

Image policy before and after running the above playbook (notice it contains package configuration).

            {
                "agnostic": false,
                "epldImgName": "n9000-epld.10.2.5.M.img",
                "fabricPolicyName": null,
                "imagePresent": "Present",
                "nxosVersion": "10.2.5_nxos64-cs_64bit",
                "packageName": "cfg_cmp-0.3.1.0-1.x86_64.rpm",
                "platform": "N9K",
                "policyDescr": "KR5M overridden",
                "policyName": "KR5M",
                "policyType": "PLATFORM",
                "role": null,
                "rpmimages": "mtx-grpctunnel-2.1.0.0-10.4.1.lib32_64_n9000",
                "sequence_number": 2,
                "unInstall": false
            }

The package configuration should be removed by the playbook.

Steps to Reproduce

  1. Create an image policy that includes package install information. The following playbook should work.
---
- name: dcnm_image_policy override
  hosts: ndfc
  tasks:
    - name: Create policy KR5M with package install information
      cisco.dcnm.dcnm_image_policy:
        state: merged
        config:
        - name: KR5M
          agnostic: false
          description: "KR5M"
          epld_image: n9000-epld.10.2.5.M.img
          packages:
            install:
            - cfg_cmp-0.3.1.0-1.x86_64.rpm
            uninstall:
            - mtx-grpctunnel-2.1.0.0-10.4.1.lib32_64_n9000
          platform: N9K
          release: 10.2.5_nxos64-cs_64bit
          type: PLATFORM
  1. override the above with the playbook provided for overridden state.

The package information is not removed.

References

allenrobel commented 2 days ago

This issue is due to Merged().commit() -- rather than Replaced().commit() -- being called from within Overridden() in plugins/modules/dcnm_image_policy.py.

Will open a PR with the fix shortly.