Skip to content

Commit

Permalink
VPC_Peering (#71)
Browse files Browse the repository at this point in the history
* add filter for non-vpc peer interfaces

* Create ndfc_vpc_peering.yml

* Create ndfc_vpc_peering.j2

* Update vpc_peering.yml

* Update ndfc_interface_vpc_peer_link.j2

* Update main.yml

* Update main.yml

* Create ndfc_interface_vpc_peering.j2

* Update vpc_peering.yml

* update vpc files

* Update main.yml

* adjust title heading in ndfc_interface_vpc_peering.j2

* update j2 file descriptions

* set deploy to false for vpc peering interface list build

* limit vpc peering paramters to just what is supported by vxlan fabric

---------

Co-authored-by: Matt Tarkington <[email protected]>
  • Loading branch information
rrahimm and mtarking authored Apr 23, 2024
1 parent d140b2a commit e1ad4e6
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 132 deletions.
21 changes: 14 additions & 7 deletions roles/dtc/common/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,27 @@
path: "{{ role_path }}/files/.gitkeep"
state: touch

# --------------------------------------------------------------------
# Build Create Fabric parameter List From Template
# --------------------------------------------------------------------

- name: Build Fabric Create Parameters
ansible.builtin.include_tasks: ndfc_fabric.yml

# --------------------------------------------------------------------
# Build NDFC Fabric Switch Inventory List From Template
# --------------------------------------------------------------------

- name: Build NDFC Fabric Switch Inventory List From Template
ansible.builtin.include_tasks: ndfc_inventory.yml

# --------------------------------------------------------------------
# Build VPC Peering parameter List From Template
# --------------------------------------------------------------------

- name: Build VPC Peering Parameters
ansible.builtin.include_tasks: ndfc_vpc_peering.yml

# --------------------------------------------------------------------
# Build NDFC Fabric VRFs Attach List From Template
# --------------------------------------------------------------------
Expand Down Expand Up @@ -110,10 +124,3 @@

- name: Build Fabric interface All List From Template
ansible.builtin.include_tasks: ndfc_interface_all.yml

# --------------------------------------------------------------------
# Build Create Fabric parameter List From Template
# --------------------------------------------------------------------

- name: Build Fabric Create Parameters
ansible.builtin.include_tasks: ndfc_fabric.yml
36 changes: 36 additions & 0 deletions roles/dtc/common/tasks/ndfc_vpc_peering.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
- 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"

- name: Build vPC Peering
ansible.builtin.template:
src: ndfc_vpc_peering.j2
dest: "{{ role_path }}/files/{{ vpc_peering_file_name }}"

- name: Set vpc_peering Var default
ansible.builtin.set_fact:
vpc_peering: []

- 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
37 changes: 37 additions & 0 deletions roles/dtc/common/templates/ndfc_interface_vpc_peering.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
# 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'
{% endfor %}
{% endfor %}
19 changes: 19 additions & 0 deletions roles/dtc/common/templates/ndfc_vpc_peering.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
# This NDFC vPC Peering config data structure is auto-generated
# DO NOT EDIT MANUALLY
#

{% if MD.fabric.topology.vpc_peers is defined and MD.fabric.topology.vpc_peers is not none %}
{% for vpc_peer in MD.fabric.topology.vpc_peers %}
{% if MD_Extended.fabric.topology.leaf[vpc_peer.peer1].management_ipv4_address is not none %}
- peerOneId: {{ MD_Extended.fabric.topology.leaf[vpc_peer.peer1].management_ipv4_address }}
{% elif MD_Extended.fabric.topology.leaf[vpc_peer.peer1].management_ipv6_address is not none %}
- peerOneId: {{ MD_Extended.fabric.topology.leaf[vpc_peer.peer1].management_ipv6_address }}
{% endif %}
{% if MD_Extended.fabric.topology.leaf[vpc_peer.peer2].management_ipv4_address is not none %}
peerTwoId: {{ MD_Extended.fabric.topology.leaf[vpc_peer.peer2].management_ipv4_address }}
{% elif MD_Extended.fabric.topology.leaf[vpc_peer.peer2].management_ipv6_address is not none %}
peerTwoId: {{ MD_Extended.fabric.topology.leaf[vpc_peer.peer2].management_ipv6_address }}
{% endif %}
{% endfor %}
{% endif %}
6 changes: 3 additions & 3 deletions roles/dtc/create/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
ansible.builtin.include_tasks: devices.yml
when: MD_Extended.fabric.topology.switches | length > 0

# - name: Manage VPC Peering
# ansible.builtin.include_tasks: vpc.yml
# when: MD.fabric.overlay_services is defined
- name: Manage VPC Peering
ansible.builtin.include_tasks: vpc_peering.yml
when: MD_Extended.fabric.topology.vpc_peers | length > 0

- name: Manage NDFC Fabric Interfaces
ansible.builtin.include_tasks: interfaces.yml
Expand Down
58 changes: 0 additions & 58 deletions roles/dtc/create/tasks/setup_vpc_peer.yml

This file was deleted.

64 changes: 0 additions & 64 deletions roles/dtc/create/tasks/vpc.yml

This file was deleted.

37 changes: 37 additions & 0 deletions roles/dtc/create/tasks/vpc_peering.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---

- 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

- name: Manage vPC Peering
cisco.dcnm.dcnm_vpc_pair:
src_fabric: "{{ MD.fabric.global.name }}"
deploy: false
state: replaced
config: "{{ vpc_peering }}"
20 changes: 20 additions & 0 deletions roles/dtc/create/templates/ndfc_interface_vpc_peer_link.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This NDFC vPC peer-link interface config data structure is auto-generated
# DO NOT EDIT MANUALLY
#

{% for item in interface_not_vpc_peering %}
{% 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
{% endfor %}
8 changes: 8 additions & 0 deletions roles/dtc/remove/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,11 @@
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 }}"

0 comments on commit e1ad4e6

Please sign in to comment.