ansible-collections / cisco.ios

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

ios_facts breaks with sub-interface index > 999 #972

Closed ghost closed 9 months ago

ghost commented 10 months ago
SUMMARY

When attempting to gather facts from an ISR4321 router (IOS-XE version 17.09.04a), the module errors out with what appears to be a truncated sub-interface index.

ISSUE TYPE
COMPONENT NAME

ios_facts

ANSIBLE VERSION

ansible [core 2.15.2]
  config file = /home/user/projects/ansible/netbox_device_onboard/ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/user/venv/lib64/python3.9/site-packages/ansible
  ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/user/venv/bin/ansible
  python version = 3.9.13 (main, Nov  9 2022, 13:16:24) [GCC 8.5.0 20210514 (Red Hat 8.5.0-15)] (/home/user/venv/bin/python3)
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION

# /home/user/venv/lib/python3.9/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 7.2.0  

# /home/user/venv/lib64/python3.9/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 7.2.0  
CONFIGURATION

ANSIBLE_HOME(/home/user/projects/ansible/netbox_device_onboard/ansible.cfg) = /home/user/.ansible
CALLBACKS_ENABLED(/home/user/projects/ansible/netbox_device_onboard/ansible.cfg) = ['ansible.posix.profile_tasks']
CONFIG_FILE() = /home/user/projects/ansible/netbox_device_onboard/ansible.cfg
DEFAULT_HOST_LIST(/home/user/projects/ansible/netbox_device_onboard/ansible.cfg) = ['/home/user/projects/ansible/netbox_dev>
DEFAULT_LOG_PATH(/home/user/projects/ansible/netbox_device_onboard/ansible.cfg) = /home/user/projects/ansible/netbox_device>
DEFAULT_ROLES_PATH(/home/user/projects/ansible/netbox_device_onboard/ansible.cfg) = ['/home/user/projects/ansible/roles']
DEFAULT_TRANSPORT(/home/user/projects/ansible/netbox_device_onboard/ansible.cfg) = smart
HOST_KEY_CHECKING(/home/user/projects/ansible/netbox_device_onboard/ansible.cfg) = False
NETWORK_GROUP_MODULES(/home/user/projects/ansible/netbox_device_onboard/ansible.cfg) = ['eos', 'nxos', 'ios', 'iosxr', 'junos', '>
TRANSFORM_INVALID_GROUP_CHARS(/home/user/projects/ansible/netbox_device_onboard/ansible.cfg) = silently
OS / ENVIRONMENT

RHEL 8.7

STEPS TO REPRODUCE

Simply run a fact gathering task (ios_facts) against the above ISR4321 running 17.09.04a code.

EXPECTED RESULTS

Example output from another router that has sub-interface values < 999:

        "GigabitEthernet0/0.100": {
            "bandwidth": 1000000,
            "description": "[ data ]",
            "duplex": null,
            "ipv4": [
                {
                    "address": "1.2.3.4",
                    "subnet": "24"
                }
            ],
            "lineprotocol": "up",
            "macaddress": "7cad.749f.6e38",
            "mediatype": null,
            "mtu": 1500,
            "operstatus": "up",
            "type": "Gigabit Ethernet"
        }
ACTUAL RESULTS

There is no GigabitEthernet0/0/0.1 - this sub-interface is actually GigabitEthernet0/0/0.1012. The "012" are being truncated for some unknown reason.


TASK [/home/user/projects/ansible/netbox_device_onboard/../roles/ios/netbox_gather_device_state : Gather IOS XE Facts] ***********
task path: /home/user/projects/ansible/roles/ios/netbox_gather_device_state/tasks/main.yml:2
Wednesday 15 November 2023  13:25:20 -0600 (0:00:00.229)       0:00:03.306 **** 
redirecting (type: terminal) ansible.builtin.ios to cisco.ios.ios
redirecting (type: cliconf) ansible.builtin.ios to cisco.ios.ios
<1.2.3.4> attempting to start connection
<1.2.3.4> using connection plugin ansible.netcommon.network_cli
Found ansible-connection at path /home/user/venv/bin/ansible-connection
<1.2.3.4> local domain socket does not exist, starting it
<1.2.3.4> control socket path is /home/user/.ansible/pc/45b96d6c6d
<1.2.3.4> Loading collection ansible.builtin from 
<1.2.3.4> Loading collection ansible.netcommon from /home/user/.ansible/collections/ansible_collections/ansible/netcommon
<1.2.3.4> Loading collection ansible.utils from /home/user/.ansible/collections/ansible_collections/ansible/utils
<1.2.3.4> redirecting (type: terminal) ansible.builtin.ios to cisco.ios.ios
<1.2.3.4> Loading collection cisco.ios from /home/user/.ansible/collections/ansible_collections/cisco/ios
<1.2.3.4> redirecting (type: cliconf) ansible.builtin.ios to cisco.ios.ios
<1.2.3.4> local domain socket listeners started successfully
<1.2.3.4> loaded cliconf plugin ansible_collections.cisco.ios.plugins.cliconf.ios from path /home/user/.ansible/collections/ansible_collections/cisco/ios/plugins/cliconf/ios.py for network_os ios
<1.2.3.4> ssh type is set to paramiko
<1.2.3.4> Loading collection ansible.builtin from 
<1.2.3.4> local domain socket path is /home/user/.ansible/pc/45b96d6c6d
redirecting (type: action) cisco.ios.ios_facts to cisco.ios.ios
redirecting (type: action) cisco.ios.ios_facts to cisco.ios.ios
<1.2.3.4> ANSIBLE_NETWORK_IMPORT_MODULES: enabled
<1.2.3.4> ANSIBLE_NETWORK_IMPORT_MODULES: found cisco.ios.ios_facts  at /home/user/.ansible/collections/ansible_collections/cisco/ios/plugins/modules/ios_facts.py
<1.2.3.4> ANSIBLE_NETWORK_IMPORT_MODULES: running cisco.ios.ios_facts
<1.2.3.4> ANSIBLE_NETWORK_IMPORT_MODULES: complete
fatal: [network_device]: FAILED! => {
    "changed": false,
    "module_stderr": "'GigabitEthernet0/0/0.1'",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error"
}
...ignoring
ghost commented 10 months ago

Bug update:

The problem exists with 17.09.04a code, as running fact gathering against 17.03.05 works fine even with a sub-interface index of 1012 ( GigabitEthernet0/0/0.1012 ).

I just tested this task against another ISR4321 running 17.09.04a code, and when I configured a sub-interface "GigabitEthernet0/0/1.1012", the task COMPLETED. When I created a "GigabitEthernet0/0/0.1012" sub-interface, the task FAILED.

roverflow commented 9 months ago

@abs-netdevops, are you certain that the issue is limited to version 17.09.04a and works correctly with all other versions?

I recommend updating to the latest collection version, 6.0.0, released recently. I've submitted a pull request with a unit test specifically checking for sub-interfaces greater than 999. Let me know if this resolves the issue. Thank you.