Skip to content

Commit c758db0

Browse files
ccoueffemtarking
andauthored
add capability to set anycast bgw (#429)
* update msd to assign anycast bgw * update condition to configure anycast * Revert changes * Update sub_main_msd.yml --------- Co-authored-by: Matt Tarkington <mtarking@cisco.com>
1 parent c9de2bc commit c758db0

File tree

4 files changed

+115
-1
lines changed

4 files changed

+115
-1
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Copyright (c) 2025 Cisco Systems, Inc. and its affiliates
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
4+
# this software and associated documentation files (the "Software"), to deal in
5+
# the Software without restriction, including without limitation the rights to
6+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7+
# the Software, and to permit persons to whom the Software is furnished to do so,
8+
# subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included in all
11+
# copies or substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19+
#
20+
# SPDX-License-Identifier: MIT
21+
22+
---
23+
- name: Initialize changes_detected Var
24+
ansible.builtin.set_fact:
25+
changes_detected_anycast_bgw: false
26+
delegate_to: localhost
27+
28+
- name: Set file_name Var
29+
ansible.builtin.set_fact:
30+
file_name: "ndfc_msd_anycast_bgw.yml"
31+
delegate_to: localhost
32+
33+
- name: Stat Previous File If It Exists
34+
ansible.builtin.stat:
35+
path: "{{ path_name }}{{ file_name }}"
36+
register: data_file_previous
37+
delegate_to: localhost
38+
39+
- name: Backup Previous Data File If It Exists
40+
ansible.builtin.copy:
41+
src: "{{ path_name }}{{ file_name }}"
42+
dest: "{{ path_name }}{{ file_name }}.old"
43+
when: data_file_previous.stat.exists
44+
45+
- name: Delete Previous Data File If It Exists
46+
ansible.builtin.file:
47+
state: absent
48+
path: "{{ path_name }}{{ file_name }}"
49+
delegate_to: localhost
50+
when: data_file_previous.stat.exists
51+
52+
- name: Build MSD Anycast BGW IP address allocation From Template
53+
ansible.builtin.template:
54+
src: ndfc_msd_anycast_bgw.j2
55+
dest: "{{ path_name }}{{ file_name }}"
56+
delegate_to: localhost
57+
58+
- name: Create Empty msd_anycast_bgw Var
59+
ansible.builtin.set_fact:
60+
msd_anycast_bgw: []
61+
delegate_to: localhost
62+
63+
- name: Set msd_anycast_bgw Var
64+
ansible.builtin.set_fact:
65+
msd_anycast_bgw: "{{ lookup('file', path_name + file_name) | from_yaml }}"
66+
delegate_to: localhost
67+
68+
- name: Diff Previous and Current Data Files
69+
cisco.nac_dc_vxlan.dtc.diff_model_changes:
70+
file_name_previous: "{{ path_name }}{{ file_name }}.old"
71+
file_name_current: "{{ path_name }}{{ file_name }}"
72+
register: file_diff_result
73+
delegate_to: localhost
74+
75+
- name: Set File Change Flag Based on File Diff Result
76+
ansible.builtin.set_fact:
77+
changes_detected_anycast_bgw: true
78+
delegate_to: localhost
79+
when:
80+
- file_diff_result.file_data_changed
81+
- check_roles['save_previous']

roles/dtc/common/tasks/sub_main_msd.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@
5252
- name: Build NDFC Child Fabric Inventory List From Template
5353
ansible.builtin.import_tasks: msd/ndfc_child_fabrics.yml
5454

55+
# --------------------------------------------------------------------
56+
# Build NDFC Child Fabric Anycast BGW List From Template
57+
# --------------------------------------------------------------------
58+
59+
- name: Build NDFC Child Fabric Anycast BGW List From Template
60+
ansible.builtin.import_tasks: msd/ndfc_anycast_bgw.yml
61+
5562
# --------------------------------------------------------------------
5663
# Build NDFC Fabric VRFs Attach List From Template
5764
# --------------------------------------------------------------------
@@ -73,9 +80,11 @@
7380
ansible.builtin.set_fact:
7481
vars_common_msd:
7582
changes_detected_fabric: "{{ changes_detected_fabric }}"
83+
changes_detected_anycast_bgw: "{{ changes_detected_anycast_bgw }}"
7684
# changes_detected_vrfs: "{{ changes_detected_vrfs }}"
7785
# changes_detected_networks: "{{ changes_detected_networks }}"
7886
fabric_config: "{{ fabric_config }}"
87+
msd_anycast_bgw: "{{ msd_anycast_bgw }}"
7988
# vrf_config: "{{ vrf_config }}"
8089
# net_config: "{{ net_config }}"
8190
# Check with Matt and Pete on how to handle this for MSD
@@ -86,6 +95,7 @@
8695
msg:
8796
- "----------------------------------------------------------------"
8897
- "+ Fabric Changes Detected - [ {{ vars_common_msd.changes_detected_fabric }} ]"
98+
- "+ Anycast Gateway Changes Detected - [ {{ vars_common_msd.changes_detected_anycast_bgw }} ]"
8999
# - "+ VRFs Changes Detected - [ {{ vars_common_msd.changes_detected_vrfs }} ]"
90100
# - "+ Networks Changes Detected - [ {{ vars_common_msd.changes_detected_networks }} ]"
91101
- "+ ----- Run Map -----"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This NDFC anycast gateway structure is auto-generated
2+
# DO NOT EDIT MANUALLY
3+
#
4+
5+
{% set anycast_lo_id = vxlan.multisite.vtep_loopback_id | default(defaults.vxlan.multisite.vtep_loopback_id) %}
6+
7+
{% for fabric in vxlan.multisite.child_fabrics %}
8+
{% if fabric.anycast_bgw_ipv4 is defined %}
9+
- entity_name: "{{ fabric.name }}"
10+
pool_type: IP
11+
pool_name: "LOOPBACK{{ anycast_lo_id }}_IP_POOL"
12+
scope_type: fabric
13+
resource: "{{ fabric.anycast_bgw_ipv4 }}"
14+
{% endif %}
15+
{% endfor %}

roles/dtc/create/tasks/sub_main_msd.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,17 @@
5252
register: MD_Multisite
5353
tags: "{{ nac_tags.create_vrfs_networks }}"
5454

55+
- name: Create Anycast Loopback Border Gateway site in NDFC
56+
cisco.dcnm.dcnm_resource_manager:
57+
state: merged
58+
fabric: "{{ MD_Extended.vxlan.fabric.name }}"
59+
config: "{{ vars_common_msd.msd_anycast_bgw }}"
60+
when:
61+
- vars_common_msd.msd_anycast_bgw | length > 0
62+
5563
- name: Manage NDFC MSD Fabric VRFs and Networks
5664
ansible.builtin.import_tasks: msd/vrfs_networks.yml
57-
when:
65+
when:
5866
- MD_Extended.vxlan.multisite.overlay is defined
5967
- MD_Extended.vxlan.multisite.overlay
6068
# - (vars_common_msd.changes_detected_vrfs or vars_common_msd.changes_detected_networks)

0 commit comments

Comments
 (0)