From bb5052de70297196f4cafc2687e9abbc1d69f03a Mon Sep 17 00:00:00 2001 From: Aleksandr Kurbatov <ak@geant.org> Date: Thu, 9 Jan 2025 12:09:55 +0000 Subject: [PATCH] PE static routes as a separate step in P-to-PE WF --- .../nokia/router/base_static_routes.j2 | 2 +- .../router/pe_promotion_static_routes.j2 | 10 +++++++ .../roles/promote_p_to_pe/tasks/compile.yaml | 14 +++++++-- .../roles/promote_p_to_pe/tasks/deploy.yaml | 29 +++++++++++++++++++ .../roles/promote_p_to_pe/tasks/main.yml | 4 +-- .../roles/promote_p_to_pe/vars/main.yml | 1 + 6 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 geant/gap_ansible/roles/bc_templates/routers/nokia/router/pe_promotion_static_routes.j2 diff --git a/geant/gap_ansible/roles/bc_templates/routers/nokia/router/base_static_routes.j2 b/geant/gap_ansible/roles/bc_templates/routers/nokia/router/base_static_routes.j2 index d7d5ff5e..3fc1919e 100644 --- a/geant/gap_ansible/roles/bc_templates/routers/nokia/router/base_static_routes.j2 +++ b/geant/gap_ansible/roles/bc_templates/routers/nokia/router/base_static_routes.j2 @@ -1,4 +1,4 @@ - {% if router_role == 'pe' or is_pe_promotion_wf %} + {% if router_role == 'pe' %} {% with static_routes_obj=nokia_pe_static_routes %} {% include 'router/static_routes.j2' %} {% endwith %} diff --git a/geant/gap_ansible/roles/bc_templates/routers/nokia/router/pe_promotion_static_routes.j2 b/geant/gap_ansible/roles/bc_templates/routers/nokia/router/pe_promotion_static_routes.j2 new file mode 100644 index 00000000..d6098586 --- /dev/null +++ b/geant/gap_ansible/roles/bc_templates/routers/nokia/router/pe_promotion_static_routes.j2 @@ -0,0 +1,10 @@ +{% with static_routes_obj=nokia_pe_static_routes %} +<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:alu="urn:ietf:params:xml:ns:netconf:base:1.0"> + <configure xmlns="urn:nokia.com:sros:ns:yang:sr:conf"> + <router xmlns="urn:nokia.com:sros:ns:yang:sr:conf" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nokia-attr="urn:nokia.com:sros:ns:yang:sr:attributes"> + <router-name>Base</router-name> + {% include './static_routes.j2' %} + </router> + </configure> +</config> +{% endwith %} diff --git a/geant/gap_ansible/roles/promote_p_to_pe/tasks/compile.yaml b/geant/gap_ansible/roles/promote_p_to_pe/tasks/compile.yaml index 91ec6aac..5303efd3 100644 --- a/geant/gap_ansible/roles/promote_p_to_pe/tasks/compile.yaml +++ b/geant/gap_ansible/roles/promote_p_to_pe/tasks/compile.yaml @@ -3,7 +3,7 @@ - name: Set ansible host to localhost to compile config when router is offline when: - subscription.router.router_access_via_ts | ansible.builtin.bool ansible_host and + subscription.router.router_access_via_ts | ansible.builtin.bool and inventory_hostname == subscription.router.router_fqdn ansible.builtin.set_fact: ansible_host: "localhost" @@ -55,9 +55,19 @@ mode: '0755' delegate_to: localhost +- name: Print the template in "/var/tmp/ansible_run_{{ opid }}/pe_promotion_static_routes.conf" + when: verb == "add_pe_static_routes" + ansible.builtin.template: + src: "routers/{{ subscription.router.vendor }}/router/pe_promotion_static_routes.j2" + dest: "/var/tmp/ansible_run_{{ opid }}/pe_promotion_static_routes.conf" + lstrip_blocks: true + trim_blocks: true + mode: '0755' + delegate_to: localhost + - name: Set back ansible_host to target terminal server if needed when: - subscription.router.router_access_via_ts | ansible.builtin.bool ansible_host and + subscription.router.router_access_via_ts | ansible.builtin.bool and inventory_hostname == subscription.router.router_fqdn ansible.builtin.set_fact: ansible_host: "{{ subscription.router.router_site.site_ts_address }}" diff --git a/geant/gap_ansible/roles/promote_p_to_pe/tasks/deploy.yaml b/geant/gap_ansible/roles/promote_p_to_pe/tasks/deploy.yaml index 8d7019f0..54e6ef8f 100644 --- a/geant/gap_ansible/roles/promote_p_to_pe/tasks/deploy.yaml +++ b/geant/gap_ansible/roles/promote_p_to_pe/tasks/deploy.yaml @@ -58,6 +58,21 @@ register: output check_mode: true +- name: Add PE static routes on "{{ inventory_hostname }}" [CHECK ONLY][NOKIA] + when: >- + dry_run | ansible.builtin.bool + and verb == "add_pe_static_routes" + geant.gap_ansible.nokia_netconf_config: + format: xml + default_operation: merge + content: "{{ lookup('ansible.builtin.template', 'routers/{{ subscription.router.vendor }}/router/pe_promotion_static_routes.j2') }}" + commit: true + validate: true + config_mode: private + diff: true + register: output + check_mode: true + # - name: Fail if there is any diff # ansible.builtin.fail: # msg: Base config drift detected!!! @@ -121,3 +136,17 @@ config_mode: private diff: true check_mode: false + +- name: Add PE static routes on "{{ inventory_hostname }}" [AND COMMIT][NOKIA] + when: >- + not (dry_run | ansible.builtin.bool) + and verb == "add_pe_static_routes" + geant.gap_ansible.nokia_netconf_config: + format: xml + default_operation: merge + content: "{{ lookup('ansible.builtin.template', 'routers/{{ subscription.router.vendor }}/router/pe_promotion_static_routes.j2') }}" + commit: true + commit_comment: "{{ commit_comment }}" + config_mode: private + diff: true + check_mode: false diff --git a/geant/gap_ansible/roles/promote_p_to_pe/tasks/main.yml b/geant/gap_ansible/roles/promote_p_to_pe/tasks/main.yml index 0b6df2e1..c31c8db5 100644 --- a/geant/gap_ansible/roles/promote_p_to_pe/tasks/main.yml +++ b/geant/gap_ansible/roles/promote_p_to_pe/tasks/main.yml @@ -50,11 +50,11 @@ # ansible.builtin.include_tasks: configure_isis_overload.yaml - name: Include templates compilation - when: verb in [ 'deploy_pe_base_config', 'update_sdp_mesh' , 'deploy_routing_instances', 'delete_default_routes' ] + when: verb in [ 'deploy_pe_base_config', 'update_sdp_mesh', 'deploy_routing_instances', 'delete_default_routes', 'add_pe_static_routes' ] ansible.builtin.include_tasks: compile.yaml - name: Include deploy if selected - when: verb in [ 'deploy_pe_base_config', 'update_sdp_mesh', 'deploy_routing_instances', 'delete_default_routes' ] + when: verb in [ 'deploy_pe_base_config', 'update_sdp_mesh', 'deploy_routing_instances', 'delete_default_routes', 'add_pe_static_routes' ] ansible.builtin.include_tasks: deploy.yaml - name: PRE checks diff --git a/geant/gap_ansible/roles/promote_p_to_pe/vars/main.yml b/geant/gap_ansible/roles/promote_p_to_pe/vars/main.yml index b6ad21f8..0dae5d11 100644 --- a/geant/gap_ansible/roles/promote_p_to_pe/vars/main.yml +++ b/geant/gap_ansible/roles/promote_p_to_pe/vars/main.yml @@ -13,6 +13,7 @@ verbs: - check_base_ris # Check BGP summary for base VPRNs - pre_checks - post_checks + - add_pe_static_routes # Add PE-specific static routes as a separate WF step to avoid blackholing lo_ipv4_address: "{{ subscription.router.router_lo_ipv4_address }}" lo_ipv6_address: "{{ subscription.router.router_lo_ipv6_address }}" -- GitLab