Can now use native route_maps module from Ansible IOS collection. Had to upgrade Ansible to 2.10 and the collection to 4.2
This commit is contained in:
parent
502fb7f6a3
commit
8e74e002fc
@ -0,0 +1,54 @@
|
||||
---
|
||||
- name: Update device prefix list
|
||||
hosts: targets
|
||||
gather_facts: false
|
||||
connection: network_cli
|
||||
roles:
|
||||
- common
|
||||
tasks:
|
||||
|
||||
# Read the CSV file and return a list of dicts with column names as keys
|
||||
- name: Read CSV file with prefixes information
|
||||
read_csv:
|
||||
path: prefixes_list.csv
|
||||
register: prefix_list
|
||||
delegate_to: localhost
|
||||
|
||||
- name: Get current prefix lists config
|
||||
cisco.ios.ios_command:
|
||||
commands: show run | i ip prefix-list
|
||||
register: config_before
|
||||
|
||||
- name: Print current prefix lists config
|
||||
debug:
|
||||
msg: "{{ config_before.stdout_lines }}"
|
||||
|
||||
- name: Apply new prefix lists
|
||||
cisco.ios.ios_prefix_lists:
|
||||
config:
|
||||
- afi: ipv4
|
||||
prefix_lists:
|
||||
- name: "{{ item.Site }}"
|
||||
description: "{{ item.Description }}"
|
||||
entries:
|
||||
- action: permit
|
||||
prefix: "{{ item.Prefix }}"
|
||||
sequence: 10
|
||||
state: merged
|
||||
loop: "{{ prefix_list.list }}"
|
||||
|
||||
- name: Get updated prefix lists config
|
||||
cisco.ios.ios_command:
|
||||
commands: show run | i ip prefix-list
|
||||
register: config_after
|
||||
|
||||
- name: Print updated prefix lists config
|
||||
debug:
|
||||
msg: "{{ config_after.stdout_lines }}"
|
||||
|
||||
- name: Update target route map
|
||||
cisco.ios.ios_config:
|
||||
lines:
|
||||
- "route-map TEST_MAP permit {{ item.SequenceNo }}"
|
||||
- " match ip next-hop prefix-list {{ item.Site }}"
|
||||
loop: "{{ prefix_list.list }}"
|
||||
8
team-requests/kav-prefix-list/instructions.txt
Normal file
8
team-requests/kav-prefix-list/instructions.txt
Normal file
@ -0,0 +1,8 @@
|
||||
Ansible playbook for loading prefix-lists to IOS-XE device and attaching them to a route-map
|
||||
Setup:
|
||||
1 - Open "main.yml" from "roles/common/var/" and fill in the user, pass and enable secret
|
||||
2 - Open "pl_inventory.yml" and enter the IP(s) of the target device
|
||||
3 - Open "prefix_list.csv" and fill in the site information
|
||||
4 - Run the playbook with "ansible-playbook -i pl_inventory.yml prefix_list_audit.yml" to retrieve and print current prefix-lists
|
||||
5 - Run the playbook with "ansible-playbook -i pl_inventory.yml prefix_list_update.yml" to apply prefix-lists from the CSV file onto the device
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
---
|
||||
- name: Audit device prefix list
|
||||
- name: Audit device prefix lists
|
||||
hosts: targets
|
||||
gather_facts: false
|
||||
connection: network_cli
|
||||
@ -8,12 +8,12 @@
|
||||
|
||||
tasks:
|
||||
|
||||
- name: Collect current prefix list
|
||||
- name: Collect current prefix lists
|
||||
cisco.ios.ios_prefix_lists:
|
||||
config:
|
||||
state: gathered
|
||||
register: result
|
||||
|
||||
- name: Print current prefix list information
|
||||
- name: Print current prefix lists information
|
||||
debug:
|
||||
var: result.gathered
|
||||
@ -10,7 +10,7 @@
|
||||
# Read the CSV file and return a list of dicts with column names as keys
|
||||
- name: Read CSV file with prefixes information
|
||||
read_csv:
|
||||
path: prefixes_list.csv
|
||||
path: prefix_list.csv
|
||||
register: prefix_list
|
||||
delegate_to: localhost
|
||||
|
||||
@ -46,9 +46,37 @@
|
||||
debug:
|
||||
msg: "{{ config_after.stdout_lines }}"
|
||||
|
||||
- name: Update target route map
|
||||
cisco.ios.ios_config:
|
||||
lines:
|
||||
- "route-map TEST_MAP permit {{ item.SequenceNo }}"
|
||||
- " match ip next-hop prefix-list {{ item.Site }}"
|
||||
- name: Get current route maps
|
||||
cisco.ios.ios_command:
|
||||
commands: show run | sec route-map
|
||||
register: config_before
|
||||
|
||||
- name: Print current route maps config
|
||||
debug:
|
||||
msg: "{{ config_before.stdout_lines }}"
|
||||
|
||||
- name: Update target route maps
|
||||
cisco.ios.ios_route_maps:
|
||||
config:
|
||||
- route_map: ANSIBLE_MANAGED_ROUTE_MAP
|
||||
entries:
|
||||
- sequence: "{{ item.SequenceNo }}"
|
||||
action: permit
|
||||
description: "Attached to {{ item.Site }}"
|
||||
match:
|
||||
ip:
|
||||
next_hop:
|
||||
prefix_lists:
|
||||
- "{{ item.Site }}"
|
||||
state: merged
|
||||
loop: "{{ prefix_list.list }}"
|
||||
|
||||
- name: Get updated route maps
|
||||
cisco.ios.ios_command:
|
||||
commands: show run | sec route-map
|
||||
register: config_after
|
||||
|
||||
- name: Print updated route maps config
|
||||
debug:
|
||||
msg: "{{ config_after.stdout_lines }}"
|
||||
|
||||
|
||||
19
team-requests/kav-prefix-list/route_map_audit.yml
Normal file
19
team-requests/kav-prefix-list/route_map_audit.yml
Normal file
@ -0,0 +1,19 @@
|
||||
---
|
||||
- name: Audit device route maps
|
||||
hosts: targets
|
||||
gather_facts: false
|
||||
connection: network_cli
|
||||
roles:
|
||||
- common
|
||||
|
||||
tasks:
|
||||
|
||||
- name: Collect current route maps
|
||||
cisco.ios.ios_route_maps:
|
||||
config:
|
||||
state: gathered
|
||||
register: result
|
||||
|
||||
- name: Print current route maps information
|
||||
debug:
|
||||
var: result.gathered
|
||||
Loading…
Reference in New Issue
Block a user