ansible-collections / cisco.ios

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

ios_facts for lag_interfaces returns a list when lags exist and an empty dictionary when lags do not exist #814

Closed wollmannbruno closed 1 year ago

wollmannbruno commented 1 year ago
SUMMARY

When a switch has lag interfaces configured, the facts module returns a list of dictionaries for these interfaces. When a switch has no lag interfaces configured, the facts module returns an empty dictionary.

This inconsistency causes extra processing of the variable in a play.

ISSUE TYPE
COMPONENT NAME

lag_interfaces inside the cisco.ios.ios_facts module.

ANSIBLE VERSION
ansible [core 2.13.8]
  config file = /home/bwollmann/repos/iac/ansible.cfg
  configured module search path = ['/home/bwollmann/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/bwollmann/venv/ans2_9_24/lib/python3.8/site-packages/ansible
  ansible collection location = /home/bwollmann/.ansible/collections
  executable location = /home/bwollmann/venv/ans2_9_24/bin/ansible
  python version = 3.8.10 (default, Mar 13 2023, 10:26:41) [GCC 9.4.0]
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION
# /home/bwollmann/.ansible/collections/ansible_collections
Collection Version
---------- -------
cisco.ios  4.5.0  
CONFIGURATION
COLLECTIONS_PATHS(/home/bwollmann/repos/iac/ansible.cfg) = ['/home/bwollmann/.ansible/collections']
DEFAULT_GATHERING(/home/bwollmann/repos/iac/ansible.cfg) = explicit
DEFAULT_HOST_LIST(/home/bwollmann/repos/iac/ansible.cfg) = ['/home/bwollmann/repos/iac/hosts']
DEFAULT_ROLES_PATH(/home/bwollmann/repos/iac/ansible.cfg) = ['/home/bwollmann/repos/iac/roles']
DEFAULT_VAULT_PASSWORD_FILE(/home/bwollmann/repos/iac/ansible.cfg) = /home/bwollmann/repos/vault
HOST_KEY_CHECKING(/home/bwollmann/repos/iac/ansible.cfg) = False
OS / ENVIRONMENT
Cisco IOS XE Software, Version 16.12.04 Cisco IOS Software [Gibraltar], Catalyst L3 Switch Software (CAT3K_CAA-UNIVERSALK9-M), Version 16.12.4, RELEASE SOFTWARE (fc5) ROM: IOS-XE ROMMON BOOTLDR: CAT3K_CAA Boot Loader (CAT3K_CAA-HBOOT-M) Version 4.78, RELEASE SOFTWARE (P) Switch Ports Model SW Version SW Image Mode
* 1 32 WS-C3850-24U 16.12.4 CAT3K_CAA-UNIVERSALK9 INSTALL
STEPS TO REPRODUCE

Use the ios_facts module to gather the lag_interfaces from switches with and without lag interfaces configured.

---
- name: GET FACTS
  hosts: swt-rga-01-dside,swt-rga-a500-a
  gather_facts: no

  tasks:
    - name: GET LAG INTERFACES
      cisco.ios.ios_facts:
        gather_network_resources: lag_interfaces
      register: lag_ints

    - name: ASSOCIATE VARIABLE TO LIST OF LAG INTERFACES FROM FACTS
      ansible.builtin.set_fact:
        lags: "{{ lag_ints['ansible_facts']['ansible_network_resources']['lag_interfaces'] }}"

    - name: PRINT LAGS
      ansible.builtin.debug:
        var: lags
EXPECTED RESULTS

I would expect that the same type of data structure be returned whether there are lag interfaces configured or not. Either return a list in both cases or a dictionary in both cases.

ok: [swt-rga-01-dside] => {
    "lags": []
}
ok: [swt-rga-a500-a] => {
    "lags": [
        {
            "members": [
                {
                    "member": "TenGigabitEthernet1/1/3",
                    "mode": "active"
                },
                {
                    "member": "TenGigabitEthernet2/1/3",
                    "mode": "active"
                }
            ],
            "name": "Port-channel5"
        }
    ]
}

empty_list

ACTUAL RESULTS

ios_facts returns a dictionary when no lag interfaces exist and a list when they do exist.

ok: [swt-rga-01-dside] => {
    "lags": {}
}
ok: [swt-rga-a500-a] => {
    "lags": [
        {
            "members": [
                {
                    "member": "TenGigabitEthernet1/1/3",
                    "mode": "active"
                },
                {
                    "member": "TenGigabitEthernet2/1/3",
                    "mode": "active"
                }
            ],
            "name": "Port-channel5"
        }
    ]
}

empty_dict

KB-perByte commented 1 year ago

@wollmannbruno, would you share the output of your sh running-config | section ^interface command from the appliance where there are no facts generated? As I don't see the issue at my end, the device when some lag-specific configuration is present,

  lags:
  - members:
    - member: GigabitEthernet2
      mode: active
    name: Port-channel10
  - members:
    - member: GigabitEthernet4
      mode: active
    name: Port-channel20
  - members:
    - {}
    name: Port-channel30

and when no lag-specific configuration is present

  lags:
  - members:
    - {}
    name: Port-channel10
  - members:
    - {}
    name: Port-channel20
  - members:
    - {}
    name: Port-channel30

Regards

wollmannbruno commented 1 year ago

@KB-perByte , Your example of "no lag-specific configuration" shows that there is in fact lag configured on that switch. The presence of Port-channelxx gives that away. These lags may not have member interfaces configured anymore, but the lag interfaces exist.

Here is the output for sh run | ^interface. It contains no Port-channel interfaces.

swt-rga-01-dside#sh run | sec ^interface
interface GigabitEthernet0/0
 vrf forwarding Mgmt-vrf
 no ip address
 negotiation auto
interface GigabitEthernet1/0/1
 switchport access vlan 400
 switchport mode access
 switchport nonegotiate
 switchport voice vlan 735
 no snmp trap link-status
 storm-control broadcast level pps 1k
 storm-control multicast level pps 2k
 storm-control action trap
 spanning-tree portfast
 service-policy input FIVE-MODEL-QOS
 service-policy output EGRESS-FIVE-MODEL-QOS
interface GigabitEthernet1/0/2
 switchport access vlan 400
 switchport mode access
 switchport nonegotiate
 switchport voice vlan 735
 no snmp trap link-status
 storm-control broadcast level pps 1k
 storm-control multicast level pps 2k
 storm-control action trap
 spanning-tree portfast
 service-policy input FIVE-MODEL-QOS
 service-policy output EGRESS-FIVE-MODEL-QOS
interface GigabitEthernet1/0/3
 description SPS Programming
 switchport access vlan 236
 switchport mode access
 switchport nonegotiate
 switchport voice vlan 735
 no snmp trap link-status
 storm-control broadcast level pps 1k
 storm-control multicast level pps 2k
 storm-control action trap
 spanning-tree portfast
 service-policy input FIVE-MODEL-QOS
 service-policy output EGRESS-FIVE-MODEL-QOS
interface GigabitEthernet1/0/4
 switchport access vlan 400
 switchport mode access
 switchport nonegotiate
 switchport voice vlan 735
 no snmp trap link-status
 storm-control broadcast level pps 1k
 storm-control multicast level pps 2k
 storm-control action trap
 spanning-tree portfast
 service-policy input FIVE-MODEL-QOS
 service-policy output EGRESS-FIVE-MODEL-QOS
interface GigabitEthernet1/0/5
 switchport access vlan 711
 switchport mode access
 switchport nonegotiate
 switchport voice vlan 731
 device-tracking attach-policy IPDT_POLICY
 authentication periodic
 authentication timer reauthenticate server
 access-session control-direction in
 access-session port-control auto
 mab
 no snmp trap link-status
 dot1x pae authenticator
 dot1x timeout tx-period 7
 dot1x max-reauth-req 3
 storm-control broadcast level pps 1k
 storm-control multicast level pps 2k
 storm-control action trap
 spanning-tree portfast
 service-policy type control subscriber PORT_AUTH_PMAP
 service-policy input FIVE-MODEL-QOS
 service-policy output EGRESS-FIVE-MODEL-QOS
interface GigabitEthernet1/0/6
 switchport access vlan 711
 switchport mode access
 switchport nonegotiate
 switchport voice vlan 731
 device-tracking attach-policy IPDT_POLICY
 authentication periodic
 authentication timer reauthenticate server
 access-session control-direction in
 access-session port-control auto
 mab
 no snmp trap link-status
 dot1x pae authenticator
 dot1x timeout tx-period 7
 dot1x max-reauth-req 3
 storm-control broadcast level pps 1k
 storm-control multicast level pps 2k
 storm-control action trap
 spanning-tree portfast
 service-policy type control subscriber PORT_AUTH_PMAP
 service-policy input FIVE-MODEL-QOS
 service-policy output EGRESS-FIVE-MODEL-QOS
interface GigabitEthernet1/0/7
 switchport access vlan 711
 switchport mode access
 switchport nonegotiate
 switchport voice vlan 731
 device-tracking attach-policy IPDT_POLICY
 authentication periodic
 authentication timer reauthenticate server
 access-session control-direction in
 access-session port-control auto
 mab
 no snmp trap link-status
 dot1x pae authenticator
 dot1x timeout tx-period 7
 dot1x max-reauth-req 3
 storm-control broadcast level pps 1k
 storm-control multicast level pps 2k
 storm-control action trap
 spanning-tree portfast
 service-policy type control subscriber PORT_AUTH_PMAP
 service-policy input FIVE-MODEL-QOS
 service-policy output EGRESS-FIVE-MODEL-QOS
interface GigabitEthernet1/0/8
 switchport access vlan 711
 switchport mode access
 switchport nonegotiate
 switchport voice vlan 731
 device-tracking attach-policy IPDT_POLICY
 authentication periodic
 authentication timer reauthenticate server
 access-session control-direction in
 access-session port-control auto
 mab
 no snmp trap link-status
 dot1x pae authenticator
 dot1x timeout tx-period 7
 dot1x max-reauth-req 3
 storm-control broadcast level pps 1k
 storm-control multicast level pps 2k
 storm-control action trap
 spanning-tree portfast
 service-policy type control subscriber PORT_AUTH_PMAP
 service-policy input FIVE-MODEL-QOS
 service-policy output EGRESS-FIVE-MODEL-QOS
interface GigabitEthernet1/0/9
 switchport access vlan 711
 switchport mode access
 switchport nonegotiate
 switchport voice vlan 731
 device-tracking attach-policy IPDT_POLICY
 authentication periodic
 authentication timer reauthenticate server
 access-session control-direction in
 access-session port-control auto
 mab
 no snmp trap link-status
 dot1x pae authenticator
 dot1x timeout tx-period 7
 dot1x max-reauth-req 3
 storm-control broadcast level pps 1k
 storm-control multicast level pps 2k
 storm-control action trap
 spanning-tree portfast
 service-policy type control subscriber PORT_AUTH_PMAP
 service-policy input FIVE-MODEL-QOS
 service-policy output EGRESS-FIVE-MODEL-QOS
interface GigabitEthernet1/0/10
 switchport access vlan 711
 switchport mode access
 switchport nonegotiate
 switchport voice vlan 731
 device-tracking attach-policy IPDT_POLICY
 authentication periodic
 authentication timer reauthenticate server
 access-session control-direction in
 access-session port-control auto
 mab
 no snmp trap link-status
 dot1x pae authenticator
 dot1x timeout tx-period 7
 dot1x max-reauth-req 3
 storm-control broadcast level pps 1k
 storm-control multicast level pps 2k
 storm-control action trap
 spanning-tree portfast
 service-policy type control subscriber PORT_AUTH_PMAP
 service-policy input FIVE-MODEL-QOS
 service-policy output EGRESS-FIVE-MODEL-QOS
interface GigabitEthernet1/0/11
 switchport access vlan 711
 switchport mode access
 switchport nonegotiate
 switchport voice vlan 731
 device-tracking attach-policy IPDT_POLICY
 authentication periodic
 authentication timer reauthenticate server
 access-session control-direction in
 access-session port-control auto
 mab
 no snmp trap link-status
 dot1x pae authenticator
 dot1x timeout tx-period 7
 dot1x max-reauth-req 3
 storm-control broadcast level pps 1k
 storm-control multicast level pps 2k
 storm-control action trap
 spanning-tree portfast
 service-policy type control subscriber PORT_AUTH_PMAP
 service-policy input FIVE-MODEL-QOS
 service-policy output EGRESS-FIVE-MODEL-QOS
interface GigabitEthernet1/0/12
 switchport access vlan 711
 switchport mode access
 switchport nonegotiate
 switchport voice vlan 731
 device-tracking attach-policy IPDT_POLICY
 authentication periodic
 authentication timer reauthenticate server
 access-session control-direction in
 access-session port-control auto
 mab
 no snmp trap link-status
 dot1x pae authenticator
 dot1x timeout tx-period 7
 dot1x max-reauth-req 3
 storm-control broadcast level pps 1k
 storm-control multicast level pps 2k
 storm-control action trap
 spanning-tree portfast
 service-policy type control subscriber PORT_AUTH_PMAP
 service-policy input FIVE-MODEL-QOS
 service-policy output EGRESS-FIVE-MODEL-QOS
interface GigabitEthernet1/0/13
 switchport access vlan 711
 switchport mode access
 switchport nonegotiate
 switchport voice vlan 731
 device-tracking attach-policy IPDT_POLICY
 authentication periodic
 authentication timer reauthenticate server
 access-session control-direction in
 access-session port-control auto
 mab
 no snmp trap link-status
 dot1x pae authenticator
 dot1x timeout tx-period 7
 dot1x max-reauth-req 3
 storm-control broadcast level pps 1k
 storm-control multicast level pps 2k
 storm-control action trap
 spanning-tree portfast
 service-policy type control subscriber PORT_AUTH_PMAP
 service-policy input FIVE-MODEL-QOS
 service-policy output EGRESS-FIVE-MODEL-QOS
interface GigabitEthernet1/0/14
 switchport access vlan 711
 switchport mode access
 switchport nonegotiate
 switchport voice vlan 731
 device-tracking attach-policy IPDT_POLICY
 authentication periodic
 authentication timer reauthenticate server
 access-session control-direction in
 access-session port-control auto
 mab
 no snmp trap link-status
 dot1x pae authenticator
 dot1x timeout tx-period 7
 dot1x max-reauth-req 3
 storm-control broadcast level pps 1k
 storm-control multicast level pps 2k
 storm-control action trap
 spanning-tree portfast
 service-policy type control subscriber PORT_AUTH_PMAP
 service-policy input FIVE-MODEL-QOS
 service-policy output EGRESS-FIVE-MODEL-QOS
interface GigabitEthernet1/0/15
 switchport access vlan 711
 switchport mode access
 switchport nonegotiate
 switchport voice vlan 731
 device-tracking attach-policy IPDT_POLICY
 authentication periodic
 authentication timer reauthenticate server
 access-session control-direction in
 access-session port-control auto
 mab
 no snmp trap link-status
 dot1x pae authenticator
 dot1x timeout tx-period 7
 dot1x max-reauth-req 3
 storm-control broadcast level pps 1k
 storm-control multicast level pps 2k
 storm-control action trap
 spanning-tree portfast
 service-policy type control subscriber PORT_AUTH_PMAP
 service-policy input FIVE-MODEL-QOS
 service-policy output EGRESS-FIVE-MODEL-QOS
interface GigabitEthernet1/0/16
 switchport access vlan 711
 switchport mode access
 switchport nonegotiate
 switchport voice vlan 731
 device-tracking attach-policy IPDT_POLICY
 authentication periodic
 authentication timer reauthenticate server
 access-session control-direction in
 access-session port-control auto
 mab
 no snmp trap link-status
 dot1x pae authenticator
 dot1x timeout tx-period 7
 dot1x max-reauth-req 3
 storm-control broadcast level pps 1k
 storm-control multicast level pps 2k
 storm-control action trap
 spanning-tree portfast
 service-policy type control subscriber PORT_AUTH_PMAP
 service-policy input FIVE-MODEL-QOS
 service-policy output EGRESS-FIVE-MODEL-QOS
interface GigabitEthernet1/0/17
 switchport access vlan 711
 switchport mode access
 switchport nonegotiate
 switchport voice vlan 731
 device-tracking attach-policy IPDT_POLICY
 authentication periodic
 authentication timer reauthenticate server
 access-session control-direction in
 access-session port-control auto
 mab
 no snmp trap link-status
 dot1x pae authenticator
 dot1x timeout tx-period 7
 dot1x max-reauth-req 3
 storm-control broadcast level pps 1k
 storm-control multicast level pps 2k
 storm-control action trap
 spanning-tree portfast
 service-policy type control subscriber PORT_AUTH_PMAP
 service-policy input FIVE-MODEL-QOS
 service-policy output EGRESS-FIVE-MODEL-QOS
interface GigabitEthernet1/0/18
 switchport access vlan 711
 switchport mode access
 switchport nonegotiate
 switchport voice vlan 731
 device-tracking attach-policy IPDT_POLICY
 authentication periodic
 authentication timer reauthenticate server
 access-session control-direction in
 access-session port-control auto
 mab
 no snmp trap link-status
 dot1x pae authenticator
 dot1x timeout tx-period 7
 dot1x max-reauth-req 3
 storm-control broadcast level pps 1k
 storm-control multicast level pps 2k
 storm-control action trap
 spanning-tree portfast
 service-policy type control subscriber PORT_AUTH_PMAP
 service-policy input FIVE-MODEL-QOS
 service-policy output EGRESS-FIVE-MODEL-QOS
interface GigabitEthernet1/0/19
 switchport access vlan 711
 switchport mode access
 switchport nonegotiate
 switchport voice vlan 731
 device-tracking attach-policy IPDT_POLICY
 authentication periodic
 authentication timer reauthenticate server
 access-session control-direction in
 access-session port-control auto
 mab
 no snmp trap link-status
 dot1x pae authenticator
 dot1x timeout tx-period 7
 dot1x max-reauth-req 3
 storm-control broadcast level pps 1k
 storm-control multicast level pps 2k
 storm-control action trap
 spanning-tree portfast
 service-policy type control subscriber PORT_AUTH_PMAP
 service-policy input FIVE-MODEL-QOS
 service-policy output EGRESS-FIVE-MODEL-QOS
interface GigabitEthernet1/0/20
 switchport access vlan 711
 switchport mode access
 switchport nonegotiate
 switchport voice vlan 731
 device-tracking attach-policy IPDT_POLICY
 authentication periodic
 authentication timer reauthenticate server
 access-session control-direction in
 access-session port-control auto
 mab
 no snmp trap link-status
 dot1x pae authenticator
 dot1x timeout tx-period 7
 dot1x max-reauth-req 3
 storm-control broadcast level pps 1k
 storm-control multicast level pps 2k
 storm-control action trap
 spanning-tree portfast
 service-policy type control subscriber PORT_AUTH_PMAP
 service-policy input FIVE-MODEL-QOS
 service-policy output EGRESS-FIVE-MODEL-QOS
interface GigabitEthernet1/0/21
 switchport access vlan 711
 switchport mode access
 switchport nonegotiate
 switchport voice vlan 731
 device-tracking attach-policy IPDT_POLICY
 authentication periodic
 authentication timer reauthenticate server
 access-session control-direction in
 access-session port-control auto
 mab
 no snmp trap link-status
 dot1x pae authenticator
 dot1x timeout tx-period 7
 dot1x max-reauth-req 3
 storm-control broadcast level pps 1k
 storm-control multicast level pps 2k
 storm-control action trap
 spanning-tree portfast
 service-policy type control subscriber PORT_AUTH_PMAP
 service-policy input FIVE-MODEL-QOS
 service-policy output EGRESS-FIVE-MODEL-QOS
interface GigabitEthernet1/0/22
 switchport access vlan 711
 switchport mode access
 switchport nonegotiate
 switchport voice vlan 731
 device-tracking attach-policy IPDT_POLICY
 authentication periodic
 authentication timer reauthenticate server
 access-session control-direction in
 access-session port-control auto
 mab
 no snmp trap link-status
 dot1x pae authenticator
 dot1x timeout tx-period 7
 dot1x max-reauth-req 3
 storm-control broadcast level pps 1k
 storm-control multicast level pps 2k
 storm-control action trap
 spanning-tree portfast
 service-policy type control subscriber PORT_AUTH_PMAP
 service-policy input FIVE-MODEL-QOS
 service-policy output EGRESS-FIVE-MODEL-QOS
interface GigabitEthernet1/0/23
 switchport access vlan 713
 switchport mode access
 switchport nonegotiate
 switchport voice vlan 731
 device-tracking attach-policy IPDT_POLICY
 authentication periodic
 authentication timer reauthenticate server
 access-session control-direction in
 access-session port-control auto
 mab
 no snmp trap link-status
 dot1x pae authenticator
 dot1x timeout tx-period 7
 dot1x max-reauth-req 3
 storm-control broadcast level pps 1k
 storm-control multicast level pps 2k
 storm-control action trap
 spanning-tree portfast
 service-policy type control subscriber PORT_AUTH_PMAP
 service-policy input FIVE-MODEL-QOS
 service-policy output EGRESS-FIVE-MODEL-QOS
interface GigabitEthernet1/0/24
 description Trunk to SWT-RGA-A100-A
 switchport trunk native vlan 99
 switchport trunk allowed vlan 1,236,249,400,711,713,731
 switchport mode trunk
 switchport nonegotiate
 service-policy output EGRESS-FIVE-MODEL-QOS
interface GigabitEthernet1/1/1
interface GigabitEthernet1/1/2
interface GigabitEthernet1/1/3
interface GigabitEthernet1/1/4
interface TenGigabitEthernet1/1/1
interface TenGigabitEthernet1/1/2
interface TenGigabitEthernet1/1/3
interface TenGigabitEthernet1/1/4
interface Vlan1
 no ip address
 shutdown
interface Vlan249
 description InBand Management
 ip address x.x.x.x y.y.y.y
swt-rga-01-dside#