ansible-collections / cisco.ios

Ansible Network Collection for Cisco IOS
GNU General Public License v3.0
261 stars 162 forks source link

cisco.ios.ios_vrf fail when sending status absent on missing VRF #1058

Open joakimnyden opened 3 weeks ago

joakimnyden commented 3 weeks ago
SUMMARY

The cisco.ios.ios_vrf module fail if we try to remove a vrf that does not exists in the config. Create works, and delete works if the vrf are there. This problem seem to be introduced in collection version 5.3, I had to go back to version 5.2 to make the module work.

ISSUE TYPE
COMPONENT NAME
  - name: delete_vrf - Delete VRF
    cisco.ios.ios_vrf:
      name: "{{ vrf_name }}"
      state: absent
ANSIBLE VERSION
ansible [core 2.15.2]
  config file = None
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
  ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.18 (main, Sep 22 2023, 17:58:34) [GCC 8.5.0 20210514 (Red Hat 8.5.0-20)] (/usr/bin/python3)
  jinja version = 3.1.3
  libyaml = True
COLLECTION VERSION
[user]# ansible-galaxy collection list cisco.ios
Collection Version
---------- -------
cisco.ios  8.0.0  
CONFIGURATION
OS / ENVIRONMENT

"ansible_net_iostype": "IOS-XE" "ansible_net_model": "C8500-12X4QC" "ansible_net_system": "ios" "ansible_net_version": "17.06.03a"

STEPS TO REPRODUCE
  1. the vrf should not be configured on the device
  2. call the module cisco.ios.ios_vrf with the state absent
  3. module will fail on collection 8.0.0
  4. If you run the same on collection 5.2.0, this will work.
  - name: delete_vrf - Delete VRF
    cisco.ios.ios_vrf:
      name: "{{ vrf_name }}"
      state: absent
EXPECTED RESULTS

The expected respond would be no change from module and without failure.

ACTUAL RESULTS
<10.10.10.10> Using network group action cisco.ios.ios for cisco.ios.ios_vrf
<NoExistingVrf> ANSIBLE_NETWORK_IMPORT_MODULES: enabled
<NoExistingVrf> ANSIBLE_NETWORK_IMPORT_MODULES: found cisco.ios.ios_vrf  at /usr/share/ansible/collections/ansible_collections/cisco/ios/plugins/modules/ios_vrf.py
<NoExistingVrf> ANSIBLE_NETWORK_IMPORT_MODULES: running cisco.ios.ios_vrf
<NoExistingVrf> ANSIBLE_NETWORK_IMPORT_MODULES: complete
<NoExistingVrf> ANSIBLE_NETWORK_IMPORT_MODULES: Result: {'failed': True, '_ansible_parsed': False, 'module_stdout': '', 'module_stderr': "'NoneType' object is not subscriptable", 'msg': 'MODULE FAILURE\nSee stdout/stderr for the exact error'}
fatal: [NoExistingVrf]: FAILED! => {
    "attempts": 3,
    "changed": false,
    "module_stderr": "'NoneType' object is not subscriptable",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error"
}
joakimnyden commented 3 weeks ago

https://github.com/ansible-collections/cisco.ios/commit/8a9d6c8f6e7d5f8e9ecf593e01e0c9139a389d56#diff-ede0fefaa17c7a86bff6a8d6fc55c4fcdbfc36b41a458c0ffdb3ad6597c5fbceR795-R806 This specific code-snippet introduced the issue, it works if I revert this part.