From 8e74e002fce81c594030a69dbc6f5fc5e84a9e91 Mon Sep 17 00:00:00 2001 From: Vlad R Date: Mon, 9 Jan 2023 18:27:47 +0000 Subject: [PATCH] Can now use native route_maps module from Ansible IOS collection. Had to upgrade Ansible to 2.10 and the collection to 4.2 --- .../prefix_list_update_workaround.yml | 54 +++++++++++++++++++ .../kav-prefix-list/instructions.txt | 8 +++ .../kav-prefix-list/prefix_list_audit.yml | 6 +-- .../kav-prefix-list/prefix_list_update.yml | 40 +++++++++++--- .../kav-prefix-list/route_map_audit.yml | 19 +++++++ 5 files changed, 118 insertions(+), 9 deletions(-) create mode 100644 team-requests/kav-prefix-list/artifacts/prefix_list_update_workaround.yml create mode 100644 team-requests/kav-prefix-list/instructions.txt create mode 100644 team-requests/kav-prefix-list/route_map_audit.yml diff --git a/team-requests/kav-prefix-list/artifacts/prefix_list_update_workaround.yml b/team-requests/kav-prefix-list/artifacts/prefix_list_update_workaround.yml new file mode 100644 index 0000000..c566a5b --- /dev/null +++ b/team-requests/kav-prefix-list/artifacts/prefix_list_update_workaround.yml @@ -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 }}" diff --git a/team-requests/kav-prefix-list/instructions.txt b/team-requests/kav-prefix-list/instructions.txt new file mode 100644 index 0000000..fd50d68 --- /dev/null +++ b/team-requests/kav-prefix-list/instructions.txt @@ -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 + diff --git a/team-requests/kav-prefix-list/prefix_list_audit.yml b/team-requests/kav-prefix-list/prefix_list_audit.yml index 3c6f8bf..0fd0f0d 100644 --- a/team-requests/kav-prefix-list/prefix_list_audit.yml +++ b/team-requests/kav-prefix-list/prefix_list_audit.yml @@ -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 \ No newline at end of file diff --git a/team-requests/kav-prefix-list/prefix_list_update.yml b/team-requests/kav-prefix-list/prefix_list_update.yml index c566a5b..953e952 100644 --- a/team-requests/kav-prefix-list/prefix_list_update.yml +++ b/team-requests/kav-prefix-list/prefix_list_update.yml @@ -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 }}" + diff --git a/team-requests/kav-prefix-list/route_map_audit.yml b/team-requests/kav-prefix-list/route_map_audit.yml new file mode 100644 index 0000000..4a60c61 --- /dev/null +++ b/team-requests/kav-prefix-list/route_map_audit.yml @@ -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 \ No newline at end of file