POC prefix list loader tool. Reads from CSV and loads into IOSXE + assigns to route-map
This commit is contained in:
parent
a1a0a6309c
commit
c0037f946c
7
ios_devices/prefix_list.csv
Normal file
7
ios_devices/prefix_list.csv
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
Site,Description,SequenceNo,Prefix
|
||||||
|
site1,desc1,10,1.1.1.1/32
|
||||||
|
site2,desc2,20,2.2.2.2/32
|
||||||
|
site3,desc3,30,3.3.3.3/32
|
||||||
|
site5,Some text here,40,5.5.5.5/32
|
||||||
|
new_site1,aaaaaa,50,6.6.6.6/32
|
||||||
|
oooo_site,zzzzzz,60,7.7.7.7/32
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
---
|
|
||||||
prefixes:
|
|
||||||
- prefix: 1.1.1.1/32
|
|
||||||
sequence: 5
|
|
||||||
site_name: site_1
|
|
||||||
site_desc: some_desc
|
|
||||||
- prefix: 1.1.1.2/32
|
|
||||||
sequence: 10
|
|
||||||
- prefix: 1.1.1.4/32
|
|
||||||
sequence: 15
|
|
||||||
- prefix: 1.2.3.4/32
|
|
||||||
sequence: 20
|
|
||||||
@ -5,37 +5,50 @@
|
|||||||
connection: network_cli
|
connection: network_cli
|
||||||
roles:
|
roles:
|
||||||
- common
|
- common
|
||||||
vars_files:
|
|
||||||
- ./prefix_list.yml
|
|
||||||
tasks:
|
tasks:
|
||||||
|
|
||||||
- name: Collect current prefix list
|
# Read the CSV file and return a list of dicts with column names as keys
|
||||||
cisco.ios.ios_prefix_lists:
|
- name: Read CSV file with prefixes information
|
||||||
config:
|
read_csv:
|
||||||
state: gathered
|
path: prefixes_list.csv
|
||||||
register: result
|
register: prefix_list
|
||||||
|
delegate_to: localhost
|
||||||
|
|
||||||
- name: Print current prefix list information
|
- 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:
|
debug:
|
||||||
var: result.gathered
|
msg: "{{ config_before.stdout_lines }}"
|
||||||
|
|
||||||
- name: Validate new prefix list
|
- name: Apply new prefix lists
|
||||||
cisco.ios.ios_prefix_lists:
|
cisco.ios.ios_prefix_lists:
|
||||||
config:
|
config:
|
||||||
- afi: ipv4
|
- afi: ipv4
|
||||||
prefix_lists:
|
prefix_lists:
|
||||||
- name: MIGRATED_SITE_SUBNETS-DUBLIN
|
- name: "{{ item.Site }}"
|
||||||
description: SOME_DESCRIPTION-DUBLIN
|
description: "{{ item.Description }}"
|
||||||
entries:
|
entries:
|
||||||
- action: permit
|
- action: permit
|
||||||
prefix: "{{ item.prefix }}"
|
prefix: "{{ item.Prefix }}"
|
||||||
sequence: "{{ item.sequence | int }}"
|
sequence: 10
|
||||||
state: merged
|
state: merged
|
||||||
loop: "{{ prefixes }}"
|
loop: "{{ prefix_list.list }}"
|
||||||
register: new_prefix_list
|
|
||||||
|
|
||||||
- name: Display new prefix 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:
|
debug:
|
||||||
var: "{{item.rendered}}"
|
msg: "{{ config_after.stdout_lines }}"
|
||||||
loop: "{{ new_prefix_list.results }}"
|
|
||||||
|
|
||||||
|
- 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 }}"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user