-
Notifications
You must be signed in to change notification settings - Fork 1
/
vrf-config-var.yml
87 lines (75 loc) · 2.27 KB
/
vrf-config-var.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
---
- name: IOS-XE - VRF configuration Playbook
hosts: csr
connection: local
gather_facts: no
# I decided to enter MPLS VPN variables directly into the Playbook. There are other options of course
# These 5 variables are all that is needed to get a basic VRF enabled, add the RD and RT,
# apply the VRF to an interface of choice, and then add the address-family to BGP (could be other protocol)
vars:
rd_id: '1:1'
rt_imp: '1:1'
rt_exp: '1:1'
vrf_name: ansible
int_name: loopback0
tasks:
- name: Get Login credentials
include_vars: /mnt/hgfs/vm_shared/ansible/access.yml
- name: Define Provider
set_fact:
provider:
# This references my "access.yml' file for login credentials
host: "{{ inventory_hostname }}"
username: "{{ access['username'] }}"
password: "{{ access['password'] }}"
# I used variables for all of the needed commands, offering flexibility for the operator
- name: Create VRF
ios_config:
provider: "{{ provider }}"
authorize: yes
lines:
- rd {{ rd_id }}
- route-target export {{ rt_exp }}
- route-target import {{ rt_imp }}
- address-family ipv4
- exit-address-family
parents: ['vrf definition {{ vrf_name }}']
match: exact
- name: Create and Attach VRF to Interface
ios_config:
provider: "{{ provider }}"
authorize: yes
lines:
- vrf forwarding {{ vrf_name }}
parents: ['interface {{ int_name }}']
match: exact
- name: Create and 'CONFIGURE VRF Under BGP'
ios_config:
provider: "{{ provider }}"
authorize: yes
lines:
- address-family ipv4 vrf {{ vrf_name }}
- exit-address-family
parents: ['router bgp 65000']
match: exact
- name: Run 'show VRF'
ios_command:
provider: "{{ provider }}"
authorize: yes
commands:
- show vrf
register: vrf
- debug: var=vrf.stdout_lines
- name: Run 'show IP VRF Interface'
ios_command:
provider: "{{ provider }}"
authorize: yes
commands:
- show ip vrf interface
register: brief
- debug: var=brief.stdout_lines
handlers:
- name: write config
ios_command:
commands: write memory
provider: "{{ provider }}"