diff --git a/geant/gap_ansible/roles/iptrunk_migration/tasks/calculate_local_side.yaml b/geant/gap_ansible/roles/iptrunk_migration/tasks/calculate_local_side.yaml index 9f984c33478b5e290391ddc471f37300a6303597..a911001a42d65da6d5b709fab4fbf7ca000c3935 100644 --- a/geant/gap_ansible/roles/iptrunk_migration/tasks/calculate_local_side.yaml +++ b/geant/gap_ansible/roles/iptrunk_migration/tasks/calculate_local_side.yaml @@ -4,13 +4,6 @@ vars: query: "iptrunk.iptrunk_sides[?iptrunk_side_node.router_fqdn == '{{ inventory_hostname }}'] | [0]" - # - name: Show local info - # debug: - # msg: "{{ local_side }}" - # - # - name: Stop - # meta: end_play - - name: Load netconf connection config ansible.builtin.set_fact: ansible_connection: "{{ netconf_access[local_side.iptrunk_side_node.vendor].ansible_connection }}" diff --git a/geant/gap_ansible/roles/iptrunk_migration/tasks/compile_template.yaml b/geant/gap_ansible/roles/iptrunk_migration/tasks/compile_template.yaml index 994d83e8b62ecbcb87bbd83436936aadcd9c1bb4..da370805d4f18cdf6f6c4241d59b1a3762bdd53a 100644 --- a/geant/gap_ansible/roles/iptrunk_migration/tasks/compile_template.yaml +++ b/geant/gap_ansible/roles/iptrunk_migration/tasks/compile_template.yaml @@ -20,7 +20,17 @@ mode: '0755' delegate_to: localhost -- name: Print the template in "/var/tmp/ansible_run_{{ opid }}/{{ config_object }}.conf" +- name: Print template for the old node "{{ old_node.fqdn }}" in "/var/tmp/ansible_run_{{ opid }}/{{ config_object }}.conf" + ansible.builtin.template: + src: "{{ old_node.vendor }}/{{ config_object }}.j2" + dest: "/var/tmp/ansible_run_{{ opid }}/{{ config_object }}.conf" + lstrip_blocks: true + trim_blocks: true + mode: '0755' + delegate_to: localhost + when: (verb == "delete" or verb == "deactivate") and inventory_hostname != new_node.router.router_fqdn + +- name: Print template for the new node in "/var/tmp/ansible_run_{{ opid }}/{{ config_object }}.conf" ansible.builtin.template: src: "{{ new_node.router.vendor }}/{{ config_object }}.j2" dest: "/var/tmp/ansible_run_{{ opid }}/{{ config_object }}.conf" @@ -28,6 +38,7 @@ trim_blocks: true mode: '0755' delegate_to: localhost + when: (verb == "deploy") and inventory_hostname == new_node.router.router_fqdn - name: Set netconf connection for trunk nodes ansible.builtin.include_tasks: set_netconf_connection.yaml diff --git a/geant/gap_ansible/roles/iptrunk_migration/tasks/deactivate_trunk_side.yaml b/geant/gap_ansible/roles/iptrunk_migration/tasks/deactivate_trunk_side.yaml index f880605aaba5eb45ca31e659c8e8497ee4599901..afeecf91c17e7ae9abc517847bfea195f10eeba1 100644 --- a/geant/gap_ansible/roles/iptrunk_migration/tasks/deactivate_trunk_side.yaml +++ b/geant/gap_ansible/roles/iptrunk_migration/tasks/deactivate_trunk_side.yaml @@ -1,43 +1,23 @@ --- - name: Deactivate Trunk interface on "{{ inventory_hostname }}" [CHECK ONLY][JUNIPER] - juniper_junos_config: - load: 'replace' + junipernetworks.junos.junos_config: + update: 'replace' src: "/var/tmp/ansible_run_{{ opid }}/{{ config_object }}.conf" - format: set - config_mode: "private" - check: true - commit: false - register: response + src_format: set + check_commit: true + diff: true when: > verb == "deactivate" and local_side.iptrunk_side_node.vendor == "juniper" and dry_run | ansible.builtin.bool -- name: Show DRY diff of "{{ config_object }}" - ansible.builtin.debug: - msg: "{{ response }}" - when: > - verb == "deactivate" - and dry_run | ansible.builtin.bool and - local_side.iptrunk_side_node.vendor == "juniper" - - name: Deactivate Trunk interface on "{{ inventory_hostname }}" [AND COMMIT][JUNIPER] - juniper_junos_config: - load: 'replace' + junipernetworks.junos.junos_config: + update: 'replace' src: "/var/tmp/ansible_run_{{ opid }}/{{ config_object }}.conf" - format: set - config_mode: "private" - commit: true + src_format: set comment: "{{ commit_comment }}" - register: response - when: > - verb == "deactivate" and - local_side.iptrunk_side_node.vendor == "juniper" and - not (dry_run | ansible.builtin.bool) - -- name: Show real diff of "{{ config_object }}" - ansible.builtin.debug: - msg: "{{ response }}" + diff: true when: > verb == "deactivate" and local_side.iptrunk_side_node.vendor == "juniper" and diff --git a/geant/gap_ansible/roles/iptrunk_migration/tasks/delete_trunk_side.yaml b/geant/gap_ansible/roles/iptrunk_migration/tasks/delete_trunk_side.yaml index 9adaafab2d3f0dd5d933b4c999276b2acad883e9..ec7b2da440a2d55afd08349d97831b13ec73b129 100644 --- a/geant/gap_ansible/roles/iptrunk_migration/tasks/delete_trunk_side.yaml +++ b/geant/gap_ansible/roles/iptrunk_migration/tasks/delete_trunk_side.yaml @@ -1,43 +1,23 @@ --- - name: Delete Trunk interface on "{{ inventory_hostname }}" [CHECK ONLY][JUNIPER] - juniper_junos_config: - load: 'replace' + junipernetworks.junos.junos_config: + update: 'replace' src: "/var/tmp/ansible_run_{{ opid }}/{{ config_object }}.conf" - format: set - config_mode: "private" - check: true - commit: false - register: response + src_format: set + check_commit: true + diff: true when: > verb == "delete" and local_side.iptrunk_side_node.vendor == "juniper" and dry_run | ansible.builtin.bool -- name: Show DRY diff of "{{ config_object }}" - ansible.builtin.debug: - msg: "{{ response }}" - when: > - verb == "delete" - and dry_run | ansible.builtin.bool and - local_side.iptrunk_side_node.vendor == "juniper" - - name: Delete Trunk interface on "{{ inventory_hostname }}" [AND COMMIT][JUNIPER] - juniper_junos_config: - load: 'replace' + junipernetworks.junos.junos_config: + update: 'replace' src: "/var/tmp/ansible_run_{{ opid }}/{{ config_object }}.conf" - format: set - config_mode: "private" - commit: true + src_format: set comment: "{{ commit_comment }}" - register: response - when: > - verb == "delete" and - local_side.iptrunk_side_node.vendor == "juniper" and - not (dry_run | ansible.builtin.bool) - -- name: Show real diff of "{{ config_object }}" - ansible.builtin.debug: - msg: "{{ response }}" + diff: true when: > verb == "delete" and local_side.iptrunk_side_node.vendor == "juniper" and diff --git a/geant/gap_ansible/roles/iptrunk_migration/tasks/deploy_object.yaml b/geant/gap_ansible/roles/iptrunk_migration/tasks/deploy_object.yaml index 7b4731a80f5afac1fd77cafd7a8d3a8aea01fc52..24ee4f6da4466f0a71ad93e7ae179b9385426649 100644 --- a/geant/gap_ansible/roles/iptrunk_migration/tasks/deploy_object.yaml +++ b/geant/gap_ansible/roles/iptrunk_migration/tasks/deploy_object.yaml @@ -1,44 +1,50 @@ --- - name: Deploy "{{ config_object }}" on "{{ inventory_hostname }}" [CHECK ONLY][JUNIPER] - juniper_junos_config: - load: 'replace' + junipernetworks.junos.junos_config: + update: 'replace' src: "/var/tmp/ansible_run_{{ opid }}/{{ config_object }}.conf" - format: text - config_mode: "private" - check: true - commit: false - register: response + src_format: set + check_commit: true + diff: true when: > verb == "deploy" and new_node.router.vendor == "juniper" and dry_run | ansible.builtin.bool -- name: Show DRY diff of "{{ config_object }}" - ansible.builtin.debug: - msg: "{{ response }}" - when: > - verb == "deploy" - and dry_run | ansible.builtin.bool and - new_node.router.vendor == "juniper" - - name: Deploy "{{ config_object }}" on "{{ inventory_hostname }}" [AND COMMIT][JUNIPER] - juniper_junos_config: - load: 'replace' + junipernetworks.junos.junos_config: + update: 'replace' src: "/var/tmp/ansible_run_{{ opid }}/{{ config_object }}.conf" - format: text - config_mode: "private" - commit: true + src_format: set comment: "{{ commit_comment }}" - register: response + diff: true when: > verb == "deploy" and new_node.router.vendor == "juniper" and not (dry_run | ansible.builtin.bool) -- name: Show real diff of "{{ config_object }}" - ansible.builtin.debug: - msg: "{{ response }}" +- name: Deploy "{{ config_object }}" on "{{ inventory_hostname }}" [CHECK ONLY][NOKIA] + ansible.netcommon.netconf_config: + format: xml + default_operation: merge + content: "{{ lookup('ansible.builtin.template', '{{ new_node.router.vendor }}/{{ config_object }}.j2') }}" + commit: true + diff: true + check_mode: true when: > verb == "deploy" and - new_node.router.vendor == "juniper" and - not (dry_run | ansible.builtin.bool) + ( dry_run | ansible.builtin.bool ) is true and + new_node.router.vendor == "nokia" + +- name: Deploy base_config on "{{ inventory_hostname }}" [AND COMMIT][NOKIA] + ansible.netcommon.netconf_config: + format: xml + default_operation: merge + content: "{{ lookup('ansible.builtin.template', '{{ new_node.router.vendor }}/{{ config_object }}.j2') }}" + commit: true + diff: true + check_mode: false + when: > + verb == "deploy" and + ( dry_run | ansible.builtin.bool ) is false and + new_node.router.vendor == "nokia" diff --git a/geant/gap_ansible/roles/iptrunk_migration/tasks/main.yml b/geant/gap_ansible/roles/iptrunk_migration/tasks/main.yml index bdcbc44cc108bf4670cabceb464d46e7a7b6d390..2d3c1b95f26803cc5fb4ec5472210978baa451df 100644 --- a/geant/gap_ansible/roles/iptrunk_migration/tasks/main.yml +++ b/geant/gap_ansible/roles/iptrunk_migration/tasks/main.yml @@ -21,17 +21,9 @@ opid: "{{ lookup('community.general.random_string', length=18, special=false) }}" config_is_different: "False" -- name: Lets take a look at trunk - ansible.builtin.debug: - msg: "{{ wfo_trunk }}" - - # - name: Lets take a look at trunk - # ansible.builtin.debug: - # msg: "{{ trunks[0] }}" - - name: The old node is ansible.builtin.debug: - msg: "{{ old_node }}" + msg: "{{ old_node.fqdn }}" - name: The new node is ansible.builtin.debug: @@ -62,26 +54,23 @@ ansible.builtin.debug: msg: "{{ opid }}" -- name: Include compiling the template +- name: Include compiling the template for the old node ansible.builtin.include_tasks: compile_template.yaml - when: verb == "deactivate" and inventory_hostname == old_node - -- name: Include compiling the template - ansible.builtin.include_tasks: compile_template.yaml - when: verb == "delete" and inventory_hostname == old_node + when: (verb == "deactivate" or verb == "delete") + and inventory_hostname == old_node -- name: Include compiling the template - ansible.builtin.include_tasks: compile_template.yaml - when: verb == "deploy" and inventory_hostname == new_node.router.router_fqdn - -- name: Include the modification tasks if specified +- name: Include deactivation tasks for the old node ansible.builtin.include_tasks: deactivate_trunk_side.yaml when: verb == "deactivate" and inventory_hostname == old_node -- name: Include the removal tasks if specified +- name: Include removal tasks for the old node ansible.builtin.include_tasks: delete_trunk_side.yaml when: verb == "delete" and inventory_hostname == old_node +- name: Include compiling the template for the new node + ansible.builtin.include_tasks: compile_template.yaml + when: verb == "deploy" and inventory_hostname == new_node.router.router_fqdn + - name: Include the deployment tasks if specified ansible.builtin.include_tasks: deploy_object.yaml when: verb == "deploy" and inventory_hostname == new_node.router.router_fqdn diff --git a/geant/gap_ansible/roles/iptrunk_migration/templates/juniper/deactivate.j2 b/geant/gap_ansible/roles/iptrunk_migration/templates/juniper/deactivate.j2 index 082ab8754b177765033750fb71dd166548f10947..717995fec98af3351049c4eb1607185bc1955224 100644 --- a/geant/gap_ansible/roles/iptrunk_migration/templates/juniper/deactivate.j2 +++ b/geant/gap_ansible/roles/iptrunk_migration/templates/juniper/deactivate.j2 @@ -1,6 +1,6 @@ deactivate protocols isis interface {{ local_side.iptrunk_side_ae_iface }}.0 deactivate interfaces {{ local_side.iptrunk_side_ae_iface }} {% for iface in local_side.iptrunk_side_ae_members %} -deactivate interfaces {{ iface }} -deactivate protocols lldp interface {{ iface }} +deactivate interfaces {{ iface.interface_name }} +deactivate protocols lldp interface {{ iface.interface_name }} {% endfor %} diff --git a/geant/gap_ansible/roles/iptrunk_migration/templates/nokia/isis_interface.j2 b/geant/gap_ansible/roles/iptrunk_migration/templates/nokia/isis_interface.j2 new file mode 100644 index 0000000000000000000000000000000000000000..fe23b76538642784dd01bca749a84f86587dd868 --- /dev/null +++ b/geant/gap_ansible/roles/iptrunk_migration/templates/nokia/isis_interface.j2 @@ -0,0 +1,20 @@ +<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> + <isis 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"> + <isis-instance>0</isis-instance> + <interface 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" alu:operation="replace"> + <interface-name>{{ new_side.ae_name | lower }}.0</interface-name> + <admin-state>enable</admin-state> + <interface-type>point-to-point</interface-type> + <level-capability>2</level-capability> + <level> + <level-number>2</level-number> + <metric>{{ new_side.isis_metric }}</metric> + </level> + </interface> + </isis> + </router> + </configure> +</config> diff --git a/geant/gap_ansible/roles/iptrunk_migration/templates/nokia/trunk_interface.j2 b/geant/gap_ansible/roles/iptrunk_migration/templates/nokia/trunk_interface.j2 new file mode 100644 index 0000000000000000000000000000000000000000..efbceabe6d027d457530784aa11e683128da40da --- /dev/null +++ b/geant/gap_ansible/roles/iptrunk_migration/templates/nokia/trunk_interface.j2 @@ -0,0 +1,89 @@ +<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"> + +{##} +{% for member in new_side.members %} + <port 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" alu:operation="replace"> + <port-id>{{ member.interface_name }}</port-id> + <admin-state>enable</admin-state> + <description>PHY INFRASTRUCTURE BACKBONE P_{{ new_side.ae_name }} | {{ new_side.description }} | {{ member.interface_description }}</description> + <ethernet> + <mode>network</mode> + <mtu>9212</mtu> + <lldp> + <dest-mac> + <mac-type>nearest-bridge</mac-type> + <receive>true</receive> + <transmit>true</transmit> + <tx-tlvs> + <port-desc>true</port-desc> + <sys-name>true</sys-name> + <sys-cap>true</sys-cap> + </tx-tlvs> + </dest-mac> + </lldp> + </ethernet> + </port> +{% endfor %} + <lag 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" alu:operation="replace"> + <lag-name>{{ new_side.ae_name | lower }}</lag-name> + <admin-state>enable</admin-state> + <description>LAG INFRASTRUCTURE BACKBONE ${{ new_side.port_sid }} | {{ new_side.description }}</description> + <mode>network</mode> + <lacp> + <mode>active</mode> + <administrative-key>{{ (new_side.ae_name|split("-"))[1] }}</administrative-key> + </lacp> +{% for member in new_side.members %} + <port> + <port-id>{{ member.interface_name }}</port-id> + </port> +{% endfor %} + </lag> + <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> + <interface alu:operation="replace"> + <interface-name>{{ new_side.ae_name | lower }}.0</interface-name> + <admin-state>enable</admin-state> + <description>SRV_GLOBAL INFRASTRUCTURE BACKBONE #{{ new_side.description }}-IPTRUNK ${{ new_side.id }}| </description> + <ip-mtu>9000</ip-mtu> + <port>{{ new_side.ae_name | lower }}</port> + <ipv4> + <primary> + <address>{{(new_ipv4_address| split('/'))[0]}}</address> + <prefix-length>{{(new_ipv4_address| split('/'))[1]}}</prefix-length> + </primary> + </ipv4> + <ipv6> + <address> + <ipv6-address>{{(new_ipv6_address| split('/'))[0]}}</ipv6-address> + <prefix-length>{{(new_ipv6_address| split('/'))[1]}}</prefix-length> + </address> + </ipv6> + <qos> + <network-policy>GEANT_BASIC</network-policy> + </qos> + </interface> + {# Add new LAG trunk into standard protocols #} + <mpls 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"> + <interface alu:operation="replace"> + <interface-name>{{ new_side.ae_name | lower }}.0</interface-name> + </interface> + </mpls> + <pim 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"> + <interface alu:operation="replace"> + <interface-name>{{ new_side.ae_name | lower }}.0</interface-name> + </interface> + </pim> + <rsvp 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"> + <interface alu:operation="replace"> + <interface-name>{{ new_side.ae_name | lower }}.0</interface-name> + {# <refresh-reduction> #} + {# <reliable-delivery>true</reliable-delivery> #} + {# </refresh-reduction> #} + </interface> + </rsvp> + </router> + + </configure> +</config> diff --git a/geant/gap_ansible/roles/iptrunk_migration/vars/main.yml b/geant/gap_ansible/roles/iptrunk_migration/vars/main.yml index 2abc10e4d3d284aeac6830cc7cf03cd7ee9c49a2..2fdb32327f536e06cf27e069098ef302c4a20c5a 100644 --- a/geant/gap_ansible/roles/iptrunk_migration/vars/main.yml +++ b/geant/gap_ansible/roles/iptrunk_migration/vars/main.yml @@ -21,7 +21,9 @@ side_a_ipv6_address: "{{ wfo_trunk.iptrunk.iptrunk_ipv6_network | ansible.utils. side_b_ipv4_address: "{{ wfo_trunk.iptrunk.iptrunk_ipv4_network | ansible.utils.ipaddr('net') | ansible.utils.ipaddr('1') | ansible.utils.ipaddr('address') }}/31" side_b_ipv6_address: "{{ wfo_trunk.iptrunk.iptrunk_ipv6_network | ansible.utils.ipaddr('net') | ansible.utils.ipaddr('2') | ansible.utils.ipaddr('address') }}/126" -old_node: "{{ wfo_trunk.iptrunk.iptrunk_sides[replace_index | int].iptrunk_side_node.router_fqdn }}" +old_node: + fqdn: "{{ wfo_trunk.iptrunk.iptrunk_sides[replace_index | int].iptrunk_side_node.router_fqdn }}" + vendor: "{{ wfo_trunk.iptrunk.iptrunk_sides[replace_index | int].iptrunk_side_node.vendor }}" new_side: id: "{{ wfo_trunk.iptrunk.geant_s_sid }}" @@ -35,5 +37,5 @@ new_side: loopback: "{{ wfo_trunk.iptrunk.iptrunk_sides[replace_index | int].iptrunk_side_node.router_lo_ipv4_address }}" ae_name: "{{ new_lag_interface }}" members: "{{ new_lag_member_interfaces }}" - members_descriptions: "{{ wfo_trunk.iptrunk.iptrunk_sides[replace_index | int].iptrunk_side_ae_members_description }}" + # members_descriptions: "{{ wfo_trunk.iptrunk.iptrunk_sides[replace_index | int].iptrunk_side_ae_members_description }}" port_sid: "{{ wfo_trunk.iptrunk.iptrunk_sides[replace_index | int].iptrunk_side_ae_geant_a_sid }}"