diff --git a/roles/dtc/common/tasks/main.yml b/roles/dtc/common/tasks/main.yml index 3c300370..9a26ffdf 100644 --- a/roles/dtc/common/tasks/main.yml +++ b/roles/dtc/common/tasks/main.yml @@ -34,6 +34,13 @@ - name: Build NDFC Fabric Switch Inventory List From Template ansible.builtin.include_tasks: ndfc_inventory.yml +# -------------------------------------------------------------------- +# Build Fabric intra links for vpc peering From Template +# -------------------------------------------------------------------- + +- name: Build intra fabric links From Template + ansible.builtin.include_tasks: ndfc_link_vpc_peering.yml + # -------------------------------------------------------------------- # Build VPC Peering parameter List From Template # -------------------------------------------------------------------- @@ -123,4 +130,4 @@ # -------------------------------------------------------------------- - name: Build Fabric interface All List From Template - ansible.builtin.include_tasks: ndfc_interface_all.yml + ansible.builtin.include_tasks: ndfc_interface_all.yml \ No newline at end of file diff --git a/roles/dtc/common/tasks/ndfc_link_vpc_peering.yml b/roles/dtc/common/tasks/ndfc_link_vpc_peering.yml new file mode 100644 index 00000000..d74bbd5e --- /dev/null +++ b/roles/dtc/common/tasks/ndfc_link_vpc_peering.yml @@ -0,0 +1,18 @@ +--- +- name: Set link_vpc_peering_file_name Var + ansible.builtin.set_fact: + link_vpc_peering_file_name: "{{ MD.fabric.global.name }}_ndfc_link_vpc_peering_.yml" + +- name: Build Links for VPC Peering + ansible.builtin.template: + src: ndfc_links_vpc_peering.j2 + dest: "{{ role_path }}/files/{{ link_vpc_peering_file_name }}" + +- name: Set link_vpc_peering Var default + ansible.builtin.set_fact: + link_vpc_peering: [] + +- name: Set link_vpc_peering Var + ansible.builtin.set_fact: + link_vpc_peering: "{{ lookup('file', link_vpc_peering_file_name) | from_yaml }}" + when: MD_Extended.fabric.topology.vpc_peers | length > 0 diff --git a/roles/dtc/common/tasks/ndfc_vpc_peering.yml b/roles/dtc/common/tasks/ndfc_vpc_peering.yml index ce8b9b40..e79f758a 100644 --- a/roles/dtc/common/tasks/ndfc_vpc_peering.yml +++ b/roles/dtc/common/tasks/ndfc_vpc_peering.yml @@ -1,22 +1,4 @@ --- -- name: Set interface_vpc_peering_file_name Var - ansible.builtin.set_fact: - interface_vpc_peering_file_name: "{{ MD.fabric.global.name }}_ndfc_interface_vpc_peering_.yml" - -- name: Build Interfaces for VPC Peering - ansible.builtin.template: - src: ndfc_interface_vpc_peering.j2 - dest: "{{ role_path }}/files/{{ interface_vpc_peering_file_name }}" - -- name: Set interface_vpc_peering Var default - ansible.builtin.set_fact: - interface_vpc_peering: [] - -- name: Set interface_vpc_peering Var - ansible.builtin.set_fact: - interface_vpc_peering: "{{ lookup('file', interface_vpc_peering_file_name) | from_yaml }}" - when: MD_Extended.fabric.topology.vpc_peers | length > 0 - - name: Set vpc_peering_file_name Var ansible.builtin.set_fact: vpc_peering_file_name: "{{ MD.fabric.global.name }}_ndfc_vpc_peering.yml" @@ -33,4 +15,4 @@ - name: Set vpc_peering Var ansible.builtin.set_fact: vpc_peering: "{{ lookup('file', vpc_peering_file_name) | from_yaml }}" - when: MD_Extended.fabric.topology.vpc_peers | length > 0 + when: MD_Extended.fabric.topology.vpc_peers | length > 0 \ No newline at end of file diff --git a/roles/dtc/common/templates/ndfc_interface_vpc_peering.j2 b/roles/dtc/common/templates/ndfc_interface_vpc_peering.j2 deleted file mode 100644 index 5c17be5d..00000000 --- a/roles/dtc/common/templates/ndfc_interface_vpc_peering.j2 +++ /dev/null @@ -1,38 +0,0 @@ ---- -# This NDFC interface vPC Peering config data structure is auto-generated -# DO NOT EDIT MANUALLY -# -#jinja2: trim_blocks: True, lstrip_blocks: False -{% for peers in MD_Extended.fabric.topology.vpc_peers %} -{% for interface in peers['peer1_peerlink_interfaces'] %} -- name : {{ interface['name'] }} - type: eth - switch: -{% set switch = MD_Extended.fabric.topology.leaf[peers.peer1] %} -{% if switch.management_ipv4_address is defined %} - - {{ switch.management_ipv4_address}} -{% elif (switch.management_ipv4_address is not defined) and (switch.management_ipv6_address is defined) %} - - {{ switch.management_ipv6_address}} -{% endif %} - deploy: false - profile: - admin_state: True - mode: 'trunk' -{% endfor %} -{% for interface in peers['peer2_peerlink_interfaces'] %} -- name : {{ interface['name'] }} - type: eth - switch: -{% set switch = MD_Extended.fabric.topology.leaf[peers.peer2] %} -{% if switch.management_ipv4_address is defined %} - - {{ switch.management_ipv4_address}} -{% elif (switch.management_ipv4_address is not defined) and (switch.management_ipv6_address is defined) %} - - {{ switch.management_ipv6_address}} -{% endif %} - deploy: true - profile: - admin_state: True - mode: 'trunk' - bpdu_guard: false -{% endfor %} -{% endfor %} diff --git a/roles/dtc/common/templates/ndfc_links_vpc_peering.j2 b/roles/dtc/common/templates/ndfc_links_vpc_peering.j2 new file mode 100644 index 00000000..e32059ea --- /dev/null +++ b/roles/dtc/common/templates/ndfc_links_vpc_peering.j2 @@ -0,0 +1,31 @@ +--- +# This NDFC links for vPC Peering is auto-generated +# DO NOT EDIT MANUALLY +# +#jinja2: trim_blocks: True, lstrip_blocks: False +{% for peers in MD_Extended.fabric.topology.vpc_peers %} +{% for interface_index in range(peers['peer1_peerlink_interfaces']|length) %} +{% set peer1_interface = peers['peer1_peerlink_interfaces'][interface_index] %} +{% set peer2_interface = peers['peer2_peerlink_interfaces'][interface_index] %} +{% if peer1_interface is defined and peer2_interface is defined %} +- dst_fabric : {{ MD_Extended.fabric.global.name }} + template: int_pre_provision_intra_fabric_link + src_interface: {{peer1_interface.name}} + dst_interface: {{peer2_interface.name}} + src_device: +{% set switch = MD_Extended.fabric.topology.leaf[peers.peer1] %} +{% if switch.management_ipv4_address is defined %} + {{ switch.management_ipv4_address}} +{% elif (switch.management_ipv4_address is not defined) and (switch.management_ipv6_address is defined) %} + {{ switch.management_ipv6_address}} +{% endif %} + dst_device: +{% set switch = MD_Extended.fabric.topology.leaf[peers.peer2] %} +{% if switch.management_ipv4_address is defined %} + {{ switch.management_ipv4_address}} +{% elif (switch.management_ipv4_address is not defined) and (switch.management_ipv6_address is defined) %} + {{ switch.management_ipv6_address}} +{% endif %} +{% endif %} +{% endfor %} +{% endfor %} diff --git a/roles/dtc/create/tasks/vpc_peering.yml b/roles/dtc/create/tasks/vpc_peering.yml index 08203b20..0508dd31 100644 --- a/roles/dtc/create/tasks/vpc_peering.yml +++ b/roles/dtc/create/tasks/vpc_peering.yml @@ -1,40 +1,21 @@ --- -- name: Query for vPC Peering Interfaces - cisco.dcnm.dcnm_interface: - fabric: "{{ MD.fabric.global.name }}" - state: query - config: "{{ interface_vpc_peering }}" - register: interface_vpc_peering_query - -- name: Get Interfaces Not Associated to vPC Peering Policy - ansible.builtin.set_fact: - interface_not_vpc_policy: "{{ interface_vpc_peering_query.response | community.general.json_query(vpc_peer_policy_query) }}" - vars: - vpc_peer_policy_query: "[?(@.policy!=`int_vpc_peer_link_po_member_11_1`)]" - -- name: Generate Config Payload Update for Interfaces Not Associated to vPC Peering Policy - ansible.builtin.set_fact: - interface_vpc_peering_payload: "{{ lookup('template', 'ndfc_interface_vpc_peer_link.j2') }}" - when: interface_not_vpc_policy | length > 0 +# -------------------------------------------------------------------- +# Manage Intra Fabric Links Configuration on NDFC (prepare links for vpc peering) +# -------------------------------------------------------------------- -- name: Manage Interfaces for vPC Peering - cisco.dcnm.dcnm_interface: - fabric: "{{ MD.fabric.global.name }}" +- name: Manage Intra Fabric Links for vpc peering + cisco.dcnm.dcnm_links: state: replaced - config: "{{ interface_vpc_peering_payload | from_yaml }}" - deploy: true + src_fabric: "{{ MD_Extended.fabric.global.name }}" + config: "{{ link_vpc_peering }}" vars: ansible_command_timeout: 3000 ansible_connect_timeout: 3000 - when: interface_not_vpc_policy | length > 0 -# tune this based on field testing. for now we are leaving at 60 seconds to allow the interfaces to come up. -# we can also look at the interface status and wait for the interfaces to be up before proceeding. -- name: Wait for vPC Peering Interfaces to come up - ansible.builtin.pause: - seconds: 60 - when: interface_not_vpc_policy | length > 0 +# -------------------------------------------------------------------- +# Manage vPC Peering +# -------------------------------------------------------------------- - name: Manage vPC Peering cisco.dcnm.dcnm_vpc_pair: @@ -42,3 +23,48 @@ deploy: false state: replaced config: "{{ vpc_peering }}" + + + +# - name: Query for vPC Peering Interfaces +# cisco.dcnm.dcnm_interface: +# fabric: "{{ MD.fabric.global.name }}" +# state: query +# config: "{{ interface_vpc_peering }}" +# register: interface_vpc_peering_query + +# - name: Get Interfaces Not Associated to vPC Peering Policy +# ansible.builtin.set_fact: +# interface_not_vpc_policy: "{{ interface_vpc_peering_query.response | community.general.json_query(vpc_peer_policy_query) }}" +# vars: +# vpc_peer_policy_query: "[?(@.policy!=`int_vpc_peer_link_po_member_11_1`)]" + +# - name: Generate Config Payload Update for Interfaces Not Associated to vPC Peering Policy +# ansible.builtin.set_fact: +# interface_vpc_peering_payload: "{{ lookup('template', 'ndfc_interface_vpc_peer_link.j2') }}" +# when: interface_not_vpc_policy | length > 0 + +# - name: Manage Interfaces for vPC Peering +# cisco.dcnm.dcnm_interface: +# fabric: "{{ MD.fabric.global.name }}" +# state: replaced +# config: "{{ interface_vpc_peering_payload | from_yaml }}" +# deploy: true +# vars: +# ansible_command_timeout: 3000 +# ansible_connect_timeout: 3000 +# when: interface_not_vpc_policy | length > 0 + +# # tune this based on field testing. for now we are leaving at 60 seconds to allow the interfaces to come up. +# # we can also look at the interface status and wait for the interfaces to be up before proceeding. +# - name: Wait for vPC Peering Interfaces to come up +# ansible.builtin.pause: +# seconds: 60 +# when: interface_not_vpc_policy | length > 0 + +# - name: Manage vPC Peering +# cisco.dcnm.dcnm_vpc_pair: +# src_fabric: "{{ MD.fabric.global.name }}" +# deploy: false +# state: replaced +# config: "{{ vpc_peering }}" diff --git a/roles/dtc/create/templates/ndfc_interface_vpc_peer_link.j2 b/roles/dtc/create/templates/ndfc_interface_vpc_peer_link.j2 deleted file mode 100644 index e9bd4c9f..00000000 --- a/roles/dtc/create/templates/ndfc_interface_vpc_peer_link.j2 +++ /dev/null @@ -1,21 +0,0 @@ -# This NDFC vPC peer-link interface config data structure is auto-generated -# DO NOT EDIT MANUALLY -# - -{% for item in interface_not_vpc_policy %} -{% set switch_serial_number = item.interfaces[0].serialNumber %} -{% set query = "[?(@.serial_number==`" ~ switch_serial_number ~ "`)].management" %} -{% set switch_management = (MD.fabric.topology.switches | community.general.json_query(query))[0] %} -- name: {{ item.interfaces[0].ifName }} - type: eth - switch: -{% if switch_management.management_ipv4_address is defined %} - - {{ switch_management.management_ipv4_address}} -{% elif (switch_management.management_ipv4_address is not defined) and (switch_management.management_ipv6_address is defined) %} - - {{ switch_management.management_ipv6_address}} -{% endif %} - profile: - admin_state: true - mode: trunk - bpdu_guard: false -{% endfor %} diff --git a/roles/dtc/remove/tasks/main.yml b/roles/dtc/remove/tasks/main.yml index 71940bea..2204fc58 100644 --- a/roles/dtc/remove/tasks/main.yml +++ b/roles/dtc/remove/tasks/main.yml @@ -31,6 +31,24 @@ state: overridden config: "{{ vrf_config }}" +- debug: msg="Removing all Unmanaged vPC Peering. This could take several minutes..." +- name: Remove vPC Peering + cisco.dcnm.dcnm_vpc_pair: + src_fabric: "{{ MD.fabric.global.name }}" + deploy: true + state: overridden + config: "{{ vpc_peering }}" + +- debug: msg="Removing all Unmanaged links. This could take several minutes..." +- name: Remove Intra Fabric Links for vpc peering + cisco.dcnm.dcnm_links: + state: replaced + src_fabric: "{{ MD_Extended.fabric.global.name }}" + config: "{{ link_vpc_peering }}" + vars: + ansible_command_timeout: 3000 + ansible_connect_timeout: 3000 + - debug: msg="Removing Unmanaged Fabric Switches. This could take several minutes..." - name: Remove NDFC Fabric Devices {{ MD.fabric.global.name }} cisco.dcnm.dcnm_inventory: @@ -41,12 +59,4 @@ state: overridden vars: ansible_command_timeout: 3000 - ansible_connect_timeout: 3000 - -- debug: msg="Removing all Unmanaged vPC Peering. This could take several minutes..." -- name: Remove vPC Peering - cisco.dcnm.dcnm_vpc_pair: - src_fabric: "{{ MD.fabric.global.name }}" - deploy: false - state: overridden - config: "{{ vpc_peering }}" \ No newline at end of file + ansible_connect_timeout: 3000 \ No newline at end of file