cisco.ios icon indicating copy to clipboard operation
cisco.ios copied to clipboard

ios_static_routes does not configure IPv6 routes in VRF

Open marehler opened this issue 2 years ago • 1 comments

SUMMARY

Static IPv6 routes are created in the default routing context instead of the specified VRF.

Playbook - IPv6 routes shall be created in VRF blue:

---

- name: Configure static routes
  hosts: CSR1Kv-0
  connection: local
  gather_facts: false

  tasks:
  - name: Create static routes
    cisco.ios.ios_static_routes:
      config:
      - vrf: blue
        address_families:
        - afi: ipv6
          routes:
          - dest: FD3D:3D:A:16::/64
            next_hops:
            - forward_router_address: FD3D:3D:A:14::2
          - dest: FD3D:3D:A:17::/64
            next_hops:
            - forward_router_address: FD3D:3D:A:14::2

Result - However routes are incorrectly created in the default routing context:

sr1000v-1#show running-config | include ip route|ipv6 route
<...>>
ipv6 route FD3D:3D:A:16::/64 FD3D:3D:A:14::2
ipv6 route FD3D:3D:A:17::/64 FD3D:3D:A:14::2

In case of IPv4, static routes are correctly configured in the specified VRF, i.e. the issue is specific to IPv6.

Cross-check: When using the ios_config module instead of the ios_static_routes modules, the routes are configured correctly:

Playbook:

---

- name: Configure static routes
  hosts: CSR1Kv-0
  connection: local
  gather_facts: false

  tasks:
  - name: Create static routes
    cisco.ios.ios_config:
      lines:
      - ipv6 route vrf blue FD3D:3D:A:16::/64 FD3D:3D:A:14::2
      - ipv6 route vrf blue FD3D:3D:A:17::/64 FD3D:3D:A:14::2

Result:

csr1000v-1#show running-config | include ip route|ipv6 route
<...>
ipv6 route vrf blue FD3D:3D:A:16::/64 FD3D:3D:A:14::2
ipv6 route vrf blue FD3D:3D:A:17::/64 FD3D:3D:A:14::2

Therefore I think this is a bug in the ios_static_routes module.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

cisco.ios.ios_static_routes

ANSIBLE VERSION
ansible [core 2.13.1]                                                                                                                                
  config file = /home/marehler/Documents/Ansible/ansible.cfg                                                                                         
  configured module search path = ['/home/marehler/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']                                  
  ansible python module location = /usr/local/lib/python3.10/dist-packages/ansible                                                                   
  ansible collection location = /home/marehler/.ansible/collections:/usr/share/ansible/collections                                                   
  executable location = /usr/local/bin/ansible                                                                                                       
  python version = 3.10.4 (main, Jun 29 2022, 12:14:53) [GCC 11.2.0]                                                                                 
  jinja version = 3.1.2                                                                                                                              
  libyaml = True
COLLECTION VERSION
# /usr/local/lib/python3.10/dist-packages/ansible_collections                                                                                        
Collection Version                                                                                                                                   
---------- -------                                                                                                                                   
cisco.ios  3.2.0 
CONFIGURATION
DEFAULT_HOST_LIST(/home/marehler/Documents/Ansible/ansible.cfg) = ['/home/marehler/Documents/Ansible/inventory/hosts.ini']                           
HOST_KEY_CHECKING(/home/marehler/Documents/Ansible/ansible.cfg) = False                                                                              
PERSISTENT_COMMAND_TIMEOUT(/home/marehler/Documents/Ansible/ansible.cfg) = 30                                                                        
PERSISTENT_CONNECT_TIMEOUT(/home/marehler/Documents/Ansible/ansible.cfg) = 60 
OS / ENVIRONMENT

Cisco IOS XE Software, Version 17.03.04a
Cisco IOS Software [Amsterdam], Virtual XE Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 17.3.4a, RELEASE SOFTWARE (fc3)

Cisco IOS Software, IOSv Software (VIOS-ADVENTERPRISEK9-M), Version 15.9(3)M4, RELEASE SOFTWARE (fc3)

STEPS TO REPRODUCE
---

- name: Configure static routes
  hosts: CSR1Kv-0
  connection: local
  gather_facts: false

  tasks:
  - name: Create static routes
    cisco.ios.ios_static_routes:
      config:
      - vrf: blue
        address_families:
        - afi: ipv6
          routes:
          - dest: FD3D:3D:A:16::/64
            next_hops:
            - forward_router_address: FD3D:3D:A:14::2
          - dest: FD3D:3D:A:17::/64
            next_hops:
            - forward_router_address: FD3D:3D:A:14::2
EXPECTED RESULTS
ipv6 route vrf blue FD3D:3D:A:16::/64 FD3D:3D:A:14::2
ipv6 route vrf blue FD3D:3D:A:17::/64 FD3D:3D:A:14::2
ACTUAL RESULTS
ipv6 route FD3D:3D:A:16::/64 FD3D:3D:A:14::2
ipv6 route FD3D:3D:A:17::/64 FD3D:3D:A:14::2

marehler avatar Sep 23 '22 06:09 marehler

Hi Martin, Thanks for notifying the community :)

The culprit appears to be in the following file: cisco/ios/plugins/module_utils/network/ios/config/static_routes/static_routes.py, starting from line 658:

if temp_want.get("afi") == "ipv4":
    cmd = "ip route "
    vrf = temp_want.get("vrf") # <- Can be moved out of if-section
    if vrf: # <- Missing in IPv6s elif!
        cmd = cmd + "vrf {0} ".format(vrf) # <- Missing in IPv6s elif!
    cmd = self.prepare_config_commands(temp_want, cmd)
elif temp_want.get("afi") == "ipv6":
    cmd = "ipv6 route "
    cmd = self.prepare_config_commands(temp_want, cmd)
commands.append(cmd)

The same goes for negating starting from line 737.

I can put a PR on this up for review, unless someones already working on it(?) It makes me wonder if there's a reason why the vrf is left out from the ipv6 section in the first place.. :)

Thanks again!

bentole avatar Sep 25 '22 19:09 bentole

Hi @KB-perByte Thank you very much for addressing and fixing this issue! Regards Martin

marehler avatar Oct 12 '22 11:10 marehler