Skip to content

iosxr_bgp_global - unable to add new VRF, when configured VRF names within router BGP are a combination of str and int #560

@mkyrc

Description

@mkyrc
SUMMARY

Unable to add VRF instance into router BGP configuration, when configured VRF names are combination of number and string. Example here:

#sh run router bgp 
Thu Aug 14 19:25:19.743 UTC
router bgp 65530
 bgp router-id 10.242.0.193
 address-family ipv4 unicast
  redistribute connected
 !
 address-family vpnv4 unicast
 !
 address-family vpnv6 unicast
 !
 address-family vpnv4 multicast
 !
 vrf 11001
  address-family ipv4 unicast
  !
  address-family ipv6 unicast
  !
  neighbor 10.240.120.2
   remote-as 65531
   description bgp peer
   address-family ipv4 unicast
    route-policy rpl-pass-all in
    route-policy rpl-prepend-as-path out
   !
  !
 !
 vrf test_test_22
  address-family ipv4 unicast
  !
 !
!

Playbook fails with this message:

"msg": "'<' not supported between instances of 'str' and 'int'"
ISSUE TYPE
  • Bug Report
COMPONENT NAME

cisco.iosxr.iosxr_bgp_global (version 11.1.0, 10.3.0)

ANSIBLE VERSION
ansible [core 2.17.13]
  config file = None
  configured module search path = ['/home/horol/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/horol/VENVS/saut/lib/python3.12/site-packages/ansible
  ansible collection location = /home/horol/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/horol/VENVS/saut/bin/ansible
  python version = 3.12.3 (main, Jun 18 2025, 17:59:45) [GCC 13.3.0] (/home/horol/VENVS/saut/bin/python)
  jinja version = 3.1.4
  libyaml = True
COLLECTION VERSION
# /home/horol/.ansible/collections/ansible_collections
Collection  Version
----------- -------
cisco.iosxr 11.1.0 
CONFIGURATION

OS / ENVIRONMENT

Linux Ubuntu 24-LTS

STEPS TO REPRODUCE
- name: "Cisco IOSXR: iosxr_bgp_global bug"
  hosts: "nkt-rt-xr2"
  gather_facts: false


  tasks:
    # you add vrf in cli or here with ansible task
    - name: "Add new VRFs"
      cisco.iosxr.iosxr_vrf_global:
        config:
          - name: "{{ item.vrf }}"
            description: "{{ item.descr | default(omit) }}"
            rd: "{{ item.rd }}"
        state: "{{ item.state | default('merged') }}"
      loop:
        [
          { vrf: "10", descr: "VRF 10", rd: "10:1" },
          { vrf: "vrf_20", descr: "VRF 20", rd: "20:1" },
        ]

    # this task fails with "'<' not supported between instances of 'str' and 'int'"
    - name: "Add VRF to BGP Global"
      cisco.iosxr.iosxr_bgp_global:
        config:
          as_number: "65530"
          vrfs:
            - vrf: "{{ item.vrf }}"
      loop: [{ vrf: "10" }, { vrf: "vrf_20" }]
EXPECTED RESULTS

Add new VRFs into router BGP configuartion.

ACTUAL RESULTS

It fails with above message.

SOLUTION

The issue is connected to this short code:

objs["vrfs"] = sorted(
                list(objs["vrfs"].values()),
                key=lambda k, sk="vrf": k[sk],
            )

When VRF names configured within router BGP is an combination of str and int, the sort() function failes.

Solution:

objs["vrfs"] = sorted(
                list(objs["vrfs"].values()),
                key=lambda k, sk="vrf": str(k[sk]),
            )

The question is why sort() is used at this place.

Our customer(s) are using VRF names with "int" and/or "str" as the name and we hit this issue. Maybe the above solution helps fix the issue shortly.

Thanks,
Martin

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions