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

Merged
merged 7 commits into from May 1, 2019
Merged

Conversation

twbowman
Copy link
Contributor

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
Copy link
Contributor

ansibot commented Apr 15, 2019

@ansibot
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

@ansibot ansibot added affects_2.9 This issue/PR affects Ansible v2.9 feature This issue/PR relates to a feature request. module This issue/PR relates to a module. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. needs_triage Needs a first human triage before being processed. networking Network category new_contributor This PR is the first contribution by a new community member. support:core This issue/PR relates to code supported by the Ansible Engineering Team. support:network This issue/PR relates to code supported by the Ansible Network Team. labels Apr 15, 2019
@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Apr 15, 2019
@ansibot ansibot removed the new_contributor This PR is the first contribution by a new community member. label Apr 24, 2019
README.rst Outdated Show resolved Hide resolved
@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. needs_triage Needs a first human triage before being processed. labels Apr 26, 2019
@ansibot ansibot removed the support:core This issue/PR relates to code supported by the Ansible Engineering Team. label Apr 26, 2019
@Qalthos Qalthos merged commit 6610d67 into ansible:devel May 1, 2019
ndclt pushed a commit to ndclt/ansible that referenced this pull request Jun 13, 2019
* added vrf to static route

* fix pylint errors

* version added 2.9 for vrf

* removed undocmented return values

* Update README.rst
@ansible ansible locked and limited conversation to collaborators Jul 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.9 This issue/PR affects Ansible v2.9 feature This issue/PR relates to a feature request. module This issue/PR relates to a module. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. networking Network category support:network This issue/PR relates to code supported by the Ansible Network Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants