Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vrf option to static routes #55298

Open
wants to merge 5 commits into
base: devel
from

Conversation

Projects
None yet
2 participants
@twbowman
Copy link

twbowman commented Apr 15, 2019

SUMMARY

Provide the option to add vrf besides the default vrf to static route commands.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

eos_static_route

vrf: add static route to a non default vrf

ADDITIONAL INFORMATION

We need to add static routes to VRFs other than the default one. I modified eos_static_route.py to achieve this.
I wrote a test playbook, see below, that checks ip route addition and deletion for the default VRF and a new vrf.

This is the result of the test playbook using the modified eos_static_route.py.

PLAY [tb-spine01] *******************************************************************************************************************

TASK [eos_facts] ********************************************************************************************************************
ok: [tb-spine01]

TASK [Arista Version] ***************************************************************************************************************
ok: [tb-spine01] => {
    "results.ansible_facts.ansible_net_version": "4.19.5M-2GB"
}

TASK [Create VRF test] **************************************************************************************************************
changed: [tb-spine01]

TASK [set_fact] *********************************************************************************************************************
ok: [tb-spine01]

TASK [Routes for testing] ***********************************************************************************************************
ok: [tb-spine01] => {
    "routes": [
        {
            "address": "1.1.1.0/24", 
            "next_hop": "4.4.4.4", 
            "vrf": "test"
        }, 
        {
            "address": "1.1.1.0/24", 
            "next_hop": "4.4.4.4"
        }
    ]
}

TASK [Add Static Routes in default vrf and test vrf] ********************************************************************************
changed: [tb-spine01]

TASK [Collect Running config] *******************************************************************************************************
ok: [tb-spine01]

TASK [Check for route in default vrf] ***********************************************************************************************
ok: [tb-spine01] => {
    "msg": [
        "ip route 1.1.1.0/24 4.4.4.4"
    ]
}

TASK [Check for route in test vrf] **************************************************************************************************
ok: [tb-spine01] => {
    "msg": [
        "ip route vrf test 1.1.1.0/24 4.4.4.4"
    ]
}

TASK [Remove Static Routes from default vrf and test vrf] ***************************************************************************
changed: [tb-spine01]

TASK [Collect Running config] *******************************************************************************************************
ok: [tb-spine01]

TASK [Check for route in default vrf, should be gone] *******************************************************************************
ok: [tb-spine01] => {
    "msg": []
}

TASK [Check for route in test vrf, should be gone] **********************************************************************************
ok: [tb-spine01] => {
    "msg": []
}

TASK [Delete VRF test] **************************************************************************************************************
changed: [tb-spine01]

PLAY RECAP **************************************************************************************************************************
tb-spine01                 : ok=14   changed=4    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0  

Below is an ansible playbook that i used to test the change:

---
- hosts: tb-spine01
  gather_facts: false
  become: "yes"

  tasks:
     - eos_facts:
       register: results

     - name: Arista Version
       debug:
          var: results.ansible_facts.ansible_net_version

     - name: Create VRF test
       eos_vrf:
          name: test
          state: present

     - set_fact:
          routes:
             - {address: 1.1.1.0/24, vrf: "test", next_hop: 4.4.4.4}
             - {address: 1.1.1.0/24, next_hop: 4.4.4.4}

     - name: Routes for testing
       debug:
          var: routes
     
     - name: Add Static Routes in default vrf and test vrf
       eos_static_route:
          aggregate: "{{ routes }}"
          state: present

     - name: Collect Running config
       eos_facts:
          gather_subset: config
       register: config

     - name: Check for route in default vrf
       debug:
          msg: "{{ config.ansible_facts.ansible_net_config.split('\n') | select('search', '^ip route 1.1.1.0/24') | list }}"

     - name: Check for route in test vrf
       debug:
          msg: "{{ config.ansible_facts.ansible_net_config.split('\n') | select('search', '^ip route vrf test 1.1.1.0/24') | list }}"

     - name: Remove Static Routes from default vrf and test vrf
       eos_static_route:
          aggregate: "{{ routes }}"
          state: absent

     - name: Collect Running config
       eos_facts:
          gather_subset: config
       register: config

     - name: Check for route in default vrf, should be gone
       debug:
          msg: "{{ config.ansible_facts.ansible_net_config.split('\n') | select('search', '^ip route 1.1.1.0/24') | list }}"

     - name: Check for route in test vrf, should be gone
       debug:
          msg: "{{ config.ansible_facts.ansible_net_config.split('\n') | select('search', '^ip route vrf test 1.1.1.0/24') | list }}"

     - name: Delete VRF test
       eos_vrf:
          name: test
          state: absent
@ansibot

This comment has been minimized.

Copy link
Contributor

ansibot commented Apr 15, 2019

@ansibot

This comment has been minimized.

Copy link
Contributor

ansibot commented Apr 15, 2019

@twbowman, just so you are aware we have a dedicated Working Group for network.
You can find other people interested in this in #ansible-network on Freenode IRC
For more information about communities, meetings and agendas see https://github.com/ansible/community

click here for bot help

Todd Bowman added some commits Apr 15, 2019

Todd Bowman
Todd Bowman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.