-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_paths.yml
47 lines (40 loc) · 1.46 KB
/
set_paths.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
---
- hosts: my_routers
gather_facts: no
connection: local
tasks:
# load all paths parameters into `paths` variable
- name: load defined paths
include_vars:
file: paths.yml
name: paths
# test prefered path using ping
- name: test paths using ping
ios_ping:
dest: "{{ paths[paths['prefered']][inventory_hostname]['next_hop'] }}"
count: 3
register: result_of_ping
ignore_errors: True
- name: select backup path
set_fact: {'active_path': "{{ paths['backup'] }}"}
when: result_of_ping|failed
- name: select prefered path
set_fact: {'active_path': "{{ paths['prefered'] }}"}
when: result_of_ping|succeeded
# start a block to remove old routes and install new ones
- name: remove old path and setup the new one
block:
- name: remove old routes
ios_config:
lines:
- "no ip route {{paths[active_path][inventory_hostname]['prefix']}} {{paths[active_path][inventory_hostname]['mask']}}"
authorize: yes
- name: setup new routes
ios_static_route:
prefix : "{{ paths[active_path][inventory_hostname]['prefix'] }}"
mask: "{{ paths[active_path][inventory_hostname]['mask'] }}"
next_hop: "{{ paths[active_path][inventory_hostname]['next_hop'] }}"
authorize: yes
rescue:
- debug:
msg: "An Error occured => rollback"