diff --git a/README.md b/README.md index 1418e98..a214f77 100644 --- a/README.md +++ b/README.md @@ -11,16 +11,16 @@ Two identical child fabrics and a multisite domain (MSD) fabric are defined in t The main playbooks, which create the two fabrics and the MSD fabric are located in the top-level directory: ```bash -example_ndfc_rest_fabric_create_f1.yml -example_ndfc_rest_fabric_create_f2.yml -example_ndfc_rest_fabric_create_msd_with_children.yml +example_ndfc_rest_fabric_switch_create_f1.yml +example_ndfc_rest_fabric_switch_create_f2.yml +example_ndfc_rest_fabric_msd_create_with_children.yml ``` Ref | Playbook | Description --- | -------- | ----------- -1 | ``example_ndfc_rest_fabric_create_f1.yml`` | creates VXLAN/EVPN fabric f1 without connectivity to an MSD fabric -2 | ``example_ndfc_rest_fabric_create_f2.yml`` | creates VXLAN/EVPN fabric f2 without connectivity to an MSD fabric -3 | ``example_ndfc_rest_fabric_create_msd_with_children.yml`` | creates VXLAN/EVPN fabrics f1 and f2, connecting them through an MSD fabric +1 | ``example_ndfc_rest_fabric_switch_create_f1.yml`` | creates VXLAN/EVPN fabric f1 without connectivity to an MSD fabric +2 | ``example_ndfc_rest_fabric_switch_create_f2.yml`` | creates VXLAN/EVPN fabric f2 without connectivity to an MSD fabric +3 | ``example_ndfc_rest_fabric_msd_create_with_children.yml`` | creates VXLAN/EVPN fabrics f1 and f2, connecting them through an MSD fabric Hence, you should use either (1 and 2) OR 3 (which creates 1 and 2, but with MSD connectivity). That is, (1 and 2) are mutually exclusive to 3. @@ -29,7 +29,7 @@ These playbooks leverage the following included Roles: ```bash ndfc_rest_config_deploy_all ndfc_device_merged -ndfc_rest_fabric_create +ndfc_rest_fabric_switch_create ndfc_network_replaced_all ndfc_policy_vrf_rt_import_loop ndfc_rest_vpc_create @@ -200,7 +200,7 @@ ndfc: ```bash cd /top/level/directory/for/this/repo -ansible-playbook example_ndfc_rest_fabric_create_f1.yml --ask-vault-pass -i inventory +ansible-playbook example_ndfc_rest_fabric_switch_create_f1.yml --ask-vault-pass -i inventory ``` When prompted, enter the password you used in response to the ansible-vault command in step 1 above. @@ -209,7 +209,7 @@ When prompted, enter the password you used in response to the ansible-vault comm ```bash cd /top/level/directory/for/this/repo -ansible-playbook example_ndfc_rest_fabric_create_f1.yml -i inventory +ansible-playbook example_ndfc_rest_fabric_switch_create_f1.yml -i inventory ``` ## Roles @@ -253,7 +253,7 @@ Role | Description [ndfc_rest_fabric_access_mode_get] | Retrieve a fabric's access mode, given ``fabric_name`` [ndfc_rest_fabric_access_mode_set] | Set a fabric's access mode, given ``fabric_name``, and ``read_only`` [ndfc_rest_fabric_asn_get] | Retrieve a fabric's BGP ASN, given ``fabric_name`` -[ndfc_rest_fabric_create] | Create a fabric, given ``fabric_name`` +[ndfc_rest_fabric_switch_create] | Create a switch fabric, given ``fabric_name`` [ndfc_rest_fabric_delete] | Delete a fabric, given ``fabric_name`` [ndfc_rest_fabric_external_create] | Create an external fabric, given ``fabric_name`` [ndfc_rest_fabric_msd_child_add] | Add a child fabric to an MSD fabric, given ``child_fabric``, and ``msd_fabric`` @@ -305,7 +305,7 @@ Role | Description [ndfc_rest_fabric_access_mode_get]: https://github.com/allenrobel/ndfc-roles/tree/master/roles/ndfc_rest_fabric_access_mode_get [ndfc_rest_fabric_access_mode_set]: https://github.com/allenrobel/ndfc-roles/tree/master/roles/ndfc_rest_fabric_access_mode_set [ndfc_rest_fabric_asn_get]: https://github.com/allenrobel/ndfc-roles/tree/master/roles/ndfc_rest_fabric_asn_get -[ndfc_rest_fabric_create]: https://github.com/allenrobel/ndfc-roles/tree/master/roles/ndfc_rest_fabric_create +[ndfc_rest_fabric_switch_create]: https://github.com/allenrobel/ndfc-roles/tree/master/roles/ndfc_rest_fabric_switch_create [ndfc_rest_fabric_delete]: https://github.com/allenrobel/ndfc-roles/tree/master/roles/ndfc_rest_fabric_delete [ndfc_rest_fabric_external_create]: https://github.com/allenrobel/ndfc-roles/tree/master/roles/ndfc_rest_fabric_external_create [ndfc_rest_fabric_msd_child_add]: https://github.com/allenrobel/ndfc-roles/tree/master/roles/ndfc_rest_fabric_msd_child_add diff --git a/example_ndfc_device_config_get.yml b/example_ndfc_device_config_get.yml new file mode 100644 index 0000000..d87f771 --- /dev/null +++ b/example_ndfc_device_config_get.yml @@ -0,0 +1,13 @@ +# example_ndfc_device_config_get.yml +# Query local vars for device configuration +--- +- hosts: ndfc + gather_facts: false + roles: + - ndfc_device_config_get + vars: + device_name: leaf_1 + tasks: + - block: + - debug: + msg: "device_config: {{ device_config }}" diff --git a/example_ndfc_device_generated_configs_get.yml b/example_ndfc_device_generated_configs_get.yml new file mode 100644 index 0000000..d352f84 --- /dev/null +++ b/example_ndfc_device_generated_configs_get.yml @@ -0,0 +1,14 @@ +# example_ndfc_device_generated_configs_get.yml +--- +- hosts: ndfc + gather_facts: false + roles: + - ndfc_device_generated_configs_get + vars: + fabric_name: f1 + device_name: leaf_1 + tasks: + - block: + - debug: + var: device_generated_configs + when: "device_generated_configs != ''" diff --git a/example_ndfc_device_ipv4_address_local_get.yml b/example_ndfc_device_ipv4_address_local_get.yml new file mode 100644 index 0000000..a1d6a92 --- /dev/null +++ b/example_ndfc_device_ipv4_address_local_get.yml @@ -0,0 +1,16 @@ +# example_ndfc_device_ipv4_address_local_get.yml +# Query device entry in ndfc_common with fabric_name and device_name +# and print the switch's ipv4 address based on the vars config in ndfc_common +--- +- hosts: ndfc + gather_facts: false + roles: + - ndfc_device_ipv4_address_local_get + vars: + fabric_name: f2 + device_name: leaf_1 + tasks: + - block: + - debug: + msg: "device_ipv4_address: {{ device_ipv4_address }}" + when: "device_ipv4_address != ''" diff --git a/example_ndfc_device_ipv4_address_remote_get.yml b/example_ndfc_device_ipv4_address_remote_get.yml new file mode 100644 index 0000000..38c1d79 --- /dev/null +++ b/example_ndfc_device_ipv4_address_remote_get.yml @@ -0,0 +1,16 @@ +# example_ndfc_device_ipv4_address_remote_get.yml +# Query NX-OS switch associated with fabric_name and device_name +# and print the switch's ipv4 address based on remote device's configuration +--- +- hosts: ndfc + gather_facts: false + roles: + - ndfc_device_ipv4_address_remote_get + vars: + fabric_name: f2 + device_name: leaf_1 + tasks: + - block: + - debug: + msg: "device_ipv4_address: {{ device_ipv4_address }}" + when: "device_ipv4_address != ''" diff --git a/example_ndfc_device_merged.yml b/example_ndfc_device_merged.yml index f084f2c..64366d2 100644 --- a/example_ndfc_device_merged.yml +++ b/example_ndfc_device_merged.yml @@ -7,5 +7,3 @@ vars: fabric_name: f1 device_name: spine_1 - # Default is true. See README for ndfc_device_merged Role - config_deploy_for_existing_device: true diff --git a/example_ndfc_device_serial_number_get.yml b/example_ndfc_device_serial_number_get.yml index 9d3d22e..3021c3c 100644 --- a/example_ndfc_device_serial_number_get.yml +++ b/example_ndfc_device_serial_number_get.yml @@ -7,8 +7,7 @@ roles: - ndfc_device_serial_number_get vars: - fabric_name: f2 - device_name: leaf_1 + device_name: leaf_5 tasks: - block: - debug: diff --git a/example_ndfc_fabric_config_get.yml b/example_ndfc_fabric_config_get.yml new file mode 100644 index 0000000..1ef0415 --- /dev/null +++ b/example_ndfc_fabric_config_get.yml @@ -0,0 +1,13 @@ +# example_ndfc_fabric_config_get.yml +# Query local vars for fabric configuration +--- +- hosts: ndfc + gather_facts: false + roles: + - ndfc_fabric_config_get + vars: + fabric_name: f1 + tasks: + - block: + - debug: + msg: "fabric_config: {{ fabric_config }}" diff --git a/example_ndfc_network_config_get.yml b/example_ndfc_network_config_get.yml new file mode 100644 index 0000000..b01416d --- /dev/null +++ b/example_ndfc_network_config_get.yml @@ -0,0 +1,13 @@ +# example_ndfc_network_config_get.yml +# Retrieve configuration of network_name from vars defined in ndfc_common +--- +- hosts: ndfc + gather_facts: false + roles: + - ndfc_network_config_get + vars: + network_name: f1_n1111 + tasks: + - block: + - debug: + msg: "network_config: {{ network_config }}" diff --git a/example_ndfc_network_deleted.yml b/example_ndfc_network_deleted.yml index 7cace89..db95020 100644 --- a/example_ndfc_network_deleted.yml +++ b/example_ndfc_network_deleted.yml @@ -8,5 +8,4 @@ roles: - ndfc_network_deleted vars: - fabric_name: MSD - network_name: n1111 + network_name: msd_n1111 diff --git a/example_ndfc_network_deleted_all.yml b/example_ndfc_network_deleted_all.yml deleted file mode 100644 index 2e65aa3..0000000 --- a/example_ndfc_network_deleted_all.yml +++ /dev/null @@ -1,11 +0,0 @@ -# example_ndfc_network_deleted_all.yml -# NOTE: If the networks to be deleted are within -# child fabric(s) of an msd_fabric, fabric_name -# must be that of the msd_fabric ---- -- hosts: ndfc - gather_facts: false - roles: - - ndfc_network_deleted_all - vars: - fabric_name: MSD diff --git a/example_ndfc_network_deleted_external_fabric_all.yml b/example_ndfc_network_deleted_external_fabric_all.yml new file mode 100644 index 0000000..6ebe7eb --- /dev/null +++ b/example_ndfc_network_deleted_external_fabric_all.yml @@ -0,0 +1,8 @@ +# example_ndfc_network_deleted_external_fabric_all.yml +--- +- hosts: ndfc + gather_facts: false + roles: + - ndfc_network_deleted_external_fabric_all + vars: + fabric_name: external diff --git a/example_ndfc_network_deleted_msd_fabric_all.yml b/example_ndfc_network_deleted_msd_fabric_all.yml new file mode 100644 index 0000000..c324c5d --- /dev/null +++ b/example_ndfc_network_deleted_msd_fabric_all.yml @@ -0,0 +1,8 @@ +# example_ndfc_network_deleted_msd_fabric_all.yml +--- +- hosts: ndfc + gather_facts: false + roles: + - ndfc_network_deleted_msd_fabric_all + vars: + fabric_name: MSD diff --git a/example_ndfc_network_deleted_switch_fabric_all.yml b/example_ndfc_network_deleted_switch_fabric_all.yml new file mode 100644 index 0000000..d6e21b5 --- /dev/null +++ b/example_ndfc_network_deleted_switch_fabric_all.yml @@ -0,0 +1,8 @@ +# example_ndfc_network_deleted_switch_fabric_all.yml +--- +- hosts: ndfc + gather_facts: false + roles: + - ndfc_network_deleted_switch_fabric_all + vars: + fabric_name: f1 diff --git a/example_ndfc_network_replaced.yml b/example_ndfc_network_replaced.yml new file mode 100644 index 0000000..9006d1e --- /dev/null +++ b/example_ndfc_network_replaced.yml @@ -0,0 +1,7 @@ +--- +- hosts: ndfc + gather_facts: false + roles: + - ndfc_network_replaced + vars: + network_name: f1_n1111 diff --git a/example_ndfc_network_replaced_all.yml b/example_ndfc_network_replaced_all.yml index 547b963..ed5cac0 100644 --- a/example_ndfc_network_replaced_all.yml +++ b/example_ndfc_network_replaced_all.yml @@ -5,4 +5,4 @@ roles: - ndfc_network_replaced_all vars: - fabric_name: f1 + fabric_name: MSD diff --git a/example_ndfc_policy_vrf_rt_import_evpn_loop.yml b/example_ndfc_policy_vrf_rt_import_evpn_loop.yml index 007f111..9c88a39 100644 --- a/example_ndfc_policy_vrf_rt_import_evpn_loop.yml +++ b/example_ndfc_policy_vrf_rt_import_evpn_loop.yml @@ -8,11 +8,10 @@ - ndfc_policy_vrf_rt_import_evpn_loop vars: fabric_name: f1 - device_name: leaf_1 vrf_name: v1 import_vrf_name: v2 state: merged - devices: + device_list: - leaf_1 - leaf_2 - leaf_3 diff --git a/example_ndfc_rest_device_set_role.yml b/example_ndfc_rest_device_set_role.yml index 4aa2078..7de234c 100644 --- a/example_ndfc_rest_device_set_role.yml +++ b/example_ndfc_rest_device_set_role.yml @@ -5,6 +5,5 @@ roles: - ndfc_rest_device_set_role vars: - fabric_name: f1 device_name: leaf_1 role: leaf diff --git a/example_ndfc_rest_fabric_access_mode_get.yml b/example_ndfc_rest_fabric_access_mode_get.yml index 6b793b6..2fc5f13 100644 --- a/example_ndfc_rest_fabric_access_mode_get.yml +++ b/example_ndfc_rest_fabric_access_mode_get.yml @@ -10,3 +10,7 @@ - ndfc_rest_fabric_access_mode_get vars: fabric_name: f1 + tasks: + - block: + - debug: + msg: "fabric {{ fabric_name }} read_only: {{ read_only }}" diff --git a/example_ndfc_rest_fabric_active_fabrics_get.yml b/example_ndfc_rest_fabric_active_fabrics_get.yml new file mode 100644 index 0000000..0d9a1d1 --- /dev/null +++ b/example_ndfc_rest_fabric_active_fabrics_get.yml @@ -0,0 +1,13 @@ +# example_ndfc_device_serial_number_get.yml +# Query NX-OS switch associated with fabric_name and device_name +# and print the switch's serial number +--- +- hosts: ndfc + gather_facts: false + roles: + - ndfc_rest_fabric_active_fabrics_get + tasks: + - block: + - debug: + msg: "active_fabrics: {{ active_fabrics }}" + when: "active_fabrics != ''" diff --git a/example_ndfc_rest_fabric_create.yml b/example_ndfc_rest_fabric_create.yml deleted file mode 100644 index 57367d9..0000000 --- a/example_ndfc_rest_fabric_create.yml +++ /dev/null @@ -1,8 +0,0 @@ -# example_ndfc_rest_fabric_create.yml ---- -- hosts: ndfc - gather_facts: false - roles: - - ndfc_rest_fabric_create - vars: - fabric_name: f1 diff --git a/example_ndfc_rest_fabric_delete.yml b/example_ndfc_rest_fabric_delete.yml index 9c95ae7..db9fdb7 100644 --- a/example_ndfc_rest_fabric_delete.yml +++ b/example_ndfc_rest_fabric_delete.yml @@ -5,4 +5,4 @@ roles: - ndfc_rest_fabric_delete vars: - fabric_name: f1 + fabric_name: f3 diff --git a/example_ndfc_rest_fabric_external_create.yml b/example_ndfc_rest_fabric_external_create.yml index 68e8ee7..afc52b0 100644 --- a/example_ndfc_rest_fabric_external_create.yml +++ b/example_ndfc_rest_fabric_external_create.yml @@ -5,4 +5,4 @@ roles: - ndfc_rest_fabric_external_create vars: - fabric_name: sn_fabric_1 + fabric_name: ext_fabric_test diff --git a/example_ndfc_rest_fabric_create_msd_with_children.yml b/example_ndfc_rest_fabric_msd_create_with_children.yml similarity index 98% rename from example_ndfc_rest_fabric_create_msd_with_children.yml rename to example_ndfc_rest_fabric_msd_create_with_children.yml index 04877f8..af90b73 100644 --- a/example_ndfc_rest_fabric_create_msd_with_children.yml +++ b/example_ndfc_rest_fabric_msd_create_with_children.yml @@ -1,10 +1,10 @@ -# example_ndfc_rest_fabric_create_msd_with_children.yml +# example_ndfc_rest_fabric_msd_create_with_children.yml --- # Fabric f1 and devices - hosts: ndfc gather_facts: false roles: - - ndfc_rest_fabric_create + - ndfc_rest_fabric_switch_create vars: fabric_name: f1 @@ -144,7 +144,7 @@ - hosts: ndfc gather_facts: false roles: - - ndfc_rest_fabric_create + - ndfc_rest_fabric_switch_create vars: fabric_name: f2 diff --git a/example_ndfc_rest_fabric_switch_create.yml b/example_ndfc_rest_fabric_switch_create.yml new file mode 100644 index 0000000..da218c6 --- /dev/null +++ b/example_ndfc_rest_fabric_switch_create.yml @@ -0,0 +1,8 @@ +# example_ndfc_rest_fabric_switch_create.yml +--- +- hosts: ndfc + gather_facts: false + roles: + - ndfc_rest_fabric_switch_create + vars: + fabric_name: f1 diff --git a/example_ndfc_rest_fabric_create_f1.yml b/example_ndfc_rest_fabric_switch_create_f1.yml similarity index 97% rename from example_ndfc_rest_fabric_create_f1.yml rename to example_ndfc_rest_fabric_switch_create_f1.yml index 27fde3f..22d3db6 100644 --- a/example_ndfc_rest_fabric_create_f1.yml +++ b/example_ndfc_rest_fabric_switch_create_f1.yml @@ -1,11 +1,11 @@ -# example_ndfc_rest_fabric_create_f1.yml +# example_ndfc_rest_fabric_switch_create_f1.yml # This creates a standalone fabric (i.e. not MSD child). As such, it provisions only the leaf and spine layers (does not provision border-gateways) --- # Fabric and devices - hosts: ndfc gather_facts: false roles: - - ndfc_rest_fabric_create + - ndfc_rest_fabric_switch_create vars: fabric_name: f1 diff --git a/example_ndfc_rest_fabric_create_f2.yml b/example_ndfc_rest_fabric_switch_create_f2.yml similarity index 97% rename from example_ndfc_rest_fabric_create_f2.yml rename to example_ndfc_rest_fabric_switch_create_f2.yml index d915e19..cea96bc 100644 --- a/example_ndfc_rest_fabric_create_f2.yml +++ b/example_ndfc_rest_fabric_switch_create_f2.yml @@ -1,11 +1,11 @@ -# example_ndfc_rest_fabric_create_f2.yml +# example_ndfc_rest_fabric_switch_create_f2.yml # This creates a standalone fabric (i.e. not MSD child). As such, it provisions only the leaf and spine layers (does not provision border-gateways) --- # Fabric and devices - hosts: ndfc gather_facts: false roles: - - ndfc_rest_fabric_create + - ndfc_rest_fabric_switch_create vars: fabric_name: f2 diff --git a/example_ndfc_rest_interface_no_shutdown.yml b/example_ndfc_rest_interface_no_shutdown.yml index 630a493..0cc7fc7 100644 --- a/example_ndfc_rest_interface_no_shutdown.yml +++ b/example_ndfc_rest_interface_no_shutdown.yml @@ -5,6 +5,5 @@ roles: - ndfc_rest_interface_no_shutdown vars: - - fabric_name: f1 - device_name: leaf_1 - interface_name: Ethernet1/49 + device_name: spine_1 + interface_name: Ethernet1/32 diff --git a/example_ndfc_vpc_interface_merged_all.yml b/example_ndfc_vpc_interface_merged_all.yml index e34092d..1f60a77 100644 --- a/example_ndfc_vpc_interface_merged_all.yml +++ b/example_ndfc_vpc_interface_merged_all.yml @@ -5,5 +5,4 @@ roles: - ndfc_vpc_interface_merged_all vars: - fabric_name: f1 vpc_name: vpc1 diff --git a/example_ndfc_vrf_config_get.yml b/example_ndfc_vrf_config_get.yml new file mode 100644 index 0000000..ba81241 --- /dev/null +++ b/example_ndfc_vrf_config_get.yml @@ -0,0 +1,13 @@ +# example_ndfc_vrf_config_get.yml +# Query local vars for vrf configuration +--- +- hosts: ndfc + gather_facts: false + roles: + - ndfc_vrf_config_get + vars: + vrf_name: msd_v1 + tasks: + - block: + - debug: + msg: "vrf_config: {{ vrf_config }}" diff --git a/example_ndfc_vrf_query.yml b/example_ndfc_vrf_query.yml index 08ef66d..1c8607e 100644 --- a/example_ndfc_vrf_query.yml +++ b/example_ndfc_vrf_query.yml @@ -5,12 +5,11 @@ roles: - ndfc_vrf_query vars: - fabric_name: f1 - vrf_name: v1 + vrf_name: msd_v1 tasks: - debug: - msg: "info.parent.fabric: {{ info.parent.fabric }}" + msg: "vrf_info.parent.fabric: {{ vrf_info.parent.fabric }}" - debug: - msg: "info.parent.vrfId: {{ info.parent.vrfId }}" + msg: "vrf_info.parent.vrfId: {{ vrf_info.parent.vrfId }}" - debug: - msg: "info.parent.vrfStatus: {{ info.parent.vrfStatus }}" + msg: "vrf_info.parent.vrfStatus: {{ vrf_info.parent.vrfStatus }}" diff --git a/example_ndfc_vrf_replaced.yml b/example_ndfc_vrf_replaced.yml index cc07315..704c9ac 100644 --- a/example_ndfc_vrf_replaced.yml +++ b/example_ndfc_vrf_replaced.yml @@ -5,5 +5,4 @@ roles: - ndfc_vrf_replaced vars: - fabric_name: f1 - vrf_name: v2 + vrf_name: f2_v2 diff --git a/roles/ndfc_common/vars/main.yml b/roles/ndfc_common/vars/main.yml index a9b8084..3b52a2a 100644 --- a/roles/ndfc_common/vars/main.yml +++ b/roles/ndfc_common/vars/main.yml @@ -1,22 +1,37 @@ --- # ndfc_common/vars/main.yml -# Multi-Site Domain Fabric parameters +# Multi-Site Domain (MSD) Fabric parameters msd_fabrics: -- name: MSD - L2_SEGMENT_ID_RANGE: 30000-49000 - L3_PARTITION_ID_RANGE: 50000-59000 - ANYCAST_GW_MAC: 2020.0000.00aa - MS_LOOPBACK_ID: 100 - BORDER_GWY_CONNECTIONS: Direct_To_BGWS - MS_UNDERLAY_AUTOCONFIG: true - DELAY_RESTORE: 300 - LOOPBACK100_IP_RANGE: 10.100.0.0/24 - DCI_SUBNET_RANGE: 10.100.1.0/24 - DCI_SUBNET_TARGET_MASK: 30 - -# Site Fabric parameters + MSD: + name: MSD + type: msd + L2_SEGMENT_ID_RANGE: 30000-49000 + L3_PARTITION_ID_RANGE: 50000-59000 + ANYCAST_GW_MAC: 2020.0000.00aa + MS_LOOPBACK_ID: 100 + BORDER_GWY_CONNECTIONS: Direct_To_BGWS + MS_UNDERLAY_AUTOCONFIG: true + DELAY_RESTORE: 300 + LOOPBACK100_IP_RANGE: 10.100.0.0/24 + DCI_SUBNET_RANGE: 10.100.1.0/24 + DCI_SUBNET_TARGET_MASK: 30 + msd_test_1: + name: msd_test_1 + type: msd + L2_SEGMENT_ID_RANGE: 30000-49000 + L3_PARTITION_ID_RANGE: 50000-59000 + ANYCAST_GW_MAC: 2020.0000.00aa + MS_LOOPBACK_ID: 100 + BORDER_GWY_CONNECTIONS: Direct_To_BGWS + MS_UNDERLAY_AUTOCONFIG: true + DELAY_RESTORE: 300 + LOOPBACK100_IP_RANGE: 10.100.0.0/24 + DCI_SUBNET_RANGE: 10.100.1.0/24 + DCI_SUBNET_TARGET_MASK: 30 + +# Switch Fabric parameters # Multicast replication mode requires the following: # # ANYCAST_RP_IP_RANGE: 10.254.1.0/24 @@ -29,197 +44,179 @@ msd_fabrics: # # ANYCAST_RP_IP_RANGE: COMMENTED OR REMOVED # REPLICATION_MODE: Ingress -fabrics: -- name: f1 - BGP_AS: 65001 - #ANYCAST_RP_IP_RANGE: 10.254.1.0/24 - LOOPBACK0_IP_RANGE: 10.2.0.0/22 - LOOPBACK1_IP_RANGE: 10.3.0.0/22 - SUBNET_RANGE: 10.4.0.0/16 - FABRIC_MTU: 9216 - REPLICATION_MODE: Ingress -- name: f2 - BGP_AS: 65002 - #ANYCAST_RP_IP_RANGE: 10.254.2.0/24 - LOOPBACK0_IP_RANGE: 10.6.0.0/22 - LOOPBACK1_IP_RANGE: 10.7.0.0/22 - SUBNET_RANGE: 10.8.0.0/16 - FABRIC_MTU: 9216 - REPLICATION_MODE: Ingress +switch_fabrics: + f1: + name: f1 + type: switch + BGP_AS: 65001 + #ANYCAST_RP_IP_RANGE: 10.254.1.0/24 + LOOPBACK0_IP_RANGE: 10.2.0.0/22 + LOOPBACK1_IP_RANGE: 10.3.0.0/22 + SUBNET_RANGE: 10.4.0.0/16 + FABRIC_MTU: 9216 + REPLICATION_MODE: Ingress + f2: + name: f2 + type: switch + BGP_AS: 65002 + #ANYCAST_RP_IP_RANGE: 10.254.1.0/24 + LOOPBACK0_IP_RANGE: 10.6.0.0/22 + LOOPBACK1_IP_RANGE: 10.7.0.0/22 + SUBNET_RANGE: 10.8.0.0/16 + FABRIC_MTU: 9216 + REPLICATION_MODE: Ingress + + f3: + name: f3 + type: switch + BGP_AS: 65003 + #ANYCAST_RP_IP_RANGE: 10.254.1.0/24 + LOOPBACK0_IP_RANGE: 10.36.0.0/22 + LOOPBACK1_IP_RANGE: 10.37.0.0/22 + SUBNET_RANGE: 10.38.0.0/16 + FABRIC_MTU: 9216 + REPLICATION_MODE: Ingress # External fabric parameters external_fabrics: -- name: sn_fabric_1 - BGP_AS: 65201 - DCI_SUBNET_RANGE: 10.101.1.0/24 - DCI_SUBNET_TARGET_MASK: 30 - LOOPBACK0_IP_RANGE: 10.201.0.0/22 - POWER_REDUNDANCY_MODE: ps-redundant - SUBINTERFACE_RANGE: 2-511 -- name: sn_fabric_2 - BGP_AS: 65202 - DCI_SUBNET_RANGE: 10.102.1.0/24 - DCI_SUBNET_TARGET_MASK: 30 - LOOPBACK0_IP_RANGE: 10.202.0.0/22 - POWER_REDUNDANCY_MODE: ps-redundant - SUBINTERFACE_RANGE: 2-511 -- name: sn_fabric_3 - BGP_AS: 65203 - DCI_SUBNET_RANGE: 10.103.1.0/24 - DCI_SUBNET_TARGET_MASK: 30 - LOOPBACK0_IP_RANGE: 10.203.0.0/22 - POWER_REDUNDANCY_MODE: ps-redundant - SUBINTERFACE_RANGE: 2-511 - -leafs: - # site_fabric f1 -- fabric: "{{ fabrics[0].name }}" - name: leaf_1 - ip: 172.22.150.102 - role: leaf -- fabric: "{{ fabrics[0].name }}" - name: leaf_2 - ip: 172.22.150.103 - role: leaf -- fabric: "{{ fabrics[0].name }}" - name: leaf_3 - ip: 172.22.150.104 - role: leaf -- fabric: "{{ fabrics[0].name }}" - name: leaf_4 - ip: 172.22.150.105 - role: leaf - # site_fabric f2 -- fabric: "{{ fabrics[1].name }}" - name: leaf_1 - ip: 172.22.150.106 - role: leaf -- fabric: "{{ fabrics[1].name }}" - name: leaf_2 - ip: 172.22.150.107 - role: leaf -- fabric: "{{ fabrics[1].name }}" - name: leaf_3 - ip: 172.22.150.108 - role: leaf -- fabric: "{{ fabrics[1].name }}" - name: leaf_4 - ip: 172.22.150.109 - role: leaf - -# Leafs need unique names across a MSD fabric. -# Below are duplicates of leafs above but for msd_fabrics - -- fabric: "{{ msd_fabrics[0].name }}" - name: leaf_1 - ip: 172.22.150.102 - role: leaf -- fabric: "{{ msd_fabrics[0].name }}" - name: leaf_2 - ip: 172.22.150.103 - role: leaf -- fabric: "{{ msd_fabrics[0].name }}" - name: leaf_3 - ip: 172.22.150.104 - role: leaf -- fabric: "{{ msd_fabrics[0].name }}" - name: leaf_4 - ip: 172.22.150.105 - role: leaf -- fabric: "{{ msd_fabrics[0].name }}" - name: leaf_5 - ip: 172.22.150.106 - role: leaf -- fabric: "{{ msd_fabrics[0].name }}" - name: leaf_6 - ip: 172.22.150.107 - role: leaf -- fabric: "{{ msd_fabrics[0].name }}" - name: leaf_7 - ip: 172.22.150.108 - role: leaf -- fabric: "{{ msd_fabrics[0].name }}" - name: leaf_8 - ip: 172.22.150.109 - role: leaf - -spines: - # site_fabric f1 -- fabric: "{{ fabrics[0].name }}" - name: spine_1 - ip: 172.22.150.112 - role: spine -- fabric: "{{ fabrics[0].name }}" - name: spine_2 - ip: 172.22.150.113 - role: spine - # site_fabric f2 -- fabric: "{{ fabrics[1].name }}" - name: spine_1 - ip: 172.22.150.114 - role: spine -- fabric: "{{ fabrics[1].name }}" - name: spine_2 - ip: 172.22.150.115 - role: spine - -# spines need unique names across a MSD fabric. -# Below are duplicates of spines above but for msd_fabrics - -- fabric: "{{ msd_fabrics[0].name }}" - name: spine_1 - ip: 172.22.150.112 - role: spine -- fabric: "{{ msd_fabrics[0].name }}" - name: spine_2 - ip: 172.22.150.113 - role: spine -- fabric: "{{ msd_fabrics[0].name }}" - name: spine_3 - ip: 172.22.150.114 - role: spine -- fabric: "{{ msd_fabrics[0].name }}" - name: spine_4 - ip: 172.22.150.115 - role: spine - -border_gateways: -- fabric: "{{ fabrics[0].name }}" - name: border_gateway_1 - ip: 172.22.150.110 - role: border_gateway -- fabric: "{{ fabrics[0].name }}" - name: border_gateway_2 - ip: 172.22.150.111 - role: border_gateway -- fabric: "{{ fabrics[1].name }}" - name: border_gateway_1 - ip: 172.22.150.100 - role: border_gateway -- fabric: "{{ fabrics[1].name }}" - name: border_gateway_2 - ip: 172.22.150.101 - role: border_gateway - -# border_gateways need unique names across a MSD fabric. -# Below are duplicates of border_gateways above but for msd_fabrics - -- fabric: "{{ msd_fabrics[0].name }}" - name: border_gateway_1 - ip: 172.22.150.110 - role: border_gateway -- fabric: "{{ msd_fabrics[0].name }}" - name: border_gateway_2 - ip: 172.22.150.111 - role: border_gateway -- fabric: "{{ msd_fabrics[0].name }}" - name: border_gateway_3 - ip: 172.22.150.100 - role: border_gateway -- fabric: "{{ msd_fabrics[0].name }}" - name: border_gateway_4 - ip: 172.22.150.101 - role: border_gateway + sn_fabric_1: + name: sn_fabric_1 + type: external + BGP_AS: 65201 + DCI_SUBNET_RANGE: 10.101.1.0/24 + DCI_SUBNET_TARGET_MASK: 30 + LOOPBACK0_IP_RANGE: 10.201.0.0/22 + POWER_REDUNDANCY_MODE: ps-redundant + SUBINTERFACE_RANGE: 2-511 + sn_fabric_2: + name: sn_fabric_2 + type: external + BGP_AS: 65202 + DCI_SUBNET_RANGE: 10.102.1.0/24 + DCI_SUBNET_TARGET_MASK: 30 + LOOPBACK0_IP_RANGE: 10.202.0.0/22 + POWER_REDUNDANCY_MODE: ps-redundant + SUBINTERFACE_RANGE: 2-511 + sn_fabric_3: + name: sn_fabric_3 + type: external + BGP_AS: 65203 + DCI_SUBNET_RANGE: 10.103.1.0/24 + DCI_SUBNET_TARGET_MASK: 30 + LOOPBACK0_IP_RANGE: 10.203.0.0/22 + POWER_REDUNDANCY_MODE: ps-redundant + SUBINTERFACE_RANGE: 2-511 + ext_fabric_test: + name: ext_fabric_test + type: external + BGP_AS: 65204 + DCI_SUBNET_RANGE: 10.104.1.0/24 + DCI_SUBNET_TARGET_MASK: 30 + LOOPBACK0_IP_RANGE: 10.204.0.0/22 + POWER_REDUNDANCY_MODE: ps-redundant + SUBINTERFACE_RANGE: 2-511 + +devices: + leaf_1: + name: leaf_1 + switch_fabric: "{{ switch_fabrics.f1.name }}" + msd_fabric: "{{ msd_fabrics.MSD.name }}" + ip: 172.22.150.102 + role: leaf + leaf_2: + name: leaf_2 + switch_fabric: "{{ switch_fabrics.f1.name }}" + msd_fabric: "{{ msd_fabrics.MSD.name }}" + ip: 172.22.150.103 + role: leaf + leaf_3: + name: leaf_3 + switch_fabric: "{{ switch_fabrics.f1.name }}" + msd_fabric: "{{ msd_fabrics.MSD.name }}" + ip: 172.22.150.104 + role: leaf + leaf_4: + name: leaf_4 + switch_fabric: "{{ switch_fabrics.f1.name }}" + msd_fabric: "{{ msd_fabrics.MSD.name }}" + ip: 172.22.150.105 + role: leaf + # switch_fabric f2 + leaf_5: + name: leaf_5 + switch_fabric: "{{ switch_fabrics.f2.name }}" + msd_fabric: "{{ msd_fabrics.MSD.name }}" + ip: 172.22.150.106 + role: leaf + leaf_6: + name: leaf_6 + switch_fabric: "{{ switch_fabrics.f2.name }}" + msd_fabric: "{{ msd_fabrics.MSD.name }}" + ip: 172.22.150.107 + role: leaf + leaf_7: + name: leaf_7 + switch_fabric: "{{ switch_fabrics.f2.name }}" + msd_fabric: "{{ msd_fabrics.MSD.name }}" + ip: 172.22.150.108 + role: leaf + leaf_8: + name: leaf_8 + switch_fabric: "{{ switch_fabrics.f2.name }}" + msd_fabric: "{{ msd_fabrics.MSD.name }}" + ip: 172.22.150.109 + role: leaf + + spine_1: + name: spine_1 + switch_fabric: "{{ switch_fabrics.f1.name }}" + msd_fabric: "{{ msd_fabrics.MSD.name }}" + ip: 172.22.150.112 + role: spine + spine_2: + name: spine_2 + switch_fabric: "{{ switch_fabrics.f1.name }}" + msd_fabric: "{{ msd_fabrics.MSD.name }}" + ip: 172.22.150.113 + role: spine + spine_3: + name: spine_3 + switch_fabric: "{{ switch_fabrics.f2.name }}" + msd_fabric: "{{ msd_fabrics.MSD.name }}" + ip: 172.22.150.114 + role: spine + spine_4: + name: spine_4 + switch_fabric: "{{ switch_fabrics.f2.name }}" + msd_fabric: "{{ msd_fabrics.MSD.name }}" + ip: 172.22.150.115 + role: spine + + border_gateway_1: + name: border_gateway_1 + switch_fabric: "{{ switch_fabrics.f1.name }}" + msd_fabric: "{{ msd_fabrics.MSD.name }}" + ip: 172.22.150.110 + role: border_gateway + border_gateway_2: + name: border_gateway_2 + switch_fabric: "{{ switch_fabrics.f1.name }}" + msd_fabric: "{{ msd_fabrics.MSD.name }}" + ip: 172.22.150.111 + role: border_gateway + border_gateway_3: + name: border_gateway_3 + switch_fabric: "{{ switch_fabrics.f2.name }}" + msd_fabric: "{{ msd_fabrics.MSD.name }}" + ip: 172.22.150.100 + role: border_gateway + border_gateway_4: + name: border_gateway_4 + switch_fabric: "{{ switch_fabrics.f2.name }}" + msd_fabric: "{{ msd_fabrics.MSD.name }}" + ip: 172.22.150.101 + role: border_gateway + port_groups: pg11: @@ -228,186 +225,200 @@ port_groups: - Port-channel12 networks: -- fabric: "{{ fabrics[0].name }}" - net_name: n1111 - vrf_name: v1 - vlan_id: 1111 - gw_ip_subnet: "10.21.1.1/24" - attach: - - ip_address: "{{ leafs[0].ip }}" - ports: "{{ port_groups.pg11 }}" - - ip_address: "{{ leafs[1].ip }}" - ports: "{{ port_groups.pg11 }}" - - ip_address: "{{ leafs[2].ip }}" - ports: "{{ port_groups.pg11 }}" - - ip_address: "{{ leafs[3].ip }}" - ports: "{{ port_groups.pg11 }}" - -- fabric: "{{ fabrics[0].name }}" - net_name: n1112 - vrf_name: v2 - vlan_id: 1112 - gw_ip_subnet: "10.22.1.1/24" - attach: - - ip_address: "{{ leafs[0].ip }}" - ports: "{{ port_groups.pg12 }}" - - ip_address: "{{ leafs[1].ip }}" - ports: "{{ port_groups.pg12 }}" - - ip_address: "{{ leafs[2].ip }}" - ports: "{{ port_groups.pg12 }}" - - ip_address: "{{ leafs[3].ip }}" - ports: "{{ port_groups.pg12 }}" - -- fabric: "{{ fabrics[1].name }}" - net_name: n1111 - vrf_name: v1 - vlan_id: 1111 - gw_ip_subnet: "10.21.1.1/24" - attach: - - ip_address: "{{ leafs[4].ip }}" - ports: "{{ port_groups.pg11 }}" - - ip_address: "{{ leafs[5].ip }}" - ports: "{{ port_groups.pg11 }}" - - ip_address: "{{ leafs[6].ip }}" - ports: "{{ port_groups.pg11 }}" - - ip_address: "{{ leafs[7].ip }}" - ports: "{{ port_groups.pg11 }}" - -- fabric: "{{ fabrics[1].name }}" - net_name: n1112 - vrf_name: v2 - vlan_id: 1112 - gw_ip_subnet: "10.22.1.1/24" - attach: - - ip_address: "{{ leafs[4].ip }}" - ports: "{{ port_groups.pg12 }}" - - ip_address: "{{ leafs[5].ip }}" - ports: "{{ port_groups.pg12 }}" - - ip_address: "{{ leafs[6].ip }}" - ports: "{{ port_groups.pg12 }}" - - ip_address: "{{ leafs[7].ip }}" - ports: "{{ port_groups.pg12 }}" - -### If using an MSD fabric to interconnect sites, we need to apply networks and -### VRFs to the MSD fabric, rather than the individual site fabrics. The -### networks below are duplicates of the above site fabric networks but -### additionally define attachments for the border_gateway roles, and will be -### used if the fabric name is an MSD fabric. - -- fabric: "{{ msd_fabrics[0].name }}" - net_name: n1111 - vrf_name: v1 - vlan_id: 1111 - gw_ip_subnet: "10.21.1.1/24" - attach: - - ip_address: "{{ leafs[0].ip }}" - ports: "{{ port_groups.pg11 }}" - - ip_address: "{{ leafs[1].ip }}" - ports: "{{ port_groups.pg11 }}" - - ip_address: "{{ leafs[2].ip }}" - ports: "{{ port_groups.pg11 }}" - - ip_address: "{{ leafs[3].ip }}" - ports: "{{ port_groups.pg11 }}" - - ip_address: "{{ leafs[4].ip }}" - ports: "{{ port_groups.pg11 }}" - - ip_address: "{{ leafs[5].ip }}" - ports: "{{ port_groups.pg11 }}" - - ip_address: "{{ leafs[6].ip }}" - ports: "{{ port_groups.pg11 }}" - - ip_address: "{{ leafs[7].ip }}" - ports: "{{ port_groups.pg11 }}" - - ip_address: "{{ border_gateways[0].ip }}" - ports: "" - - ip_address: "{{ border_gateways[1].ip }}" - ports: "" - - ip_address: "{{ border_gateways[2].ip }}" - ports: "" - - ip_address: "{{ border_gateways[3].ip }}" - ports: "" - -- fabric: "{{ msd_fabrics[0].name }}" - net_name: n1112 - vrf_name: v2 - vlan_id: 1112 - gw_ip_subnet: "10.22.1.1/24" - attach: - - ip_address: "{{ leafs[0].ip }}" - ports: "{{ port_groups.pg12 }}" - - ip_address: "{{ leafs[1].ip }}" - ports: "{{ port_groups.pg12 }}" - - ip_address: "{{ leafs[2].ip }}" - ports: "{{ port_groups.pg12 }}" - - ip_address: "{{ leafs[3].ip }}" - ports: "{{ port_groups.pg12 }}" - - ip_address: "{{ leafs[4].ip }}" - ports: "{{ port_groups.pg12 }}" - - ip_address: "{{ leafs[5].ip }}" - ports: "{{ port_groups.pg12 }}" - - ip_address: "{{ leafs[6].ip }}" - ports: "{{ port_groups.pg12 }}" - - ip_address: "{{ leafs[7].ip }}" - ports: "{{ port_groups.pg12 }}" - - ip_address: "{{ border_gateways[0].ip }}" - ports: "" - - ip_address: "{{ border_gateways[1].ip }}" - ports: "" - - ip_address: "{{ border_gateways[2].ip }}" - ports: "" - - ip_address: "{{ border_gateways[3].ip }}" - ports: "" + f1_n1111: + name: f1_n1111 # name must be unique across all fabrics + fabric: "{{ switch_fabrics.f1.name }}" + net_name: n1111 # can be the same across fabrics + vrf_name: v1 + vlan_id: 1111 + gw_ip_subnet: "10.21.1.1/24" + attach: + - ip_address: "{{ devices.leaf_1.ip }}" + ports: "{{ port_groups.pg11 }}" + - ip_address: "{{ devices.leaf_2.ip }}" + ports: "{{ port_groups.pg11 }}" + - ip_address: "{{ devices.leaf_3.ip }}" + ports: "{{ port_groups.pg11 }}" + - ip_address: "{{ devices.leaf_4.ip }}" + ports: "{{ port_groups.pg11 }}" + + f1_n1112: + name: f1_n1112 + fabric: "{{ switch_fabrics.f1.name }}" + net_name: n1112 + vrf_name: v2 + vlan_id: 1112 + gw_ip_subnet: "10.22.1.1/24" + attach: + - ip_address: "{{ devices.leaf_1.ip }}" + ports: "{{ port_groups.pg12 }}" + - ip_address: "{{ devices.leaf_2.ip }}" + ports: "{{ port_groups.pg12 }}" + - ip_address: "{{ devices.leaf_3.ip }}" + ports: "{{ port_groups.pg12 }}" + - ip_address: "{{ devices.leaf_4.ip }}" + ports: "{{ port_groups.pg12 }}" + + f2_n1111: + name: f2_n1111 + fabric: "{{ switch_fabrics.f2.name }}" + net_name: n1111 + vrf_name: v1 + vlan_id: 1111 + gw_ip_subnet: "10.21.1.1/24" + attach: + - ip_address: "{{ devices.leaf_5.ip }}" + ports: "{{ port_groups.pg11 }}" + - ip_address: "{{ devices.leaf_6.ip }}" + ports: "{{ port_groups.pg11 }}" + - ip_address: "{{ devices.leaf_7.ip }}" + ports: "{{ port_groups.pg11 }}" + - ip_address: "{{ devices.leaf_8.ip }}" + ports: "{{ port_groups.pg11 }}" + + f2_n1112: + name: f2_n1112 + fabric: "{{ switch_fabrics.f2.name }}" + net_name: n1112 + vrf_name: v2 + vlan_id: 1112 + gw_ip_subnet: "10.22.1.1/24" + attach: + - ip_address: "{{ devices.leaf_5.ip }}" + ports: "{{ port_groups.pg12 }}" + - ip_address: "{{ devices.leaf_6.ip }}" + ports: "{{ port_groups.pg12 }}" + - ip_address: "{{ devices.leaf_7.ip }}" + ports: "{{ port_groups.pg12 }}" + - ip_address: "{{ devices.leaf_8.ip }}" + ports: "{{ port_groups.pg12 }}" + + msd_n1111: + name: msd_n1111 + fabric: "{{ msd_fabrics.MSD.name }}" + net_name: n1111 + vrf_name: v1 + vlan_id: 1111 + gw_ip_subnet: "10.21.1.1/24" + attach: + - ip_address: "{{ devices.leaf_1.ip }}" + ports: "{{ port_groups.pg11 }}" + - ip_address: "{{ devices.leaf_2.ip }}" + ports: "{{ port_groups.pg11 }}" + - ip_address: "{{ devices.leaf_3.ip }}" + ports: "{{ port_groups.pg11 }}" + - ip_address: "{{ devices.leaf_4.ip }}" + ports: "{{ port_groups.pg11 }}" + - ip_address: "{{ devices.leaf_5.ip }}" + ports: "{{ port_groups.pg11 }}" + - ip_address: "{{ devices.leaf_6.ip }}" + ports: "{{ port_groups.pg11 }}" + - ip_address: "{{ devices.leaf_7.ip }}" + ports: "{{ port_groups.pg11 }}" + - ip_address: "{{ devices.leaf_8.ip }}" + ports: "{{ port_groups.pg11 }}" + - ip_address: "{{ devices.border_gateway_1.ip }}" + ports: "" + - ip_address: "{{ devices.border_gateway_2.ip }}" + ports: "" + - ip_address: "{{ devices.border_gateway_3.ip }}" + ports: "" + - ip_address: "{{ devices.border_gateway_4.ip }}" + ports: "" + + msd_n1112: + name: msd_n1112 + fabric: "{{ msd_fabrics.MSD.name }}" + net_name: n1112 + vrf_name: v2 + vlan_id: 1112 + gw_ip_subnet: "10.22.1.1/24" + attach: + - ip_address: "{{ devices.leaf_1.ip }}" + ports: "{{ port_groups.pg11 }}" + - ip_address: "{{ devices.leaf_2.ip }}" + ports: "{{ port_groups.pg11 }}" + - ip_address: "{{ devices.leaf_3.ip }}" + ports: "{{ port_groups.pg11 }}" + - ip_address: "{{ devices.leaf_4.ip }}" + ports: "{{ port_groups.pg11 }}" + - ip_address: "{{ devices.leaf_5.ip }}" + ports: "{{ port_groups.pg11 }}" + - ip_address: "{{ devices.leaf_6.ip }}" + ports: "{{ port_groups.pg11 }}" + - ip_address: "{{ devices.leaf_7.ip }}" + ports: "{{ port_groups.pg11 }}" + - ip_address: "{{ devices.leaf_8.ip }}" + ports: "{{ port_groups.pg11 }}" + - ip_address: "{{ devices.border_gateway_1.ip }}" + ports: "" + - ip_address: "{{ devices.border_gateway_2.ip }}" + ports: "" + - ip_address: "{{ devices.border_gateway_3.ip }}" + ports: "" + - ip_address: "{{ devices.border_gateway_4.ip }}" + ports: "" vrfs: -- fabric: "{{ fabrics[0].name }}" - vrf_name: v1 - vrf_id: 63031 - vlan_id: 3031 - vrf_template: Default_VRF_Universal - vrf_extension_template: Default_VRF_Extension_Universal - service_vrf_template: null - attach: - - ip_address: "{{ leafs[0].ip }}" - - ip_address: "{{ leafs[1].ip }}" - - ip_address: "{{ leafs[2].ip }}" - - ip_address: "{{ leafs[3].ip }}" - -- fabric: "{{ fabrics[0].name }}" - vrf_name: v2 - vrf_id: 63032 - vlan_id: 3032 - vrf_template: Default_VRF_Universal - vrf_extension_template: Default_VRF_Extension_Universal - service_vrf_template: null - attach: - - ip_address: "{{ leafs[0].ip }}" - - ip_address: "{{ leafs[1].ip }}" - - ip_address: "{{ leafs[2].ip }}" - - ip_address: "{{ leafs[3].ip }}" - -- fabric: "{{ fabrics[1].name }}" - vrf_name: v1 - vrf_id: 63031 - vlan_id: 3031 - vrf_template: Default_VRF_Universal - vrf_extension_template: Default_VRF_Extension_Universal - service_vrf_template: null - attach: - - ip_address: "{{ leafs[4].ip }}" - - ip_address: "{{ leafs[5].ip }}" - - ip_address: "{{ leafs[6].ip }}" - - ip_address: "{{ leafs[7].ip }}" - -- fabric: "{{ fabrics[1].name }}" - vrf_name: v2 - vrf_id: 63032 - vlan_id: 3032 - vrf_template: Default_VRF_Universal - vrf_extension_template: Default_VRF_Extension_Universal - service_vrf_template: null - attach: - - ip_address: "{{ leafs[4].ip }}" - - ip_address: "{{ leafs[5].ip }}" - - ip_address: "{{ leafs[6].ip }}" - - ip_address: "{{ leafs[7].ip }}" + f1_v1: + name: f1_v1 + fabric: "{{ switch_fabrics.f1.name }}" + vrf_name: v1 + vrf_id: 63031 + vlan_id: 3031 + vrf_template: Default_VRF_Universal + vrf_extension_template: Default_VRF_Extension_Universal + service_vrf_template: null + attach: + - ip_address: "{{ devices.leaf_1.ip }}" + - ip_address: "{{ devices.leaf_2.ip }}" + - ip_address: "{{ devices.leaf_3.ip }}" + - ip_address: "{{ devices.leaf_4.ip }}" + + f1_v2: + name: f1_v2 + fabric: "{{ switch_fabrics.f1.name }}" + vrf_name: v2 + vrf_id: 63032 + vlan_id: 3032 + vrf_template: Default_VRF_Universal + vrf_extension_template: Default_VRF_Extension_Universal + service_vrf_template: null + attach: + - ip_address: "{{ devices.leaf_1.ip }}" + - ip_address: "{{ devices.leaf_2.ip }}" + - ip_address: "{{ devices.leaf_3.ip }}" + - ip_address: "{{ devices.leaf_4.ip }}" + + f2_v1: + name: f2_v1 + fabric: "{{ switch_fabrics.f2.name }}" + vrf_name: v1 + vrf_id: 63031 + vlan_id: 3031 + vrf_template: Default_VRF_Universal + vrf_extension_template: Default_VRF_Extension_Universal + service_vrf_template: null + attach: + - ip_address: "{{ devices.leaf_5.ip }}" + - ip_address: "{{ devices.leaf_6.ip }}" + - ip_address: "{{ devices.leaf_7.ip }}" + - ip_address: "{{ devices.leaf_8.ip }}" + + f2_v2: + name: f2_v2 + fabric: "{{ switch_fabrics.f2.name }}" + vrf_name: v2 + vrf_id: 63032 + vlan_id: 3032 + vrf_template: Default_VRF_Universal + vrf_extension_template: Default_VRF_Extension_Universal + service_vrf_template: null + attach: + - ip_address: "{{ devices.leaf_5.ip }}" + - ip_address: "{{ devices.leaf_6.ip }}" + - ip_address: "{{ devices.leaf_7.ip }}" + - ip_address: "{{ devices.leaf_8.ip }}" ### If using an MSD fabric to interconnect sites, we need to apply networks and ### VRFs to the MSD fabric, rather than the individual site fabrics. The @@ -415,232 +426,287 @@ vrfs: ### attachments for the border_gateway roles, and will be used if the fabric name ### is an MSD fabric. -- fabric: "{{ msd_fabrics[0].name }}" - vrf_name: v1 - vrf_id: 63031 - vlan_id: 3031 - vrf_template: Default_VRF_Universal - vrf_extension_template: Default_VRF_Extension_Universal - service_vrf_template: null - attach: - - ip_address: "{{ leafs[0].ip }}" - - ip_address: "{{ leafs[1].ip }}" - - ip_address: "{{ leafs[2].ip }}" - - ip_address: "{{ leafs[3].ip }}" - - ip_address: "{{ leafs[4].ip }}" - - ip_address: "{{ leafs[5].ip }}" - - ip_address: "{{ leafs[6].ip }}" - - ip_address: "{{ leafs[7].ip }}" - - ip_address: "{{ border_gateways[0].ip }}" - - ip_address: "{{ border_gateways[1].ip }}" - - ip_address: "{{ border_gateways[2].ip }}" - - ip_address: "{{ border_gateways[3].ip }}" -- fabric: "{{ msd_fabrics[0].name }}" - vrf_name: v2 - vrf_id: 63032 - vlan_id: 3032 - vrf_template: Default_VRF_Universal - vrf_extension_template: Default_VRF_Extension_Universal - service_vrf_template: null - attach: - - ip_address: "{{ leafs[0].ip }}" - - ip_address: "{{ leafs[1].ip }}" - - ip_address: "{{ leafs[2].ip }}" - - ip_address: "{{ leafs[3].ip }}" - - ip_address: "{{ leafs[4].ip }}" - - ip_address: "{{ leafs[5].ip }}" - - ip_address: "{{ leafs[6].ip }}" - - ip_address: "{{ leafs[7].ip }}" - - ip_address: "{{ border_gateways[0].ip }}" - - ip_address: "{{ border_gateways[1].ip }}" - - ip_address: "{{ border_gateways[2].ip }}" - - ip_address: "{{ border_gateways[3].ip }}" + msd_v1: + name: msd_v1 + fabric: "{{ msd_fabrics.MSD.name }}" + vrf_name: v1 + vrf_id: 63031 + vlan_id: 3031 + vrf_template: Default_VRF_Universal + vrf_extension_template: Default_VRF_Extension_Universal + service_vrf_template: null + attach: + - ip_address: "{{ devices.leaf_1.ip }}" + - ip_address: "{{ devices.leaf_2.ip }}" + - ip_address: "{{ devices.leaf_3.ip }}" + - ip_address: "{{ devices.leaf_4.ip }}" + - ip_address: "{{ devices.leaf_5.ip }}" + - ip_address: "{{ devices.leaf_6.ip }}" + - ip_address: "{{ devices.leaf_7.ip }}" + - ip_address: "{{ devices.leaf_8.ip }}" + - ip_address: "{{ devices.border_gateway_1.ip }}" + - ip_address: "{{ devices.border_gateway_2.ip }}" + - ip_address: "{{ devices.border_gateway_3.ip }}" + - ip_address: "{{ devices.border_gateway_4.ip }}" + + msd_v2: + name: msd_v2 + fabric: "{{ msd_fabrics.MSD.name }}" + vrf_name: v2 + vrf_id: 63032 + vlan_id: 3032 + vrf_template: Default_VRF_Universal + vrf_extension_template: Default_VRF_Extension_Universal + service_vrf_template: null + attach: + - ip_address: "{{ devices.leaf_1.ip }}" + - ip_address: "{{ devices.leaf_2.ip }}" + - ip_address: "{{ devices.leaf_3.ip }}" + - ip_address: "{{ devices.leaf_4.ip }}" + - ip_address: "{{ devices.leaf_5.ip }}" + - ip_address: "{{ devices.leaf_6.ip }}" + - ip_address: "{{ devices.leaf_7.ip }}" + - ip_address: "{{ devices.leaf_8.ip }}" + - ip_address: "{{ devices.border_gateway_1.ip }}" + - ip_address: "{{ devices.border_gateway_2.ip }}" + - ip_address: "{{ devices.border_gateway_3.ip }}" + - ip_address: "{{ devices.border_gateway_4.ip }}" # VPC Peers vpc_peers: -- fabric: "{{ fabrics[0].name }}" - vpc_name: "vpc1" - peer_1_ip: "{{ leafs[0].ip }}" - peer_2_ip: "{{ leafs[1].ip }}" -- fabric: "{{ fabrics[0].name }}" - vpc_name: "vpc2" - peer_1_ip: "{{ leafs[2].ip }}" - peer_2_ip: "{{ leafs[3].ip }}" - -- fabric: "{{ fabrics[1].name }}" - vpc_name: "vpc1" - peer_1_ip: "{{ leafs[4].ip }}" - peer_2_ip: "{{ leafs[5].ip }}" -- fabric: "{{ fabrics[1].name }}" - vpc_name: "vpc2" - peer_1_ip: "{{ leafs[6].ip }}" - peer_2_ip: "{{ leafs[7].ip }}" + vpc1: + fabric: "{{ switch_fabrics.f1.name }}" + vpc_name: "vpc1" + peer_1_ip: "{{ devices.leaf_1.ip }}" + peer_2_ip: "{{ devices.leaf_2.ip }}" + vpc2: + fabric: "{{ switch_fabrics.f1.name }}" + vpc_name: "vpc2" + peer_1_ip: "{{ devices.leaf_3.ip }}" + peer_2_ip: "{{ devices.leaf_4.ip }}" + vpc3: + fabric: "{{ switch_fabrics.f2.name }}" + vpc_name: "vpc3" + peer_1_ip: "{{ devices.leaf_5.ip }}" + peer_2_ip: "{{ devices.leaf_6.ip }}" + vpc4: + fabric: "{{ switch_fabrics.f2.name }}" + vpc_name: "vpc4" + peer_1_ip: "{{ devices.leaf_7.ip }}" + peer_2_ip: "{{ devices.leaf_8.ip }}" # VPC Interfaces vpc_interfaces: -- fabric: "{{ fabrics[0].name }}" - vpc_name: vpc1 - vpc_port_id: vpi11 - interface_mode: trunk - mtu: jumbo - port_type_fast: true - bpdu_guard: true - port_channel_mode: active - peer1_allowed_vlans: 1111 - peer2_allowed_vlans: 1111 - member_list: - - Ethernet1/11 - -- fabric: "{{ fabrics[0].name}}" - vpc_name: vpc2 - vpc_port_id: vpi11 - interface_mode: trunk - mtu: jumbo - port_type_fast: true - bpdu_guard: true - port_channel_mode: active - peer1_allowed_vlans: 1111 - peer2_allowed_vlans: 1111 - member_list: - - Ethernet1/11 - -- fabric: "{{ fabrics[0].name }}" - vpc_name: vpc1 - vpc_port_id: vpi12 - interface_mode: trunk - mtu: jumbo - port_type_fast: true - bpdu_guard: true - port_channel_mode: active - peer1_allowed_vlans: 1112 - peer2_allowed_vlans: 1112 - member_list: - - Ethernet1/12 - -- fabric: "{{ fabrics[0].name }}" - vpc_name: vpc2 - vpc_port_id: vpi12 - interface_mode: trunk - mtu: jumbo - port_type_fast: true - bpdu_guard: true - port_channel_mode: active - peer1_allowed_vlans: 1112 - peer2_allowed_vlans: 1112 - member_list: - - Ethernet1/12 + vpci_1111: + fabric: "{{ switch_fabrics.f1.name }}" + vpc_name: vpc1 + vpc_port_id: vpi11 + interface_mode: trunk + mtu: jumbo + port_type_fast: true + bpdu_guard: true + port_channel_mode: active + peer1_allowed_vlans: 1111 + peer2_allowed_vlans: 1111 + member_list: + - Ethernet1/11 + + vpci_1112: + fabric: "{{ switch_fabrics.f1.name }}" + vpc_name: vpc1 + vpc_port_id: vpi12 + interface_mode: trunk + mtu: jumbo + port_type_fast: true + bpdu_guard: true + port_channel_mode: active + peer1_allowed_vlans: 1112 + peer2_allowed_vlans: 1112 + member_list: + - Ethernet1/12 + + vpci_1211: + fabric: "{{ switch_fabrics.f1.name }}" + vpc_name: vpc2 + vpc_port_id: vpi11 + interface_mode: trunk + mtu: jumbo + port_type_fast: true + bpdu_guard: true + port_channel_mode: active + peer1_allowed_vlans: 1111 + peer2_allowed_vlans: 1111 + member_list: + - Ethernet1/11 + + vpci_1212: + fabric: "{{ switch_fabrics.f1.name }}" + vpc_name: vpc2 + vpc_port_id: vpi12 + interface_mode: trunk + mtu: jumbo + port_type_fast: true + bpdu_guard: true + port_channel_mode: active + peer1_allowed_vlans: 1112 + peer2_allowed_vlans: 1112 + member_list: + - Ethernet1/12 # f2 -- fabric: "{{ fabrics[1].name }}" - vpc_name: vpc1 - vpc_port_id: vpi11 - interface_mode: trunk - mtu: jumbo - port_type_fast: true - bpdu_guard: true - port_channel_mode: active - peer1_allowed_vlans: 1111 - peer2_allowed_vlans: 1111 - member_list: - - Ethernet1/11 - -- fabric: "{{ fabrics[1].name }}" - vpc_name: vpc2 - vpc_port_id: vpi11 - interface_mode: trunk - mtu: jumbo - port_type_fast: true - bpdu_guard: true - port_channel_mode: active - peer1_allowed_vlans: 1111 - peer2_allowed_vlans: 1111 - member_list: - - Ethernet1/11 - -- fabric: "{{ fabrics[1].name }}" - vpc_name: vpc1 - vpc_port_id: vpi12 - interface_mode: trunk - mtu: jumbo - port_type_fast: true - bpdu_guard: true - port_channel_mode: active - peer1_allowed_vlans: 1112 - peer2_allowed_vlans: 1112 - member_list: - - Ethernet1/12 - -- fabric: "{{ fabrics[1].name }}" - vpc_name: vpc2 - vpc_port_id: vpi12 - interface_mode: trunk - mtu: jumbo - port_type_fast: true - bpdu_guard: true - port_channel_mode: active - peer1_allowed_vlans: 1112 - peer2_allowed_vlans: 1112 - member_list: - - Ethernet1/12 + vpci_2111: + fabric: "{{ switch_fabrics.f2.name }}" + vpc_name: vpc3 + vpc_port_id: vpi11 + interface_mode: trunk + mtu: jumbo + port_type_fast: true + bpdu_guard: true + port_channel_mode: active + peer1_allowed_vlans: 1111 + peer2_allowed_vlans: 1111 + member_list: + - Ethernet1/11 + + vpci_2112: + fabric: "{{ switch_fabrics.f2.name }}" + vpc_name: vpc3 + vpc_port_id: vpi12 + interface_mode: trunk + mtu: jumbo + port_type_fast: true + bpdu_guard: true + port_channel_mode: active + peer1_allowed_vlans: 1112 + peer2_allowed_vlans: 1112 + member_list: + - Ethernet1/12 + + vpci_2211: + fabric: "{{ switch_fabrics.f2.name }}" + vpc_name: vpc4 + vpc_port_id: vpi11 + interface_mode: trunk + mtu: jumbo + port_type_fast: true + bpdu_guard: true + port_channel_mode: active + peer1_allowed_vlans: 1111 + peer2_allowed_vlans: 1111 + member_list: + - Ethernet1/11 + + vpci_2212: + fabric: "{{ switch_fabrics.f2.name }}" + vpc_name: vpc4 + vpc_port_id: vpi12 + interface_mode: trunk + mtu: jumbo + port_type_fast: true + bpdu_guard: true + port_channel_mode: active + peer1_allowed_vlans: 1112 + peer2_allowed_vlans: 1112 + member_list: + - Ethernet1/12 service_nodes: -- service_node_name: "sn_1" - external_fabric_name: "{{ external_fabrics[0].name }}" - # NOTE, service_node_type values are different between Ansible module - # dcnm_service_node and the REST API. Since ndfc-roles offers roles - # based on both, you need to ensure that you're using the correct - # service_node_type values, per below (these are case-sensitive): - # REST: "Firewall" "ADC" "VNF" - # dcnm_service_node: firewall, load_balancer, virtual_network_function - service_node_type: "firewall" - service_node_form_factor: "Virtual" - service_node_peer_name: "foo" - service_node_interface_name: "Ethernet1/1" - attached_fabric_name: "{{ fabrics[0].name }}" - attached_switch_name: "leaf_1" - attached_switch_interface_name: "Ethernet1/1" - vpc_switches_attached: false - link_template_name: "service_link_trunk" - interface_speed: "Auto" - interface_mtu: "jumbo" - interface_allowed_vlans: "all" - interface_bpduguard_enabled: true - interface_porttype_fast_enabled: true - interface_admin_state: true - -- service_node_name: "sn_2" - external_fabric_name: "{{ external_fabrics[1].name }}" - # see note for service_node_type above - service_node_type: "firewall" - service_node_form_factor: "Virtual" - service_node_peer_name: "bar" - service_node_interface_name: "Ethernet1/1" - attached_fabric_name: "{{ fabrics[0].name }}" - attached_switch_name: "leaf_2" - attached_switch_interface_name: "Ethernet1/1" - vpc_switches_attached: false - link_template_name: "service_link_trunk" - interface_speed: "Auto" - interface_mtu: "jumbo" - interface_allowed_vlans: "all" - interface_bpduguard_enabled: true - interface_porttype_fast_enabled: true - interface_admin_state: true - -- service_node_name: "sn_3" - external_fabric_name: "{{ external_fabrics[2].name }}" - service_node_type: "Firewall" - service_node_form_factor: "Virtual" - service_node_peer_name: "foobar" - service_node_interface_name: "Ethernet1/1" - attached_fabric_name: "{{ fabrics[1].name }}" - attached_switch_name: "leaf_1" - attached_switch_interface_name: "Ethernet1/1" - vpc_switches_attached: false - link_template_name: "service_link_trunk" - interface_speed: "Auto" - interface_mtu: "jumbo" - interface_allowed_vlans: "all" - interface_bpduguard_enabled: true - interface_porttype_fast_enabled: true - interface_admin_state: true + sn_1: + service_node_name: "sn_1" + external_fabric_name: "{{ external_fabrics.sn_fabric_1.name }}" + # NOTE, service_node_type values are different between Ansible module + # dcnm_service_node and the REST API. Since ndfc-roles offers roles + # based on both, you need to ensure that you're using the correct + # service_node_type values, per below (these are case-sensitive): + # REST: "Firewall" "ADC" "VNF" + # dcnm_service_node: firewall, load_balancer, virtual_network_function + service_node_type: "firewall" # dcnm_service_node + # service_node_type: "Firewall" # REST + service_node_form_factor: "Virtual" + service_node_peer_name: "foo" + service_node_interface_name: "Ethernet1/1" + attached_fabric_name: "{{ switch_fabrics.f1.name }}" + attached_switch_name: "leaf_1" + attached_switch_interface_name: "Ethernet1/1" + vpc_switches_attached: false + link_template_name: "service_link_trunk" + interface_speed: "Auto" + interface_mtu: "jumbo" + interface_allowed_vlans: "all" + interface_bpduguard_enabled: true + interface_porttype_fast_enabled: true + interface_admin_state: true + + sn_2: + service_node_name: "sn_2" + external_fabric_name: "{{ external_fabrics.sn_fabric_2.name }}" + # see note for service_node_type above + service_node_type: "firewall" + service_node_form_factor: "Virtual" + service_node_peer_name: "bar" + service_node_interface_name: "Ethernet1/1" + attached_fabric_name: "{{ switch_fabrics.f1.name }}" + attached_switch_name: "leaf_2" + attached_switch_interface_name: "Ethernet1/1" + vpc_switches_attached: false + link_template_name: "service_link_trunk" + interface_speed: "Auto" + interface_mtu: "jumbo" + interface_allowed_vlans: "all" + interface_bpduguard_enabled: true + interface_porttype_fast_enabled: true + interface_admin_state: true + + sn_3: + service_node_name: "sn_3" + external_fabric_name: "{{ external_fabrics.sn_fabric_3.name }}" + service_node_type: "Firewall" + service_node_form_factor: "Virtual" + service_node_peer_name: "foobar" + service_node_interface_name: "Ethernet1/1" + attached_fabric_name: "{{ switch_fabrics.f2.name }}" + attached_switch_name: "leaf_1" + attached_switch_interface_name: "Ethernet1/1" + vpc_switches_attached: false + link_template_name: "service_link_trunk" + interface_speed: "Auto" + interface_mtu: "jumbo" + interface_allowed_vlans: "all" + interface_bpduguard_enabled: true + interface_porttype_fast_enabled: true + interface_admin_state: true + +service_route_peerings: + srp_1: + state: merged + fabric: "{{ switch_fabrics.f1.name }}" + foo: "{{ switch_fabrics.f2.name}}" + service_fabric: "{{ external_fabrics.sn_fabric_2.name }}" + attach: true + deploy: true + config: + - name: IT-FW-RP1 # mandatory + node_name: sn_2 # mandatory + deploy_mode: intra_tenant_fw # mandatory, choices=[intra_tenant_fw, inter_tenant_fw] + inside_network: # + vrf: v1 # mandatory + name: rp1-sn1-inside-net # mandatory + vlan_id: 1111 # optional + profile: + ipv4_gw: 10.21.1.1/24 # mandatory + #ipv6_gw: 2001:db01::1/64 # optional, default is '' + #vlan_name: rp1-sn1-inside # optional, default is '' + int_descr: "RP1 SN1 inside interface" # optional, default is '' + tag: 12345 # optional, default is 12345 + next_hop: 10.21.1.100 # mandatory + outside_network: # + vrf: v1 # mandatory + name: rp1-sn1-outside-net # mandatory + vlan_id: 1112 # optional + profile: + ipv4_gw: 10.22.1.1/24 # mandatory + #ipv6_gw: 2001:db02::1/64 # optional, default is '' + #vlan_name: rp1-sn1-outside # optional, default is '' + int_descr: "RP1 SN1 outside interface" # optionL, default is '' + tag: 12345 # optional, default is 12345 + reverse_next_hop: 10.22.1.100 # optional, default is '' diff --git a/roles/ndfc_device_config_get/README.md b/roles/ndfc_device_config_get/README.md new file mode 100644 index 0000000..ac4d7b0 --- /dev/null +++ b/roles/ndfc_device_config_get/README.md @@ -0,0 +1,42 @@ +# ndfc_device_deleted + +Delete device ``device_name`` from fabric ``fabric_name`` using ``cisco.dcnm.dcnm_inventory`` + +### Role Variables + +Variable | Type | Description +----------------|-------|---------------------------------------- +device_name | str() | The device to be deleted +fabric_name | str() | The fabric in which device_name resides + +Device and fabric names are defined in the following file: + +``./roles/ndfc_common/vars/main.yml``) + +See the following for details: + +[./roles/ndfc_common/README.md](https://github.com/allenrobel/ndfc-roles/tree/master/roles/ndfc_common/README.md) + + +### Example Playbook + +```yaml +--- +- hosts: ndfc + gather_facts: false + roles: + - ndfc_device_deleted + vars: + fabric_name: f1 + device_name: spine_1 +``` + +### Licensing + +GNU General Public License v3.0 or later. + +See [LICENSE](https://www.gnu.org/licenses/gpl-3.0.txt) for full text. + +### Author Information + +Allen Robel (@packetcalc) diff --git a/roles/ndfc_device_query/meta/main.yml b/roles/ndfc_device_config_get/meta/main.yml similarity index 100% rename from roles/ndfc_device_query/meta/main.yml rename to roles/ndfc_device_config_get/meta/main.yml diff --git a/roles/ndfc_device_config_get/tasks/main.yml b/roles/ndfc_device_config_get/tasks/main.yml new file mode 100644 index 0000000..2c12dc4 --- /dev/null +++ b/roles/ndfc_device_config_get/tasks/main.yml @@ -0,0 +1,6 @@ +--- +- name: set_fact device_config {{ device_name }} + ansible.builtin.set_fact: + device_config: "{{ devices | json_query(device_config_get_q1) }}" + vars: + device_config_get_q1: "{{ device_name }}" diff --git a/roles/ndfc_device_config_get/vars/main.yml b/roles/ndfc_device_config_get/vars/main.yml new file mode 100644 index 0000000..f2bcdf0 --- /dev/null +++ b/roles/ndfc_device_config_get/vars/main.yml @@ -0,0 +1 @@ +ansible_connection: local diff --git a/roles/ndfc_device_deleted/tasks/main.yml b/roles/ndfc_device_deleted/tasks/main.yml index cc9398c..5e9d119 100644 --- a/roles/ndfc_device_deleted/tasks/main.yml +++ b/roles/ndfc_device_deleted/tasks/main.yml @@ -1,8 +1,20 @@ -# ndfc_device_deleted/tasks/main.yml --- -- name: main deleted FABRIC {{ fabric_name }} DEVICE {{ device_name }} - include_tasks: worker.yml - loop: "{{ mr1 }}" +- ansible.builtin.include_role: + name: ndfc_device_config_get + +- ansible.builtin.include_role: + name: ndfc_device_serial_number_get vars: - mq1: "[?name == '{{ device_name }}'] | [?fabric == '{{ fabric_name }}']" - mr1: "{{ leafs | json_query(mq1) + spines | json_query(mq1) + border_gateways | json_query(mq1) }}" + device_name: "{{ device_config.name }}" + fabric_name: "{{ device_config.switch_fabric }}" + +- name: device deleted fabric {{ device_config.switch_fabric }} name {{ device_config.name }} ip {{ device_config.ip }} serial_number ({{ device_serial_number }}) + cisco.dcnm.dcnm_inventory: + fabric: "{{ device_config.switch_fabric }}" + state: deleted + config: + - seed_ip: "{{ device_config.ip }}" + when: "device_serial_number != ''" + +- ansible.builtin.include_role: + name: ndfc_rest_config_deploy_all diff --git a/roles/ndfc_device_deleted/tasks/worker.yml b/roles/ndfc_device_deleted/tasks/worker.yml deleted file mode 100644 index 029251b..0000000 --- a/roles/ndfc_device_deleted/tasks/worker.yml +++ /dev/null @@ -1,20 +0,0 @@ ---- -- ansible.builtin.include_role: - name: ndfc_device_serial_number_get - vars: - device_name: "{{ item.name }}" - fabric_name: "{{ item.fabric }}" - -- name: worker deleted device_fabric {{ item.fabric }} device_name {{ item.name }} device_ip {{ item.ip}} device_serial_number ({{ device_serial_number }}) - cisco.dcnm.dcnm_inventory: - fabric: "{{ item.fabric }}" - state: deleted - config: - - seed_ip: "{{ item.ip }}" - when: "device_serial_number != ''" - -- ansible.builtin.include_role: - name: ndfc_rest_config_deploy - vars: - device_name: "{{ item.name }}" - fabric_name: "{{ item.fabric }}" diff --git a/roles/ndfc_device_generated_configs_get/tasks/main.yml b/roles/ndfc_device_generated_configs_get/tasks/main.yml index 8a0cfbf..6e59af1 100644 --- a/roles/ndfc_device_generated_configs_get/tasks/main.yml +++ b/roles/ndfc_device_generated_configs_get/tasks/main.yml @@ -1,8 +1,19 @@ -# ndfc_device_generated_configs_get/main.yml ---- -- name: main query FABRIC {{ fabric_name }} DEVICE {{ device_name }} - include_tasks: worker.yml - loop: "{{ mr1 }}" +# ndfc_device_generated_configs_get/worker.yml + +- ansible.builtin.include_role: + name: ndfc_device_config_get + +- name: main query FABRIC {{ device_config.switch_fabric }} DEVICE {{ device_config.name }} IP {{ device_config.ip }} generated_config + cisco.dcnm.dcnm_policy: + fabric: "{{ device_config.switch_fabric }}" + state: query + config: + - switch: + - ip: "{{ device_config.ip }}" + register: wr1 + +- name: worker set_fact generated_config DEVICE {{ device_config.name }} IP {{ device_config.ip }} + set_fact: + device_generated_configs: "{{ wr1.response | json_query(wq1) }}" vars: - mq1: "[?name == '{{ device_name }}'] | [?fabric == '{{ fabric_name }}']" - mr1: "{{ leafs | json_query(mq1) + spines | json_query(mq1) + border_gateways | json_query(mq1) }}" + wq1: "[?generatedConfig != ''].{TemplateName: templateName GeneratedConfig: generatedConfig}" diff --git a/roles/ndfc_device_generated_configs_get/tasks/worker.yml b/roles/ndfc_device_generated_configs_get/tasks/worker.yml deleted file mode 100644 index 13b57c4..0000000 --- a/roles/ndfc_device_generated_configs_get/tasks/worker.yml +++ /dev/null @@ -1,15 +0,0 @@ -# ndfc_device_generated_configs_get/worker.yml -- name: worker query FABRIC {{ item.fabric }} DEVICE {{ item.name }} IP {{ item.ip }} generated_config - cisco.dcnm.dcnm_policy: - fabric: "{{ item.fabric }}" - state: query - config: - - switch: - - ip: "{{ item.ip }}" - register: wr1 - -- name: worker set_fact generated_config DEVICE {{ item.name }} IP {{ item.ip }} - set_fact: - device_generated_configs: "{{ wr1.response | json_query(wq1) }}" - vars: - wq1: "[?generatedConfig != ''].{TemplateName: templateName GeneratedConfig: generatedConfig}" diff --git a/roles/ndfc_device_info_get/tasks/main.yml b/roles/ndfc_device_info_get/tasks/main.yml index 5d2c8d7..cf10ff3 100644 --- a/roles/ndfc_device_info_get/tasks/main.yml +++ b/roles/ndfc_device_info_get/tasks/main.yml @@ -1,10 +1,17 @@ -# ndfc_device_info_get/tasks/main.yml ---- -- name: main device_info_get FABRIC {{ fabric_name }} DEVICE {{ device_name }} - include_tasks: worker.yml - loop: "{{ mr1 }}" - loop_control: - loop_var: d +# ndfc_device_info_get/tasks/worker.yml +- ansible.builtin.include_role: + name: ndfc_device_config_get + +- name: query FABRIC {{ device_config.switch_fabric }} NAME {{ device_config.name }} IP {{ device_config.ip }} + cisco.dcnm.dcnm_inventory: + fabric: "{{ device_config.switch_fabric }}" + state: query + config: + - seed_ip: "{{ device_config.ip }}" + register: wr1 + +- name: worker set_fact device_info + set_fact: + device_info: "{{ wr1.response | json_query(wq1) }}" vars: - mq1: "[?name == '{{ device_name }}'] | [?fabric == '{{ fabric_name }}']" - mr1: "{{ leafs | json_query(mq1) + spines | json_query(mq1) + border_gateways | json_query(mq1) }}" + wq1: "[0]" diff --git a/roles/ndfc_device_info_get/tasks/worker.yml b/roles/ndfc_device_info_get/tasks/worker.yml deleted file mode 100644 index 3f0e8d1..0000000 --- a/roles/ndfc_device_info_get/tasks/worker.yml +++ /dev/null @@ -1,14 +0,0 @@ -# ndfc_device_info_get/tasks/worker.yml -- name: worker query FABRIC {{ d.fabric }} NAME {{ d.name }} IP {{ d.ip }} - cisco.dcnm.dcnm_inventory: - fabric: "{{ d.fabric }}" - state: query - config: - - seed_ip: "{{ d.ip }}" - register: wr1 - -- name: worker set_fact device_info - set_fact: - device_info: "{{ wr1.response | json_query(wq1) }}" - vars: - wq1: "[0]" diff --git a/roles/ndfc_device_ipv4_address_local_get/README.md b/roles/ndfc_device_ipv4_address_local_get/README.md index 6f64ff3..4465dc7 100644 --- a/roles/ndfc_device_ipv4_address_local_get/README.md +++ b/roles/ndfc_device_ipv4_address_local_get/README.md @@ -1,6 +1,6 @@ # ndfc_device_ipv4_address_local_get -Return device's ipv4 address, given ``device_name`` and fabric ``fabric_name``. +Return device's ipv4 address, given ``device_name``. The device's ipv4 address is returned in the variable ``device_ipv4_address``. @@ -15,9 +15,8 @@ SEE ALSO: ``ndfc_device_ipv4_address_remote_get`` Variable | Type | Description ----------------|-------|---------------------------------------- device_name | str() | The device to be queried -fabric_name | str() | The fabric in which device_name resides -Device and Fabric names are defined in the following file: +Device names are defined in the following file: ``./roles/ndfc_common/vars/main.yml``) @@ -36,7 +35,6 @@ See the following for details: roles: - ndfc_device_ipv4_address_local_get vars: - fabric_name: f2 device_name: leaf_1 tasks: - block: diff --git a/roles/ndfc_device_ipv4_address_local_get/tasks/main.yml b/roles/ndfc_device_ipv4_address_local_get/tasks/main.yml index 12bdeef..55d9ab1 100644 --- a/roles/ndfc_device_ipv4_address_local_get/tasks/main.yml +++ b/roles/ndfc_device_ipv4_address_local_get/tasks/main.yml @@ -1,11 +1,9 @@ -# ndfc_device_ipv4_address_local_get/tasks/main.yml -# Return device_ipv4_address, given fabric_name and device_name ---- -- name: main device_model_number_get FABRIC {{ fabric_name }} DEVICE {{ device_name }} - include_tasks: worker.yml - loop: "{{ mr1 }}" - loop_control: - loop_var: device - vars: - mq1: "[?name == '{{ device_name }}'] | [?fabric == '{{ fabric_name }}']" - mr1: "{{ leafs | json_query(mq1) + spines | json_query(mq1) + border_gateways | json_query(mq1) }}" +# ndfc_device_ipv4_address_local_get/tasks/worker.yml + +- ansible.builtin.include_role: + name: ndfc_device_config_get + +# Device ipv4 address +- name: worker set_fact device_ipv4_address + set_fact: + device_ipv4_address: "{{ device_config.ip }}" diff --git a/roles/ndfc_device_ipv4_address_local_get/tasks/worker.yml b/roles/ndfc_device_ipv4_address_local_get/tasks/worker.yml deleted file mode 100644 index 006fa94..0000000 --- a/roles/ndfc_device_ipv4_address_local_get/tasks/worker.yml +++ /dev/null @@ -1,6 +0,0 @@ -# ndfc_device_ipv4_address_local_get/tasks/worker.yml - -# Device ipv4 address -- name: worker set_fact device_ipv4_address - set_fact: - device_ipv4_address: "{{ device.ip }}" diff --git a/roles/ndfc_device_ipv4_address_remote_get/README.md b/roles/ndfc_device_ipv4_address_remote_get/README.md index 0394831..cee2930 100644 --- a/roles/ndfc_device_ipv4_address_remote_get/README.md +++ b/roles/ndfc_device_ipv4_address_remote_get/README.md @@ -1,6 +1,6 @@ # ndfc_device_ipv4_address_remote_get -Return device's ipv4 address, given ``device_name`` and fabric ``fabric_name``. +Return device's ipv4 address, given ``device_name``. The device's ipv4 address is returned in the variable ``device_ipv4_address``. @@ -15,9 +15,8 @@ SEE ALSO: ``ndfc_device_ipv4_address_local_get`` Variable | Type | Description ----------------|-------|---------------------------------------- device_name | str() | The device to be queried -fabric_name | str() | The fabric in which device_name resides -Device and Fabric names are defined in the following file: +Device names are defined in the following file: ``./roles/ndfc_common/vars/main.yml``) @@ -36,7 +35,6 @@ See the following for details: roles: - ndfc_device_ipv4_address_remote_get vars: - fabric_name: f2 device_name: leaf_1 tasks: - block: diff --git a/roles/ndfc_device_ipv4_address_remote_get/tasks/main.yml b/roles/ndfc_device_ipv4_address_remote_get/tasks/main.yml index 9a6d857..a2c5e58 100644 --- a/roles/ndfc_device_ipv4_address_remote_get/tasks/main.yml +++ b/roles/ndfc_device_ipv4_address_remote_get/tasks/main.yml @@ -1,11 +1,19 @@ -# ndfc_device_ipv4_address_remote_get/tasks/main.yml -# Return device_ipv4_address, given fabric_name and device_name ---- -- name: main device_model_number_get FABRIC {{ fabric_name }} DEVICE {{ device_name }} - include_tasks: worker.yml - loop: "{{ mr1 }}" - loop_control: - loop_var: device +# ndfc_device_ipv4_address_remote_get/tasks/worker.yml + +- ansible.builtin.include_role: + name: ndfc_device_config_get + +- name: worker device_ipv4_address_get FABRIC {{ device_config.switch_fabric }} NAME {{ device_config.name }} IP {{ device_config.ip }} + cisco.dcnm.dcnm_inventory: + fabric: "{{ device_config.switch_fabric }}" + state: query + config: + - seed_ip: "{{ device_config.ip }}" + register: wr1 + +# Device ipv4 address +- name: worker set_fact device_ipv4_address + set_fact: + device_ipv4_address: "{{ wr1.response | json_query(wq2) }}" vars: - mq1: "[?name == '{{ device_name }}'] | [?fabric == '{{ fabric_name }}']" - mr1: "{{ leafs | json_query(mq1) + spines | json_query(mq1) + border_gateways | json_query(mq1) }}" + wq2: "[0].ipAddress" diff --git a/roles/ndfc_device_ipv4_address_remote_get/tasks/worker.yml b/roles/ndfc_device_ipv4_address_remote_get/tasks/worker.yml deleted file mode 100644 index 9d71430..0000000 --- a/roles/ndfc_device_ipv4_address_remote_get/tasks/worker.yml +++ /dev/null @@ -1,15 +0,0 @@ -# ndfc_device_ipv4_address_remote_get/tasks/worker.yml -- name: worker device_ipv4_address_get FABRIC {{ device.fabric }} NAME {{ device.name }} local (inventory) IP {{ device.ip }} - cisco.dcnm.dcnm_inventory: - fabric: "{{ device.fabric }}" - state: query - config: - - seed_ip: "{{ device.ip }}" - register: wr1 - -# Device ipv4 address -- name: worker set_fact device_ipv4_address - set_fact: - device_ipv4_address: "{{ wr1.response | json_query(wq2) }}" - vars: - wq2: "[0].ipAddress" diff --git a/roles/ndfc_device_merged/tasks/main.yml b/roles/ndfc_device_merged/tasks/main.yml index 7272348..52b5f8c 100644 --- a/roles/ndfc_device_merged/tasks/main.yml +++ b/roles/ndfc_device_merged/tasks/main.yml @@ -1,8 +1,23 @@ -# ndfc_device_merged/tasks/main.yml ---- -- name: main merged FABRIC {{ fabric_name }} DEVICE {{ device_name }} - include_tasks: worker.yml - loop: "{{ mr1 }}" +# ndfc_device_merged/tasks/worker.yml + +- ansible.builtin.include_role: + name: ndfc_device_config_get + +- name: worker merged FABRIC {{ device_config.switch_fabric }} NAME {{ device_config.name }} IP {{ device_config.ip }} + cisco.dcnm.dcnm_inventory: + fabric: "{{ device_config.switch_fabric }}" + state: merged + config: + - seed_ip: "{{ device_config.ip }}" + auth_proto: "{{ auth_proto }}" + user_name: "{{ device_username }}" + password: "{{ device_password }}" + max_hops: "{{ max_hops }}" + role: "{{ device_config.role }}" + preserve_config: "{{ preserve_config }}" + +- ansible.builtin.include_role: + name: ndfc_rest_config_deploy vars: - mq1: "[?name == '{{ device_name }}'] | [?fabric == '{{ fabric_name }}']" - mr1: "{{ leafs | json_query(mq1) + spines | json_query(mq1) + border_gateways | json_query(mq1) }}" + device_name: "{{ device_config.name }}" + fabric_name: "{{ device_config.switch_fabric }}" diff --git a/roles/ndfc_device_merged/tasks/worker.yml b/roles/ndfc_device_merged/tasks/worker.yml deleted file mode 100644 index 220c8b8..0000000 --- a/roles/ndfc_device_merged/tasks/worker.yml +++ /dev/null @@ -1,20 +0,0 @@ -# ndfc_device_merged/tasks/worker.yml - -- name: worker merged FABRIC {{ item.fabric }} NAME {{ item.name }} IP {{ item.ip }} - cisco.dcnm.dcnm_inventory: - fabric: "{{ item.fabric }}" - state: merged - config: - - seed_ip: "{{ item.ip }}" - auth_proto: "{{ auth_proto }}" - user_name: "{{ device_username }}" - password: "{{ device_password }}" - max_hops: "{{ max_hops }}" - role: "{{ item.role }}" - preserve_config: "{{ preserve_config }}" - -- ansible.builtin.include_role: - name: ndfc_rest_config_deploy - vars: - device_name: "{{ item.name }}" - fabric_name: "{{ item.fabric }}" diff --git a/roles/ndfc_device_merged_all/tasks/main.yml b/roles/ndfc_device_merged_all/tasks/main.yml index 8eae054..b599d6a 100644 --- a/roles/ndfc_device_merged_all/tasks/main.yml +++ b/roles/ndfc_device_merged_all/tasks/main.yml @@ -1,20 +1,5 @@ # ndfc_device_merged_all/tasks/main.yml --- -- name: main merged leaf FABRIC {{ fabric_name }} +- name: all devices merged include_tasks: worker.yml - loop: "{{ leafs | json_query(mq1) }}" - vars: - mq1: "[?fabric == '{{ fabric_name }}']" -- name: main merged spine FABRIC {{ fabric_name }} - include_tasks: worker.yml - loop: "{{ spines | json_query(mq2) }}" - vars: - mq2: "[?fabric == '{{ fabric_name }}']" -- name: main merged border_gateway FABRIC {{ fabric_name }} - include_tasks: worker.yml - loop: "{{ border_gateways | json_query(mq3) }}" - vars: - mq3: "[?fabric == '{{ fabric_name }}']" - -- ansible.builtin.include_role: - name: ndfc_rest_config_deploy_all + loop: "{{ devices.values() | list }}" diff --git a/roles/ndfc_device_merged_all/tasks/worker.yml b/roles/ndfc_device_merged_all/tasks/worker.yml index e2f98f8..bb14829 100644 --- a/roles/ndfc_device_merged_all/tasks/worker.yml +++ b/roles/ndfc_device_merged_all/tasks/worker.yml @@ -1,14 +1,12 @@ # ndfc_device_merged_all/tasks/worker.yml -- ansible.builtin.include_role: - name: ndfc_device_serial_number_get - vars: - device_name: "{{ item.name }}" - fabric_name: "{{ item.fabric }}" +- name: debug item + debug: + var: item -- name: worker merged FABRIC {{ item.fabric }} NAME {{ item.name }} device_serial_number {{ device_serial_number }} IP {{ item.ip }} MAX_HOPS {{ max_hops }} AUTH_PROTO {{ auth_proto }} +- name: worker merged FABRIC {{ item.switch_fabric }} NAME {{ item.name }} IP {{ item.ip }} MAX_HOPS {{ max_hops }} AUTH_PROTO {{ auth_proto }} cisco.dcnm.dcnm_inventory: - fabric: "{{ item.fabric }}" + fabric: "{{ item.switch_fabric }}" state: merged config: - seed_ip: "{{ item.ip }}" @@ -18,4 +16,11 @@ max_hops: "{{ max_hops }}" role: "{{ item.role }}" preserve_config: "{{ preserve_config }}" - when: "device_serial_number == ''" + vars: + ansible_connection: httpapi + +- ansible.builtin.include_role: + name: ndfc_rest_config_deploy + vars: + fabric: "{{ item.switch_fabric }}" + device_name: "{{ item.name }}" diff --git a/roles/ndfc_device_model_number_get/tasks/main.yml b/roles/ndfc_device_model_number_get/tasks/main.yml index b3dbdd2..795f24f 100644 --- a/roles/ndfc_device_model_number_get/tasks/main.yml +++ b/roles/ndfc_device_model_number_get/tasks/main.yml @@ -1,11 +1,18 @@ -# ndfc_device_model_number_get/tasks/main.yml -# Return device_model_number, given fabric_name and device_name ---- -- name: main device_model_number_get FABRIC {{ fabric_name }} DEVICE {{ device_name }} - include_tasks: worker.yml - loop: "{{ mr1 }}" - loop_control: - loop_var: device +# ndfc_device_model_number_get/tasks/worker.yml +- ansible.builtin.include_role: + name: ndfc_device_config_get + +- name: worker device_model_number_get FABRIC {{ device_config.switch_fabric }} NAME {{ device_config.name }} IP {{ device_config.ip }} + cisco.dcnm.dcnm_inventory: + fabric: "{{ device_config.switch_fabric }}" + state: query + config: + - seed_ip: "{{ device_config.ip }}" + register: wr1 + +# Device model number +- name: worker set_fact device_model_number + set_fact: + device_model_number: "{{ wr1.response | json_query(wq2) }}" vars: - mq1: "[?name == '{{ device_name }}'] | [?fabric == '{{ fabric_name }}']" - mr1: "{{ leafs | json_query(mq1) + spines | json_query(mq1) + border_gateways | json_query(mq1) }}" + wq2: "[0].model" diff --git a/roles/ndfc_device_model_number_get/tasks/worker.yml b/roles/ndfc_device_model_number_get/tasks/worker.yml deleted file mode 100644 index 87f09b7..0000000 --- a/roles/ndfc_device_model_number_get/tasks/worker.yml +++ /dev/null @@ -1,15 +0,0 @@ -# ndfc_device_model_number_get/tasks/worker.yml -- name: worker device_model_number_get FABRIC {{ device.fabric }} NAME {{ device.name }} IP {{ device.ip }} - cisco.dcnm.dcnm_inventory: - fabric: "{{ device.fabric }}" - state: query - config: - - seed_ip: "{{ device.ip }}" - register: wr1 - -# Device model number -- name: worker set_fact device_model_number - set_fact: - device_model_number: "{{ wr1.response | json_query(wq2) }}" - vars: - wq2: "[0].model" diff --git a/roles/ndfc_device_query/README.md b/roles/ndfc_device_query/README.md deleted file mode 100644 index 809466f..0000000 --- a/roles/ndfc_device_query/README.md +++ /dev/null @@ -1,182 +0,0 @@ -# ndfc_device_query - -Query device ``device_name`` in fabric ``fabric_name``. - -A device_info object is returned, as described below. - -### Role Variables - -Variable | Type | Description -----------------|-------|---------------------------------------- -device_name | str() | The device to be queried -fabric_name | str() | The fabric in which device_name resides - -Device and Fabric names are defined in the following file: - -``./roles/ndfc_common/vars/main.yml``) - -See the following for details: - -[./roles/ndfc_common/README.md](https://github.com/allenrobel/ndfc-roles/tree/master/roles/ndfc_common/README.md) - -### Example Playbook - -```yaml -# Query NX-OS switch associated with fabric_name + device_name -# and print several items from the returned device_info dictionary ---- -- hosts: ndfc - gather_facts: false - roles: - - ndfc_device_query - vars: - fabric_name: f2 - device_name: leaf_1 - tasks: - - block: - - debug: - msg: "uptime: {{ device_info.upTimeStr }}" - - debug: - msg: "serial: {{ device_info.serialNumber }}" - - debug: - msg: "version: {{ device_info.release }}" - when: "serial != ''" -``` - -### Licensing - -GNU General Public License v3.0 or later. - -See [LICENSE](https://www.gnu.org/licenses/gpl-3.0.txt) for full text. - -### Author Information - -Allen Robel (@packetcalc) - - - -### Example returned object device_info (as of NDFC version 12.0.1) - -{ - "device_info": { - "activeSupSlot": 0, - "availPorts": 0, - "colDBId": 0, - "connUnitStatus": 0, - "consistencyState": true, - "contact": "", - "cpuUsage": 25, - "deviceType": "Switch_Fabric", - "displayHdrs": [ - "Name", - "IP Address", - "Fabric", - "WWN", - "FC Ports", - "Vendor", - "Model", - "Release", - "UpTime" - ], - "displayValues": [ - "cvd_leaf_2311", - "172.XX.XX.XX", - "fabric_2", - "FDOXXXXXXXX", - "54", - "Cisco", - "N9K-C93180YC-EX", - "10.2(3)", - "18 days, 23:02:23" - ], - "domain": null, - "domainID": 0, - "elementType": null, - "fabricId": 3, - "fabricName": "fabric_2", - "fabricTechnology": "VXLANFabric", - "fcoeEnabled": false, - "fex": false, - "fexMap": {}, - "fid": 3, - "health": -1, - "hostName": "cvd_leaf_2311", - "index": 3, - "interfaces": null, - "ipAddress": "172.XX.XX.XX", - "ipDomain": "", - "isEchSupport": false, - "isLan": false, - "isNonNexus": false, - "isPmCollect": false, - "isTrapDelayed": false, - "isVpcConfigured": true, - "is_smlic_enabled": false, - "keepAliveState": "Peer is not alive", - "lastScanTime": 1649700732019, - "licenseDetail": null, - "licenseViolation": false, - "linkName": null, - "location": "", - "logicalName": "cvd_leaf_2311", - "managable": true, - "mds": false, - "membership": null, - "memoryUsage": 35, - "mgmtAddress": null, - "mode": "Normal", - "model": "N9K-C93180YC-EX", - "modelType": 0, - "moduleIndexOffset": 9999, - "modules": null, - "name": null, - "network": "LAN", - "nonMdsModel": "N9K-C93180YC-EX", - "npvEnabled": false, - "numberOfPorts": 54, - "peer": "cvd_leaf_2312", - "peerSerialNumber": "FDOXXXXXXXX", - "peerSwitchDbId": 576650, - "peerlinkState": "Peer link is down", - "ports": 0, - "present": true, - "primaryIP": null, - "primarySwitchDbID": 0, - "principal": null, - "recvIntf": "mgmt0", - "release": "10.2(3)", - "role": "None established", - "sanAnalyticsCapable": false, - "scope": null, - "secondaryIP": "", - "secondarySwitchDbID": 0, - "sendIntf": "mgmt0", - "serialNumber": "FDOXXXXXXXX", - "standbySupState": 0, - "status": "ok", - "swWwn": null, - "swWwnName": "FDOXXXXXXXX", - "switchDbID": 575610, - "switchRole": "leaf", - "switchRoleEnum": "Leaf", - "sysDescr": "", - "systemMode": null, - "uid": 0, - "unmanagableCause": "", - "upTime": 163814317, - "upTimeNumber": 0, - "upTimeStr": "18 days, 23:02:23", - "usedPorts": 0, - "username": null, - "vdcId": -1, - "vdcMac": null, - "vdcName": "", - "vendor": "Cisco", - "version": null, - "vpcDomain": 1, - "vrf": "management", - "vsanWwn": null, - "vsanWwnName": null, - "wwn": null - } -} diff --git a/roles/ndfc_device_query/tasks/main.yml b/roles/ndfc_device_query/tasks/main.yml deleted file mode 100644 index d31bb86..0000000 --- a/roles/ndfc_device_query/tasks/main.yml +++ /dev/null @@ -1,8 +0,0 @@ -# ndfc_device_query/tasks/main.yml ---- -- name: main query FABRIC {{ fabric_name }} DEVICE {{ device_name }} - include_tasks: worker.yml - loop: "{{ mr1 }}" - vars: - mq1: "[?name == '{{ device_name }}'] | [?fabric == '{{ fabric_name }}']" - mr1: "{{ leafs | json_query(mq1) + spines | json_query(mq1) + border_gateways | json_query(mq1) }}" diff --git a/roles/ndfc_device_query/tasks/worker.yml b/roles/ndfc_device_query/tasks/worker.yml deleted file mode 100644 index 579442c..0000000 --- a/roles/ndfc_device_query/tasks/worker.yml +++ /dev/null @@ -1,22 +0,0 @@ -# ndfc_device_query/tasks/worker.yml -- name: worker query FABRIC {{ item.fabric }} NAME {{ item.name }} IP {{ item.ip }} - cisco.dcnm.dcnm_inventory: - fabric: "{{ item.fabric }}" - state: query - config: - - seed_ip: "{{ item.ip }}" - register: wr1 - -# playbooks can cull information from device_info -- name: worker set_fact device_info - set_fact: - device_info: "{{ wr1.response | json_query(wq1) }}" - vars: - wq1: "[0]" - -# Device serial number -- name: worker set_fact serial - set_fact: - serial: "{{ wr1.response | json_query(wq2) }}" - vars: - wq2: "[0].serialNumber" diff --git a/roles/ndfc_device_query_all/tasks/main.yml b/roles/ndfc_device_query_all/tasks/main.yml deleted file mode 100644 index 6006460..0000000 --- a/roles/ndfc_device_query_all/tasks/main.yml +++ /dev/null @@ -1,8 +0,0 @@ -# ndfc_device_query_all/tasks/main.yml ---- -- name: main query FABRIC {{ fabric_name }} - include_tasks: worker.yml - loop: "{{ mr1 }}" - vars: - mq1: "[?fabric == '{{ fabric_name }}']" - mr1: "{{ leafs | json_query(mq1) + spines | json_query(mq1) + border_gateways | json_query(mq1) }}" diff --git a/roles/ndfc_device_query_all/tasks/worker.yml b/roles/ndfc_device_query_all/tasks/worker.yml deleted file mode 100644 index d9429f5..0000000 --- a/roles/ndfc_device_query_all/tasks/worker.yml +++ /dev/null @@ -1,24 +0,0 @@ -# ndfc_device_query_all/tasks/worker.yml -- name: worker query FABRIC {{ item.fabric }} NAME {{ item.name }} IP {{ item.ip }} - cisco.dcnm.dcnm_inventory: - fabric: "{{ item.fabric }}" - state: query - config: - - seed_ip: "{{ item.ip }}" - register: wr1 - -- name: worker set_fact serial - set_fact: - serial: "{{ wr1.response | json_query(wq1) }}" - vars: - wq1: "[0].serialNumber" - -- debug: - msg: "uptime: {{ wr1.response[0].upTime }} - {{ item.fabric }} {{ item.name }} {{ item.ip }}" - when: "serial != ''" -- debug: - msg: "serial: {{ wr1.response[0].serialNumber }} - {{ item.fabric }} {{ item.name }} {{ item.ip }}" - when: "serial != ''" -- debug: - msg: "version: {{ wr1.response[0].release }} - {{ item.fabric }} {{ item.name }} {{ item.ip }}" - when: "serial != ''" diff --git a/roles/ndfc_device_serial_number_get/README.md b/roles/ndfc_device_serial_number_get/README.md index 0a4ed9e..0f24cf9 100644 --- a/roles/ndfc_device_serial_number_get/README.md +++ b/roles/ndfc_device_serial_number_get/README.md @@ -1,6 +1,6 @@ # ndfc_device_serial_number_get -Return ``device_serial_number`` given ``device_name`` and fabric ``fabric_name``. +Return ``device_serial_number`` given ``device_name``. The device's serial number is returned in variable ``device_serial_number``. @@ -9,9 +9,8 @@ The device's serial number is returned in variable ``device_serial_number``. Variable | Type | Description ----------------|-------|---------------------------------------- device_name | str() | The device to be queried -fabric_name | str() | The fabric in which device_name resides -Device and Fabric names are defined in the following file: +Device names are defined in the following file: ``./roles/ndfc_common/vars/main.yml``) @@ -30,7 +29,6 @@ See the following for details: roles: - ndfc_device_serial_get vars: - fabric_name: f2 device_name: leaf_1 tasks: - block: diff --git a/roles/ndfc_device_serial_number_get/tasks/main.yml b/roles/ndfc_device_serial_number_get/tasks/main.yml index 28678ea..ce3320f 100644 --- a/roles/ndfc_device_serial_number_get/tasks/main.yml +++ b/roles/ndfc_device_serial_number_get/tasks/main.yml @@ -1,11 +1,21 @@ -# ndfc_device_serial_number_get/tasks/main.yml -# Return device_serial_number,given fabric_name and device_name ---- -- name: main device_serial_number_get FABRIC {{ fabric_name }} DEVICE {{ device_name }} - include_tasks: worker.yml - loop: "{{ mr1 }}" - loop_control: - loop_var: device +#ndfc_device_serial_number_get/tasks/main.yml + +- ansible.builtin.include_role: + name: ndfc_device_config_get + +- name: worker device_serial_number_get FABRIC {{ device_config.switch_fabric }} NAME {{ device_config.name }} IP {{ device_config.ip }} + cisco.dcnm.dcnm_inventory: + fabric: "{{ device_config.switch_fabric }}" + state: query + config: + - seed_ip: "{{ device_config.ip }}" + register: r1 vars: - mq1: "[?name == '{{ device_name }}'] | [?fabric == '{{ fabric_name }}']" - mr1: "{{ leafs | json_query(mq1) + spines | json_query(mq1) + border_gateways | json_query(mq1) }}" + ansible_connection: httpapi + +# Device serial number +- name: worker set_fact device_serial_number + ansible.builtin.set_fact: + device_serial_number: "{{ r1.response | json_query(q1) }}" + vars: + q1: "[0].serialNumber" diff --git a/roles/ndfc_device_serial_number_get/tasks/worker.yml b/roles/ndfc_device_serial_number_get/tasks/worker.yml deleted file mode 100644 index 7592094..0000000 --- a/roles/ndfc_device_serial_number_get/tasks/worker.yml +++ /dev/null @@ -1,15 +0,0 @@ -# ndfc_device_serial_number_get/tasks/worker.yml -- name: worker device_serial_number_get FABRIC {{ device.fabric }} NAME {{ device.name }} IP {{ device.ip }} - cisco.dcnm.dcnm_inventory: - fabric: "{{ device.fabric }}" - state: query - config: - - seed_ip: "{{ device.ip }}" - register: wr1 - -# Device serial number -- name: worker set_fact device_serial_number - set_fact: - device_serial_number: "{{ wr1.response | json_query(wq2) }}" - vars: - wq2: "[0].serialNumber" diff --git a/roles/ndfc_fabric_active_fabrics_get/README.md b/roles/ndfc_fabric_active_fabrics_get/README.md new file mode 100644 index 0000000..ac4d7b0 --- /dev/null +++ b/roles/ndfc_fabric_active_fabrics_get/README.md @@ -0,0 +1,42 @@ +# ndfc_device_deleted + +Delete device ``device_name`` from fabric ``fabric_name`` using ``cisco.dcnm.dcnm_inventory`` + +### Role Variables + +Variable | Type | Description +----------------|-------|---------------------------------------- +device_name | str() | The device to be deleted +fabric_name | str() | The fabric in which device_name resides + +Device and fabric names are defined in the following file: + +``./roles/ndfc_common/vars/main.yml``) + +See the following for details: + +[./roles/ndfc_common/README.md](https://github.com/allenrobel/ndfc-roles/tree/master/roles/ndfc_common/README.md) + + +### Example Playbook + +```yaml +--- +- hosts: ndfc + gather_facts: false + roles: + - ndfc_device_deleted + vars: + fabric_name: f1 + device_name: spine_1 +``` + +### Licensing + +GNU General Public License v3.0 or later. + +See [LICENSE](https://www.gnu.org/licenses/gpl-3.0.txt) for full text. + +### Author Information + +Allen Robel (@packetcalc) diff --git a/roles/ndfc_device_query_all/meta/main.yml b/roles/ndfc_fabric_active_fabrics_get/meta/main.yml similarity index 100% rename from roles/ndfc_device_query_all/meta/main.yml rename to roles/ndfc_fabric_active_fabrics_get/meta/main.yml diff --git a/roles/ndfc_fabric_active_fabrics_get/tasks/main.yml b/roles/ndfc_fabric_active_fabrics_get/tasks/main.yml new file mode 100644 index 0000000..ded5c7d --- /dev/null +++ b/roles/ndfc_fabric_active_fabrics_get/tasks/main.yml @@ -0,0 +1,23 @@ +# roles/ndfc_fabric_active_fabrics_get/tasks/main.yml +--- +- name: main REST GET fabrics + cisco.dcnm.dcnm_rest: + method: GET + path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics" + register: mr1 + vars: + ansible_connection: httpapi + ansible_httpapi_use_ssl: 'yes' + ansible_httpapi_validate_certs: 'no' + ansible_httpapi_port: 443 + +- name: main set_fact active_fabrics + set_fact: + active_fabrics: "{{ mr1.response.DATA | json_query(mq1) | to_json }}" + vars: + mq1: "[*].{FabricName: fabricName}" + +- name: debug active_fabrics + debug: + var: active_fabrics + diff --git a/roles/ndfc_fabric_active_fabrics_get/vars/main.yml b/roles/ndfc_fabric_active_fabrics_get/vars/main.yml new file mode 100644 index 0000000..aff8e49 --- /dev/null +++ b/roles/ndfc_fabric_active_fabrics_get/vars/main.yml @@ -0,0 +1 @@ +ansible_connection: httpapi diff --git a/roles/ndfc_device_query_all/README.md b/roles/ndfc_fabric_config_get/README.md similarity index 70% rename from roles/ndfc_device_query_all/README.md rename to roles/ndfc_fabric_config_get/README.md index 8d75f7e..49dff62 100644 --- a/roles/ndfc_device_query_all/README.md +++ b/roles/ndfc_fabric_config_get/README.md @@ -1,12 +1,16 @@ -# ndfc_device_query_all +# ndfc_fabric_config_get -Query all devices in fabric ``fabric_name`` +Retrieve config for ``fabric_name`` from the following sections of ``./roles/ndfc_common/vars/main.yml`` + +- msd_fabrics +- switch_fabrics +- external fabrics ### Role Variables Variable | Type | Description ----------------|-------|---------------------------------------- -fabric_name | str() | The fabric in which the devices reside +fabric_name | str() | The fabric configuration to retrieve Fabric names are defined in the following file: @@ -20,12 +24,11 @@ See the following for details: ### Example Playbook ```yaml -# Query all NX-OS switches in fabric_name --- - hosts: ndfc gather_facts: false roles: - - ndfc_device_query_all + - ndfc_fabric_config_get vars: fabric_name: f1 ``` diff --git a/roles/ndfc_policy_vrf_rt_import/meta/main.yml b/roles/ndfc_fabric_config_get/meta/main.yml similarity index 100% rename from roles/ndfc_policy_vrf_rt_import/meta/main.yml rename to roles/ndfc_fabric_config_get/meta/main.yml diff --git a/roles/ndfc_fabric_config_get/tasks/main.yml b/roles/ndfc_fabric_config_get/tasks/main.yml new file mode 100644 index 0000000..b9b4d9a --- /dev/null +++ b/roles/ndfc_fabric_config_get/tasks/main.yml @@ -0,0 +1,11 @@ +# roles/ndfc_fabric_config_get/tasks/main.yml +--- +- name: set_fact all_fabrics + ansible.builtin.set_fact: + all_fabrics: "{{ msd_fabrics | combine(switch_fabrics, external_fabrics) }}" + +- name: set_fact fabric_config {{ fabric_name }} + ansible.builtin.set_fact: + fabric_config: "{{ all_fabrics | json_query(mq1) }}" + vars: + mq1: "{{ fabric_name }}" diff --git a/roles/ndfc_fabric_config_get/vars/main.yml b/roles/ndfc_fabric_config_get/vars/main.yml new file mode 100644 index 0000000..f2bcdf0 --- /dev/null +++ b/roles/ndfc_fabric_config_get/vars/main.yml @@ -0,0 +1 @@ +ansible_connection: local diff --git a/roles/ndfc_network_config_get/README.md b/roles/ndfc_network_config_get/README.md new file mode 100644 index 0000000..1f9e31b --- /dev/null +++ b/roles/ndfc_network_config_get/README.md @@ -0,0 +1,40 @@ +# ndfc_network_config_get + +Retrieve config for ``network_name`` from the ``networks`` portion of ``./roles/ndfc_common/vars/main.yml`` + +### Role Variables + +Variable | Type | Description +----------------|-------|---------------------------------------- +network_name | str() | The network to be retrieved + +network names are defined in the following file: + +``./roles/ndfc_common/vars/main.yml`` + +See the following for details: + +[./roles/ndfc_common/README.md](https://github.com/allenrobel/ndfc-roles/tree/master/roles/ndfc_common/README.md) + + +### Example Playbook + +```yaml +--- +- hosts: ndfc + gather_facts: false + roles: + - ndfc_network_config_get + vars: + network_name: f1_n1111 +``` + +### Licensing + +GNU General Public License v3.0 or later. + +See [LICENSE](https://www.gnu.org/licenses/gpl-3.0.txt) for full text. + +### Author Information + +Allen Robel (@packetcalc) diff --git a/roles/ndfc_policy_vrf_rt_import_loop/meta/main.yml b/roles/ndfc_network_config_get/meta/main.yml similarity index 100% rename from roles/ndfc_policy_vrf_rt_import_loop/meta/main.yml rename to roles/ndfc_network_config_get/meta/main.yml diff --git a/roles/ndfc_network_config_get/tasks/main.yml b/roles/ndfc_network_config_get/tasks/main.yml new file mode 100644 index 0000000..ca7cc87 --- /dev/null +++ b/roles/ndfc_network_config_get/tasks/main.yml @@ -0,0 +1,7 @@ +# roles/ndfc_network_config_get/tasks/main.yml +--- +- name: set_fact network_config {{ network_name }} + ansible.builtin.set_fact: + network_config: "{{ networks | json_query(mq1) }}" + vars: + mq1: "{{ network_name }}" diff --git a/roles/ndfc_network_config_get/vars/main.yml b/roles/ndfc_network_config_get/vars/main.yml new file mode 100644 index 0000000..f2bcdf0 --- /dev/null +++ b/roles/ndfc_network_config_get/vars/main.yml @@ -0,0 +1 @@ +ansible_connection: local diff --git a/roles/ndfc_network_deleted/README.md b/roles/ndfc_network_deleted/README.md index cbc4a7a..7bda3cf 100644 --- a/roles/ndfc_network_deleted/README.md +++ b/roles/ndfc_network_deleted/README.md @@ -1,15 +1,14 @@ # ndfc_network_deleted -Delete network ``network_name`` from fabric ``fabric_name`` using ``cisco.dcnm.dcnm_network`` +Delete network ``network_name`` where ``network_name`` matches the ``name`` key in the ``networks`` dictionary in ``roles/ndfc_common/vars/main.yml`` ### Role Variables Variable | Type | Description ----------------|-------|---------------------------------------- network_name | str() | The network to be deleted -fabric_name | str() | The fabric in which ``network_name`` resides. If ``network_name`` resides in a child fabric to an msd_fabric, then ``fabric_name`` must be that of the msd_fabric. -Network and fabric names are defined in the following file: +Network names are defined in the following file: ``./roles/ndfc_common/vars/main.yml``) @@ -20,7 +19,7 @@ See the following for details: ### Example Playbooks -# Delete network_name n1111 from fabric_name f1. +# Delete network_name f1_n1111 ```yaml --- @@ -29,13 +28,12 @@ See the following for details: roles: - ndfc_network_deleted vars: - fabric_name: f1 - network_name: n1111 + network_name: f1_n1111 ``` -# Delete network_name n1111 from fabric_name f1, which is a child of msd_fabric MSD. +# Delete network_name msd_n1111, which resides in fabric MSD (an msd fabric) -This will delete network_name n1111 from ALL child fabrics of msd_fabric MSD. +This will delete network_name msd_n1111 from ALL child fabrics of fabric MSD. ```yaml --- @@ -44,8 +42,7 @@ This will delete network_name n1111 from ALL child fabrics of msd_fabric MSD. roles: - ndfc_network_deleted vars: - fabric_name: MSD - network_name: n1111 + network_name: msd_n1111 ``` ### License diff --git a/roles/ndfc_network_deleted/tasks/main.yml b/roles/ndfc_network_deleted/tasks/main.yml index 48ec407..2acadbc 100644 --- a/roles/ndfc_network_deleted/tasks/main.yml +++ b/roles/ndfc_network_deleted/tasks/main.yml @@ -1,10 +1,36 @@ -# ndfc_network_deleted/tasks/main.yml --- -- name: main deleted FABRIC {{ fabric_name }} NETWORK {{ network_name }} - include_tasks: worker.yml - loop: "{{ mr1 }}" - loop_control: - loop_var: dn + +- ansible.builtin.include_role: + name: ndfc_network_config_get +- name: debug network_config + debug: + var: network_config + +- ansible.builtin.include_role: + name: ndfc_network_info_get vars: - mq1: "[?net_name == '{{ network_name }}'] | [?fabric == '{{ fabric_name }}']" - mr1: "{{ networks | json_query(mq1) }}" + fabric_name: "{{ network_config.fabric }}" + network_name: "{{ network_config.net_name }}" + +# We set wf1 to '' so that we can skip the last task below if it's still equal to '' +- name: set fact wf1 temp + set_fact: + wf1: '' + +- name: worker set_fact wf1 networkName + set_fact: + wf1: "{{ network_info | json_query(wq1) | default('', true) }}" + vars: + wq1: "networkName" + when: "network_info != ''" + +- name: worker deleted FABRIC {{ network_config.fabric }} NETWORK {{ network_config.net_name }} networkName ({{ wf1 }}) + cisco.dcnm.dcnm_network: + fabric: "{{ network_config.fabric }}" + state: deleted + config: + - net_name: "{{ network_config.net_name }}" + when: "wf1 == network_config.net_name" + vars: + ansible_connection: httpapi + diff --git a/roles/ndfc_network_deleted/tasks/worker.yml b/roles/ndfc_network_deleted/tasks/worker.yml deleted file mode 100644 index f3490fe..0000000 --- a/roles/ndfc_network_deleted/tasks/worker.yml +++ /dev/null @@ -1,26 +0,0 @@ ---- -- ansible.builtin.include_role: - name: ndfc_network_info_get - vars: - fabric_name: "{{ dn.fabric }}" - network_name: "{{ dn.net_name }}" - -# We set wf1 to '' so that we can skip the last task below if it's still equal to '' -- name: set fact wf1 temp - set_fact: - wf1: '' - -- name: worker set_fact wf1 networkName - set_fact: - wf1: "{{ network_info | json_query(wq1) | default('', true) }}" - vars: - wq1: "networkName" - when: "network_info != ''" - -- name: worker deleted FABRIC {{ dn.fabric }} NETWORK {{ dn.net_name }} networkName ({{ wf1 }}) - cisco.dcnm.dcnm_network: - fabric: "{{ dn.fabric }}" - state: deleted - config: - - net_name: "{{ dn.net_name }}" - when: "wf1 == network_name" diff --git a/roles/ndfc_network_deleted_all/tasks/main.yml b/roles/ndfc_network_deleted_all/tasks/main.yml deleted file mode 100644 index 82ed425..0000000 --- a/roles/ndfc_network_deleted_all/tasks/main.yml +++ /dev/null @@ -1,7 +0,0 @@ -# ndfc_network_deleted_all/tasks/main.yml ---- -- name: main deleted FABRIC {{ fabric_name }} networks - include_tasks: worker.yml - loop: "{{ networks | json_query(mq1) }}" - vars: - mq1: "[?fabric == '{{ fabric_name }}']" diff --git a/roles/ndfc_network_deleted_all/tasks/worker.yml b/roles/ndfc_network_deleted_all/tasks/worker.yml deleted file mode 100644 index a0971c6..0000000 --- a/roles/ndfc_network_deleted_all/tasks/worker.yml +++ /dev/null @@ -1,20 +0,0 @@ -# ndfc_network_deleted_all/tasks/worker.yml -# - name: main REST GET fabrics -# cisco.dcnm.dcnm_rest: -# method: GET -# path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics" -# register: mr1 - -# - name: main set_fact active_fabrics -# set_fact: -# active_fabrics: "{{ mr1.response.DATA | json_query(mq1) | to_json }}" -# vars: -# mq1: "[*].{FabricName: fabricName}" - -- name: worker deleted FABRIC {{ fabric_name }} NETWORK {{ item.net_name }} VRF {{ item.vrf_name }} VLAN {{ item.vlan_id }} SUBNET {{ item.gw_ip_subnet }} - cisco.dcnm.dcnm_network: - fabric: "{{ fabric_name }}" - state: deleted - config: - - net_name: "{{ item.net_name }}" - #when: "fabric_name in active_fabrics" diff --git a/roles/ndfc_network_deleted_external_fabric_all/README.md b/roles/ndfc_network_deleted_external_fabric_all/README.md new file mode 100644 index 0000000..4968d7c --- /dev/null +++ b/roles/ndfc_network_deleted_external_fabric_all/README.md @@ -0,0 +1,47 @@ +# ndfc_network_deleted_external_fabric_all + +Delete all networks in external fabric ``fabric_name`` + +NOTE: If the networks were created in an msd or switch fabric, use their corresponding roles instead + +SEE ALSO: ndfc_network_deleted_msd_fabric_all +SEE ALSO: ndfc_network_deleted_switch_fabric_all + +### Role Variables + +Variable | Type | Description +----------------|-------|---------------------------------------- +fabric_name | str() | The external fabric from which to delete all networks. + +Fabric parameters, including ``fabric_name`, are defined in the following file: + +``./roles/ndfc_common/vars/main.yml``) + +See the following for details: + +[./roles/ndfc_common/README.md](https://github.com/allenrobel/ndfc-roles/tree/master/roles/ndfc_common/README.md) + + +### Example Playbooks + +# Delete all networks in external fabric_name f1 + +```yaml +--- +- hosts: ndfc + gather_facts: false + roles: + - ndfc_network_deleted_external_fabric_all + vars: + fabric_name: f1 +``` + +### Licensing + +GNU General Public License v3.0 or later. + +See [LICENSE](https://www.gnu.org/licenses/gpl-3.0.txt) for full text. + +### Author Information + +Allen Robel (@packetcalc) diff --git a/roles/ndfc_network_deleted_all/meta/main.yml b/roles/ndfc_network_deleted_external_fabric_all/meta/main.yml similarity index 100% rename from roles/ndfc_network_deleted_all/meta/main.yml rename to roles/ndfc_network_deleted_external_fabric_all/meta/main.yml diff --git a/roles/ndfc_network_deleted_external_fabric_all/tasks/main.yml b/roles/ndfc_network_deleted_external_fabric_all/tasks/main.yml new file mode 100644 index 0000000..c61f515 --- /dev/null +++ b/roles/ndfc_network_deleted_external_fabric_all/tasks/main.yml @@ -0,0 +1,19 @@ +# ndfc_network_deleted_external_all/tasks/main.yml +--- +- name: main REST GET fabrics + cisco.dcnm.dcnm_rest: + method: GET + path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics" + register: mr1 + vars: + ansible_connection: httpapi + +- name: main set_fact active_fabrics + set_fact: + active_fabrics: "{{ mr1.response.DATA | json_query(mq1) | to_json }}" + vars: + mq1: "[*].{FabricName: fabricName}" + +- name: main deleted networks + include_tasks: worker.yml + loop: "{{ networks.values() | list }}" diff --git a/roles/ndfc_network_deleted_external_fabric_all/tasks/worker.yml b/roles/ndfc_network_deleted_external_fabric_all/tasks/worker.yml new file mode 100644 index 0000000..27155c2 --- /dev/null +++ b/roles/ndfc_network_deleted_external_fabric_all/tasks/worker.yml @@ -0,0 +1,16 @@ +# ndfc_network_deleted_external_all/tasks/worker.yml +- ansible.builtin.include_role: + name: ndfc_fabric_config_get + vars: + ansible_connection: local + fabric_name: "{{ item.fabric }}" + +- name: worker deleted FABRIC {{ item.fabric }} NETWORK {{ item.net_name }} VRF {{ item.vrf_name }} VLAN {{ item.vlan_id }} SUBNET {{ item.gw_ip_subnet }} + cisco.dcnm.dcnm_network: + fabric: "{{ item.fabric }}" + state: deleted + config: + - net_name: "{{ item.net_name }}" + when: "item.fabric in active_fabrics and fabric_config.type == 'external'" + vars: + ansible_connection: httpapi diff --git a/roles/ndfc_network_deleted_all/README.md b/roles/ndfc_network_deleted_msd_fabric_all/README.md similarity index 53% rename from roles/ndfc_network_deleted_all/README.md rename to roles/ndfc_network_deleted_msd_fabric_all/README.md index 213e013..3990c7e 100644 --- a/roles/ndfc_network_deleted_all/README.md +++ b/roles/ndfc_network_deleted_msd_fabric_all/README.md @@ -1,12 +1,17 @@ -# ndfc_network_deleted_all +# ndfc_network_deleted_msd_fabric_all -Delete all networks in fabric ``fabric_name`` +Delete all networks in MSD fabric ``fabric_name`` + +NOTE: If the networks were created in an external or switch fabric, use their corresponding roles instead + +SEE ALSO: ndfc_network_deleted_external_fabric_all +SEE ALSO: ndfc_network_deleted_switch_fabric_all ### Role Variables Variable | Type | Description ----------------|-------|---------------------------------------- -fabric_name | str() | The fabric from which to delete all networks. If ``fabric_name`` is a child fabric of an msd_fabric, then ``fabric_name`` must be that of the msd_fabric. +fabric_name | str() | The msd fabric from which to delete all networks. Fabric parameters, including ``fabric_name`, are defined in the following file: @@ -19,27 +24,14 @@ See the following for details: ### Example Playbooks -# Delete all networks in fabric_name f1 - -```yaml ---- -- hosts: ndfc - gather_facts: false - roles: - - ndfc_network_deleted_all - vars: - fabric_name: f1 -``` - -# Delete all networks in fabric_name f1, which is a child of msd_fabric MSD -# This will delete all networks in all child fabrics of msd_fabric MSD. +# Delete all networks in msd fabric_name MSD ```yaml --- - hosts: ndfc gather_facts: false roles: - - ndfc_network_deleted_all + - ndfc_network_deleted_msd_fabric_all vars: fabric_name: MSD ``` diff --git a/roles/ndfc_network_deleted_msd_fabric_all/meta/main.yml b/roles/ndfc_network_deleted_msd_fabric_all/meta/main.yml new file mode 100644 index 0000000..6208027 --- /dev/null +++ b/roles/ndfc_network_deleted_msd_fabric_all/meta/main.yml @@ -0,0 +1,11 @@ +galaxy_info: + author: Allen Robel + description: NDFC deploy configuration + company: Cisco Systems, Inc. + license: license (GPL-2.0-or-later, MIT, etc) + min_ansible_version: 2.1 + galaxy_tags: + - ndfc + - cisco +dependencies: + - ndfc_common diff --git a/roles/ndfc_network_deleted_msd_fabric_all/tasks/main.yml b/roles/ndfc_network_deleted_msd_fabric_all/tasks/main.yml new file mode 100644 index 0000000..4004f6c --- /dev/null +++ b/roles/ndfc_network_deleted_msd_fabric_all/tasks/main.yml @@ -0,0 +1,23 @@ +# ndfc_network_deleted_msd_all/tasks/main.yml +--- +- name: main REST GET fabrics + cisco.dcnm.dcnm_rest: + method: GET + path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics" + register: mr1 + vars: + ansible_connection: httpapi + +- name: debug mr1 + debug: + var: mr1 + +- name: main set_fact active_fabrics + set_fact: + active_fabrics: "{{ mr1.response.DATA | json_query(mq1) | to_json }}" + vars: + mq1: "[*].{FabricName: fabricName}" + +- name: main deleted networks + include_tasks: worker.yml + loop: "{{ networks.values() | list }}" diff --git a/roles/ndfc_network_deleted_msd_fabric_all/tasks/worker.yml b/roles/ndfc_network_deleted_msd_fabric_all/tasks/worker.yml new file mode 100644 index 0000000..e949e8e --- /dev/null +++ b/roles/ndfc_network_deleted_msd_fabric_all/tasks/worker.yml @@ -0,0 +1,16 @@ +# ndfc_network_deleted_msd_all/tasks/worker.yml +- ansible.builtin.include_role: + name: ndfc_fabric_config_get + vars: + ansible_connection: local + fabric_name: "{{ item.fabric }}" + +- name: worker deleted FABRIC {{ item.fabric }} NETWORK {{ item.net_name }} VRF {{ item.vrf_name }} VLAN {{ item.vlan_id }} SUBNET {{ item.gw_ip_subnet }} + cisco.dcnm.dcnm_network: + fabric: "{{ item.fabric }}" + state: deleted + config: + - net_name: "{{ item.net_name }}" + when: "item.fabric in active_fabrics and fabric_config.type == 'msd'" + vars: + ansible_connection: httpapi diff --git a/roles/ndfc_network_deleted_switch_fabric_all/README.md b/roles/ndfc_network_deleted_switch_fabric_all/README.md new file mode 100644 index 0000000..43146b3 --- /dev/null +++ b/roles/ndfc_network_deleted_switch_fabric_all/README.md @@ -0,0 +1,47 @@ +# ndfc_network_deleted_switch_fabric_all + +Delete all networks in switch fabric ``fabric_name`` + +NOTE: If the networks were created in an external or msd fabric, use their corresponding roles instead + +SEE ALSO: ndfc_network_deleted_external_fabric_all +SEE ALSO: ndfc_network_deleted_msd_fabric_all + +### Role Variables + +Variable | Type | Description +----------------|-------|---------------------------------------- +fabric_name | str() | The switch fabric from which to delete all networks. + +Fabric parameters, including ``fabric_name`, are defined in the following file: + +``./roles/ndfc_common/vars/main.yml``) + +See the following for details: + +[./roles/ndfc_common/README.md](https://github.com/allenrobel/ndfc-roles/tree/master/roles/ndfc_common/README.md) + + +### Example Playbooks + +# Delete all networks in switch fabric_name f1 + +```yaml +--- +- hosts: ndfc + gather_facts: false + roles: + - ndfc_network_deleted_switch_fabric_all + vars: + fabric_name: f1 +``` + +### Licensing + +GNU General Public License v3.0 or later. + +See [LICENSE](https://www.gnu.org/licenses/gpl-3.0.txt) for full text. + +### Author Information + +Allen Robel (@packetcalc) diff --git a/roles/ndfc_network_deleted_switch_fabric_all/meta/main.yml b/roles/ndfc_network_deleted_switch_fabric_all/meta/main.yml new file mode 100644 index 0000000..6208027 --- /dev/null +++ b/roles/ndfc_network_deleted_switch_fabric_all/meta/main.yml @@ -0,0 +1,11 @@ +galaxy_info: + author: Allen Robel + description: NDFC deploy configuration + company: Cisco Systems, Inc. + license: license (GPL-2.0-or-later, MIT, etc) + min_ansible_version: 2.1 + galaxy_tags: + - ndfc + - cisco +dependencies: + - ndfc_common diff --git a/roles/ndfc_network_deleted_switch_fabric_all/tasks/main.yml b/roles/ndfc_network_deleted_switch_fabric_all/tasks/main.yml new file mode 100644 index 0000000..9a24f9d --- /dev/null +++ b/roles/ndfc_network_deleted_switch_fabric_all/tasks/main.yml @@ -0,0 +1,19 @@ +# ndfc_network_deleted_switch_all/tasks/main.yml +--- +- name: main REST GET fabrics + cisco.dcnm.dcnm_rest: + method: GET + path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics" + register: mr1 + vars: + ansible_connection: httpapi + +- name: main set_fact active_fabrics + set_fact: + active_fabrics: "{{ mr1.response.DATA | json_query(mq1) | to_json }}" + vars: + mq1: "[*].{FabricName: fabricName}" + +- name: main deleted networks + include_tasks: worker.yml + loop: "{{ networks.values() | list }}" diff --git a/roles/ndfc_network_deleted_switch_fabric_all/tasks/worker.yml b/roles/ndfc_network_deleted_switch_fabric_all/tasks/worker.yml new file mode 100644 index 0000000..2e34e06 --- /dev/null +++ b/roles/ndfc_network_deleted_switch_fabric_all/tasks/worker.yml @@ -0,0 +1,16 @@ +# ndfc_network_deleted_switch_all/tasks/worker.yml +- ansible.builtin.include_role: + name: ndfc_fabric_config_get + vars: + ansible_connection: local + fabric_name: "{{ item.fabric }}" + +- name: worker deleted FABRIC {{ item.fabric }} NETWORK {{ item.net_name }} VRF {{ item.vrf_name }} VLAN {{ item.vlan_id }} SUBNET {{ item.gw_ip_subnet }} + cisco.dcnm.dcnm_network: + fabric: "{{ item.fabric }}" + state: deleted + config: + - net_name: "{{ item.net_name }}" + when: "item.fabric in active_fabrics and fabric_config.type == 'switch'" + vars: + ansible_connection: httpapi diff --git a/roles/ndfc_network_info_get/tasks/main.yml b/roles/ndfc_network_info_get/tasks/main.yml index 830d2e6..3ceca47 100644 --- a/roles/ndfc_network_info_get/tasks/main.yml +++ b/roles/ndfc_network_info_get/tasks/main.yml @@ -1,9 +1,36 @@ -# ndfc_network_info_get/tasks/main.yml +# roles/ndfc_network_info_get/tasks/main.yml --- -- name: main network_info_get FABRIC {{ fabric_name }} NETWORK {{ network_name }} - include_tasks: worker.yml - loop: "{{ mr2 }}" +- ansible.builtin.include_role: + name: ndfc_network_config_get vars: - mq2: "[?net_name == '{{ network_name }}'] | [?fabric == '{{ fabric_name }}']" - mr2: "{{ networks | json_query(mq2) }}" + ansible_connection: local + when: network_config == '' +- name: network_info_get debug network_config + debug: + var: network_config + +- name: worker query network_name {{ network_config.name }} FABRIC {{ network_config.fabric }} NETWORK {{ network_config.net_name }} + cisco.dcnm.dcnm_network: + fabric: "{{ network_config.fabric }}" + state: query + config: + - net_name: "{{ network_config.net_name }}" + register: wr1 + vars: + ansible_connection: httpapi + # when: "item.net_name is not none" + +- name: worker set_fact network_info + set_fact: + network_info: "{{ wr1.response | json_query(wq1) | default('', true) }}" + vars: + wq1: "[0].parent" + # when: "item.net_name is not none" + +# - name: worker set_fact network_info null +# set_fact: +# network_info: "{{ wr1.response | json_query(wq1) }}" +# vars: +# wq1: "[0].parent" +# when: "item.net_name is none" diff --git a/roles/ndfc_network_info_get/tasks/worker.yml b/roles/ndfc_network_info_get/tasks/worker.yml deleted file mode 100644 index de6896e..0000000 --- a/roles/ndfc_network_info_get/tasks/worker.yml +++ /dev/null @@ -1,23 +0,0 @@ ---- -- name: worker query FABRIC {{ item.fabric }} NETWORK {{ item.net_name }} - cisco.dcnm.dcnm_network: - fabric: "{{ fabric_name }}" - state: query - config: - - net_name: "{{ item.net_name }}" - register: wr1 - # when: "item.net_name is not none" - -- name: worker set_fact network_info - set_fact: - network_info: "{{ wr1.response | json_query(wq1) | default('', true) }}" - vars: - wq1: "[0].parent" - # when: "item.net_name is not none" - -# - name: worker set_fact network_info null -# set_fact: -# network_info: "{{ wr1.response | json_query(wq1) }}" -# vars: -# wq1: "[0].parent" -# when: "item.net_name is none" diff --git a/roles/ndfc_network_replaced/README.md b/roles/ndfc_network_replaced/README.md new file mode 100644 index 0000000..1b1f6d2 --- /dev/null +++ b/roles/ndfc_network_replaced/README.md @@ -0,0 +1,40 @@ +# ndfc_network_replaced + +Replace network ``network_name`` with its current definitions in ``./roles/ndfc_common/vars/main.yml`` + +### Role Variables + +Variable | Type | Description +----------------|-------|---------------------------------------- +network_name | str() | The network to be replaced + +Network parameters, including ``network_name`, are defined in the following file: + +``./roles/ndfc_common/vars/main.yml`` + +See the following for details: + +[./roles/ndfc_common/README.md](https://github.com/allenrobel/ndfc-roles/tree/master/roles/ndfc_common/README.md) + + +### Example Playbook + +```yaml +--- +- hosts: ndfc + gather_facts: false + roles: + - ndfc_network_replaced + vars: + network_name: f1_n1111 +``` + +### Licensing + +GNU General Public License v3.0 or later. + +See [LICENSE](https://www.gnu.org/licenses/gpl-3.0.txt) for full text. + +### Author Information + +Allen Robel (@packetcalc) diff --git a/roles/ndfc_network_replaced/meta/main.yml b/roles/ndfc_network_replaced/meta/main.yml new file mode 100644 index 0000000..6208027 --- /dev/null +++ b/roles/ndfc_network_replaced/meta/main.yml @@ -0,0 +1,11 @@ +galaxy_info: + author: Allen Robel + description: NDFC deploy configuration + company: Cisco Systems, Inc. + license: license (GPL-2.0-or-later, MIT, etc) + min_ansible_version: 2.1 + galaxy_tags: + - ndfc + - cisco +dependencies: + - ndfc_common diff --git a/roles/ndfc_network_replaced/tasks/main.yml b/roles/ndfc_network_replaced/tasks/main.yml new file mode 100644 index 0000000..91eff69 --- /dev/null +++ b/roles/ndfc_network_replaced/tasks/main.yml @@ -0,0 +1,14 @@ +# ndfc_network_replaced/tasks/main.yml +- ansible.builtin.include_role: + name: ndfc_network_config_get + +- name: worker replaced FABRIC {{ network_config.fabric }} NETWORK {{ network_config.net_name }} VRF {{ network_config.vrf_name }} VLAN {{ network_config.vlan_id }} SUBNET {{ network_config.gw_ip_subnet }}" + cisco.dcnm.dcnm_network: + fabric: "{{ network_config.fabric }}" + state: replaced + config: + - net_name: "{{ network_config.net_name }}" + vrf_name: "{{ network_config.vrf_name }}" + vlan_id: "{{ network_config.vlan_id }}" + gw_ip_subnet: "{{ network_config.gw_ip_subnet }}" + attach: "{{ network_config.attach }}" diff --git a/roles/ndfc_network_replaced_all/README.md b/roles/ndfc_network_replaced_all/README.md index cb4c5d3..ba3f622 100644 --- a/roles/ndfc_network_replaced_all/README.md +++ b/roles/ndfc_network_replaced_all/README.md @@ -26,7 +26,7 @@ See the following for details: roles: - ndfc_network_replaced_all vars: - fabric_name: f1 + fabric_name: MSD ``` ### Licensing diff --git a/roles/ndfc_network_replaced_all/tasks/main.yml b/roles/ndfc_network_replaced_all/tasks/main.yml index a98a6bc..bb6761f 100644 --- a/roles/ndfc_network_replaced_all/tasks/main.yml +++ b/roles/ndfc_network_replaced_all/tasks/main.yml @@ -2,6 +2,7 @@ --- - name: main replaced Network FABRIC {{ fabric_name }} include_tasks: worker.yml - loop: "{{ networks | json_query(mq1) }}" - vars: - mq1: "[?fabric == '{{ fabric_name }}']" + loop: "{{ lookup('ansible.builtin.dict', networks) }}" + when: "fabric_name in network.value.fabric" + loop_control: + loop_var: network diff --git a/roles/ndfc_network_replaced_all/tasks/worker.yml b/roles/ndfc_network_replaced_all/tasks/worker.yml index c9b25fa..4cff22d 100644 --- a/roles/ndfc_network_replaced_all/tasks/worker.yml +++ b/roles/ndfc_network_replaced_all/tasks/worker.yml @@ -1,11 +1,13 @@ # ndfc_network_replaced_all/tasks/worker.yml -- name: worker replaced FABRIC {{ fabric_name }} NETWORK {{ item.net_name }} VRF {{ item.vrf_name }} VLAN {{ item.vlan_id }} SUBNET {{ item.gw_ip_subnet }}" +- name: worker replaced FABRIC {{ network.value.fabric }} NETWORK {{ network.value.net_name }} VRF {{ network.value.vrf_name }} VLAN {{ network.value.vlan_id }} SUBNET {{ network.value.gw_ip_subnet }}" cisco.dcnm.dcnm_network: fabric: "{{ fabric_name }}" state: replaced config: - - net_name: "{{ item.net_name }}" - vrf_name: "{{ item.vrf_name }}" - vlan_id: "{{ item.vlan_id }}" - gw_ip_subnet: "{{ item.gw_ip_subnet }}" - attach: "{{ item.attach }}" + - net_name: "{{ network.value.net_name }}" + vrf_name: "{{ network.value.vrf_name }}" + vlan_id: "{{ network.value.vlan_id }}" + gw_ip_subnet: "{{ network.value.gw_ip_subnet }}" + attach: "{{ network.value.attach }}" + vars: + ansible_connection: httpapi diff --git a/roles/ndfc_policy_query_generated_config_all/tasks/main.yml b/roles/ndfc_policy_query_generated_config_all/tasks/main.yml index 544b2de..f0280c0 100644 --- a/roles/ndfc_policy_query_generated_config_all/tasks/main.yml +++ b/roles/ndfc_policy_query_generated_config_all/tasks/main.yml @@ -1,20 +1,8 @@ # ndfc_policy_query_generated_config_all/main.yml --- -- name: main query FABRIC {{ fabric_name }} Generated Configs leaf +- name: main query generated config include_tasks: worker.yml - loop: "{{ leafs | json_query(mq1) }}" - vars: - mq1: "[?fabric == '{{ fabric_name }}']" - -- name: main query FABRIC {{ fabric_name }} Generated Configs spine - include_tasks: worker.yml - loop: "{{ spines | json_query(mq2) }}" - vars: - mq2: "[?fabric == '{{ fabric_name }}']" - -- name: main query FABRIC {{ fabric_name }} Generated Configs border_gateway - include_tasks: worker.yml - loop: "{{ border_gateways | json_query(mq3) }}" - vars: - mq3: "[?fabric == '{{ fabric_name }}']" - + loop: "{{ lookup('ansible.builtin.dict', devices) }}" + when: "fabric_name in device.value.switch_fabric" + loop_control: + loop_var: device diff --git a/roles/ndfc_policy_query_generated_config_all/tasks/worker.yml b/roles/ndfc_policy_query_generated_config_all/tasks/worker.yml index f7eb799..47541bd 100644 --- a/roles/ndfc_policy_query_generated_config_all/tasks/worker.yml +++ b/roles/ndfc_policy_query_generated_config_all/tasks/worker.yml @@ -1,18 +1,21 @@ # ndfc_policy_query_generated_config_all/worker.yml -- name: worker query FABRIC {{ fabric_name }} DEVICE {{ item.name }} IP {{ item.ip }} generated_config +- name: worker query WANT FABRIC {{ fabric_name }} CURRENT FABRIC {{ device.value.switch_fabric }} DEVICE {{ device.value.name }} IP {{ device.value.ip }} generated_config cisco.dcnm.dcnm_policy: - fabric: "{{ fabric_name }}" + fabric: "{{ device.value.switch_fabric }}" state: query config: - switch: - - ip: "{{ item.ip }}" + - ip: "{{ device.value.ip }}" register: wr1 + vars: + ansible_connection: httpapi -- name: worker set_fact generated_configs DEVICE {{ item.name }} IP {{ item.ip }} +- name: worker set_fact generated_configs DEVICE {{ device.value.name }} IP {{ device.value.ip }} set_fact: - generated_configs: "{{ wr1.response | json_query(wq1) }}" + generated_configs: "{{ wr1.response | json_query(wq1) }}" vars: wq1: "[?generatedConfig != ''].{TemplateName: templateName GeneratedConfig: generatedConfig}" -- name: show populated generated_configs {{ item.role }} {{ item.name }} {{ item.ip }} + +- name: show populated generated_configs {{ device.value.role }} {{ device.value.name }} {{ device.value.ip }} debug: var: generated_configs diff --git a/roles/ndfc_policy_query_interface_all/tasks/main.yml b/roles/ndfc_policy_query_interface_all/tasks/main.yml index 368e18f..37f0917 100644 --- a/roles/ndfc_policy_query_interface_all/tasks/main.yml +++ b/roles/ndfc_policy_query_interface_all/tasks/main.yml @@ -1,19 +1,8 @@ # ndfc_policy_query_interface/tasks/main.yml --- -- name: main query FABRIC {{ fabric_name }} Interface Policies leaf +- name: main query generated config include_tasks: worker.yml - loop: "{{ leafs | json_query(mq1) }}" - vars: - mq1: "[?fabric == '{{ fabric_name }}']" - -- name: main query FABRIC {{ fabric_name }} Interface Policies spine - include_tasks: worker.yml - loop: "{{ spines | json_query(mq2) }}" - vars: - mq2: "[?fabric == '{{ fabric_name }}']" - -- name: main query FABRIC {{ fabric_name }} Interface Policies border_gateway - include_tasks: worker.yml - loop: "{{ border_gateways | json_query(mq3) }}" - vars: - mq3: "[?fabric == '{{ fabric_name }}']" + loop: "{{ lookup('ansible.builtin.dict', devices) }}" + when: "fabric_name in device.value.switch_fabric" + loop_control: + loop_var: device diff --git a/roles/ndfc_policy_query_interface_all/tasks/worker.yml b/roles/ndfc_policy_query_interface_all/tasks/worker.yml index d53aa90..aff0840 100644 --- a/roles/ndfc_policy_query_interface_all/tasks/worker.yml +++ b/roles/ndfc_policy_query_interface_all/tasks/worker.yml @@ -1,12 +1,14 @@ # ndfc_policy_query_interface/tasks/worker.yml -- name: worker query FABRIC {{ fabric_name }} ROLE {{ item.role}} DEVICE {{ item.name }} INTERFACE {{ interface_name }}" +- name: worker query FABRIC {{ fabric_name }} ROLE {{ device.value.role}} DEVICE {{ device.value.name }} INTERFACE {{ interface_name }}" cisco.dcnm.dcnm_policy: fabric: "{{ fabric_name }}" state: query config: - switch: - - ip: "{{ item.ip }}" + - ip: "{{ device.value.ip }}" register: wr1 + vars: + ansible_connection: httpapi - name: worker set_fact interface_config set_fact: diff --git a/roles/ndfc_policy_vrf_rt_import/README.md b/roles/ndfc_policy_vrf_rt_import/README.md deleted file mode 100644 index 8265e5c..0000000 --- a/roles/ndfc_policy_vrf_rt_import/README.md +++ /dev/null @@ -1,50 +0,0 @@ -# ndfc_policy_vrf_rt_import - -Import vrf ``import_vrf_name``'s route-targets into vrf ``vrf_name`` on device ``device_name`` in fabric ``fabric_name`` using Ansible state ``state`` - -NOTE: This role doesn't work for inter-vrf route-target import/export and may be deprecated in the future. Please use ``ndfc_policy_vrf_rt_import_evpn`` or ``ndfc_policy_vrf_rt_import_evpn_loop`` instead. - -### Role Variables - -Variable | Type | Description -----------------|-------|---------------------------------------- -device_name | str() | The device to which vrf ``vrf_name`` is attached -fabric_name | str() | The fabric in which ``device_name`` resides -vrf_name | str() | The vrf into which ``import_vrf_name``'s route-targets will be imports -import_vrf_name | str() | The vrf whose route-targets will be imported into ``vrf_name`` -state | str() | The Ansible state to apply for the import. e.g. ``deleted`` to delete the import, ``merged`` to merge the import, etc. - -Fabric, device, and vrf names are are defined in the following file: - -``./roles/ndfc_common/vars/main.yml`` - -See the following for details: - -[./roles/ndfc_common/README.md](https://github.com/allenrobel/ndfc-roles/tree/master/roles/ndfc_common/README.md) - -### Example Playbook - -```yaml -# Import vrf v2's route-targets into vrf v1 on device leaf_2 in fabric f1, using Ansible state 'merged' ---- -- hosts: ndfc - gather_facts: false - roles: - - ndfc_policy_vrf_rt_import - vars: - fabric_name: f1 - device_name: leaf_2 - vrf_name: v1 - import_vrf_name: v2 - state: merged -``` - -### Licensing - -GNU General Public License v3.0 or later. - -See [LICENSE](https://www.gnu.org/licenses/gpl-3.0.txt) for full text. - -### Author Information - -Allen Robel (@packetcalc) diff --git a/roles/ndfc_policy_vrf_rt_import/tasks/main.yml b/roles/ndfc_policy_vrf_rt_import/tasks/main.yml deleted file mode 100644 index eb8e499..0000000 --- a/roles/ndfc_policy_vrf_rt_import/tasks/main.yml +++ /dev/null @@ -1,8 +0,0 @@ -# ndfc_policy_vrf_rt_import/tasks/main.yml ---- -- name: main {{ state }} FABRIC {{ fabric_name }} DEVICE {{ device_name }} vrf route-target import/export - include_tasks: worker.yml - loop: "{{ mr1 }}" - vars: - mq1: "[?name == '{{ device_name }}'] | [?fabric == '{{ fabric_name }}']" - mr1: "{{ leafs | json_query(mq1) + spines | json_query(mq1) + border_gateways | json_query(mq1) }}" diff --git a/roles/ndfc_policy_vrf_rt_import/tasks/worker.yml b/roles/ndfc_policy_vrf_rt_import/tasks/worker.yml deleted file mode 100644 index 1fab920..0000000 --- a/roles/ndfc_policy_vrf_rt_import/tasks/worker.yml +++ /dev/null @@ -1,20 +0,0 @@ -# ndfc_policy_vrf_rt_import/tasks/worker.yml -- name: worker {{ state }} {{ item.fabric }} {{ item.name }} {{ vrf_name }} importing {{ import_vrf_name }}.{{ import_vrf_asn }}:{{ import_vrf_index }} - cisco.dcnm.dcnm_policy: - state: "{{ state }}" - deploy: true - fabric: "{{ item.fabric }}" - config: - - name: vrf_context_rt - create_additional_policy: false - policy_vars: - VRF_NAME: "{{ vrf_name }}" - ASN: "{{ import_vrf_asn }}" - ALLOCATE_INDEX: "{{ import_vrf_index }}" - - switch: - - ip: "{{ item.ip }}" - vars: - q2: "[?fabric == '{{ item.fabric }}'] | [?vrf_name == '{{ import_vrf_name }}'].vrf_id | [0]" - q3: "[?name == '{{ item.fabric }}'].BGP_AS | [0]" - import_vrf_index: "{{ vrfs | json_query(q2) }}" - import_vrf_asn: "{{ fabrics | json_query(q3) }}" diff --git a/roles/ndfc_policy_vrf_rt_import_evpn/tasks/main.yml b/roles/ndfc_policy_vrf_rt_import_evpn/tasks/main.yml index 8a4fe91..1e280b9 100644 --- a/roles/ndfc_policy_vrf_rt_import_evpn/tasks/main.yml +++ b/roles/ndfc_policy_vrf_rt_import_evpn/tasks/main.yml @@ -1,8 +1,45 @@ -# ndfc_policy_vrf_rt_import_evpn/tasks/main.yml ---- -- name: main {{ state }} FABRIC {{ fabric_name }} DEVICE {{ device_name }} vrf route-target evpn import - include_tasks: worker.yml - loop: "{{ mr1 }}" +# ndfc_policy_vrf_rt_import/tasks/worker.yml +- ansible.builtin.include_role: + name: ndfc_device_config_get + +- name: set_fact all_fabrics + ansible.builtin.set_fact: + all_fabrics: "{{ msd_fabrics | combine(switch_fabrics, external_fabrics) }}" + +- name: state {{ state }} fabric {{ device_config.switch_fabric }} {{ device_config.name }} vrf {{ vrf_name }} importing {{ import_vrf_name }}.{{ import_vrf_asn }}:{{ import_vrf_index }} + retries: 3 + register: result + until: result is not failed + cisco.dcnm.dcnm_policy: + state: "{{ state }}" + deploy: true + fabric: "{{ device_config.switch_fabric }}" + config: + - name: Default_VRF_Universal + create_additional_policy: false + policy_vars: + vrfName: "{{ vrf_name }}" + vrfVlanId: "{{ vrf_vlan_id }}" + nveId: 1 + asn: "{{ import_vrf_asn }}" + vrfSegmentId: "{{ vrf_index }}" + routeTargetImport: "{{ import_vrf_asn }}:{{ import_vrf_index }}" + routeTargetImportEvpn: "{{ import_vrf_asn }}:{{ import_vrf_index }}" + - switch: + - ip: "{{ device_config.ip }}" vars: - mq1: "[?name == '{{ device_name }}'] | [?fabric == '{{ fabric_name }}']" - mr1: "{{ leafs | json_query(mq1) + spines | json_query(mq1) + border_gateways | json_query(mq1) }}" + ansible_connection: httpapi + wq1: "[?fabric == '{{ fabric_name }}'] | [?vrf_name == '{{ import_vrf_name }}'].vrf_id | [0]" + wq2: "[?fabric == '{{ fabric_name }}'] | [?vrf_name == '{{ vrf_name }}'].vlan_id | [0]" + wq3: "[?fabric == '{{ fabric_name }}'] | [?vrf_name == '{{ vrf_name }}'].vrf_id | [0]" + wq4: "[?name == '{{ fabric_name }}'].BGP_AS | [0]" + import_vrf_index: "{{ vrfs.values() | list | json_query(wq1) }}" + vrf_vlan_id: "{{ vrfs.values() | list | json_query(wq2) }}" + vrf_index: "{{ vrfs.values() | list | json_query(wq3) }}" + import_vrf_asn: "{{ all_fabrics.values() | list | json_query(wq4) }}" + +- ansible.builtin.include_role: + name: ndfc_rest_config_deploy + vars: + device_name: "{{ device_config.name }}" + fabric_name: "{{ device_config.switch_fabric }}" diff --git a/roles/ndfc_policy_vrf_rt_import_evpn/tasks/worker.yml b/roles/ndfc_policy_vrf_rt_import_evpn/tasks/worker.yml deleted file mode 100644 index beff5ba..0000000 --- a/roles/ndfc_policy_vrf_rt_import_evpn/tasks/worker.yml +++ /dev/null @@ -1,37 +0,0 @@ -# ndfc_policy_vrf_rt_import/tasks/worker.yml -- name: worker {{ state }} {{ item.fabric }} {{ item.name }} {{ vrf_name }} importing {{ import_vrf_name }}.{{ import_vrf_asn }}:{{ import_vrf_index }} - retries: 3 - register: result - until: result is not failed - cisco.dcnm.dcnm_policy: - state: "{{ state }}" - deploy: true - fabric: "{{ item.fabric }}" - config: - - name: Default_VRF_Universal - create_additional_policy: false - policy_vars: - vrfName: "{{ vrf_name }}" - vrfVlanId: "{{ vrf_vlan_id }}" - nveId: 1 - asn: "{{ import_vrf_asn }}" - vrfSegmentId: "{{ vrf_index }}" - routeTargetImport: "{{ import_vrf_asn }}:{{ import_vrf_index }}" - routeTargetImportEvpn: "{{ import_vrf_asn }}:{{ import_vrf_index }}" - - switch: - - ip: "{{ item.ip }}" - vars: - wq1: "[?fabric == '{{ fabric_name }}'] | [?vrf_name == '{{ import_vrf_name }}'].vrf_id | [0]" - wq2: "[?fabric == '{{ fabric_name }}'] | [?vrf_name == '{{ vrf_name }}'].vlan_id | [0]" - wq3: "[?fabric == '{{ fabric_name }}'] | [?vrf_name == '{{ vrf_name }}'].vrf_id | [0]" - wq4: "[?name == '{{ fabric_name }}'].BGP_AS | [0]" - import_vrf_index: "{{ vrfs | json_query(wq1) }}" - vrf_vlan_id: "{{ vrfs | json_query(wq2) }}" - vrf_index: "{{ vrfs | json_query(wq3) }}" - import_vrf_asn: "{{ fabrics | json_query(wq4) }}" - -- ansible.builtin.include_role: - name: ndfc_rest_config_deploy - vars: - device_name: "{{ item.name }}" - fabric_name: "{{ item.fabric }}" diff --git a/roles/ndfc_policy_vrf_rt_import_evpn_loop/tasks/main.yml b/roles/ndfc_policy_vrf_rt_import_evpn_loop/tasks/main.yml index 7988172..27f0b1c 100644 --- a/roles/ndfc_policy_vrf_rt_import_evpn_loop/tasks/main.yml +++ b/roles/ndfc_policy_vrf_rt_import_evpn_loop/tasks/main.yml @@ -2,4 +2,4 @@ --- - name: main {{ state }} VRF route-target import/export include_tasks: worker.yml - loop: "{{ devices }}" + loop: "{{ device_list }}" diff --git a/roles/ndfc_policy_vrf_rt_import_evpn_loop/tasks/worker.yml b/roles/ndfc_policy_vrf_rt_import_evpn_loop/tasks/worker.yml index 8db4166..e6e1405 100644 --- a/roles/ndfc_policy_vrf_rt_import_evpn_loop/tasks/worker.yml +++ b/roles/ndfc_policy_vrf_rt_import_evpn_loop/tasks/worker.yml @@ -1,4 +1,13 @@ # ndfc_policy_vrf_rt_import_evpn_loop/tasks/worker.yml + +- ansible.builtin.include_role: + name: ndfc_device_config_get + vars: + device_name: "{{ item }}" +- name: set_fact all_fabrics + ansible.builtin.set_fact: + all_fabrics: "{{ msd_fabrics | combine(switch_fabrics, external_fabrics) }}" + - name: worker {{ state }} FABRIC {{ fabric_name }} ITEM {{ item }} VRF.VLAN.ASN.INDEX {{ vrf_name }}.{{ vrf_vlan_id }}.{{ import_vrf_asn }}.{{ vrf_index }} import VRF.ASN:INDEX {{ import_vrf_name }}.{{ import_vrf_asn }}:{{ import_vrf_index }} retries: 3 register: result @@ -19,17 +28,19 @@ routeTargetImport: "{{ import_vrf_asn }}:{{ import_vrf_index }}" routeTargetImportEvpn: "{{ import_vrf_asn }}:{{ import_vrf_index }}" - switch: - - ip: "{{ devices[0].ip }}" + - ip: "{{ device_config.ip }}" vars: + ansible_connection: httpapi wq1: "[?fabric == '{{ fabric_name }}'] | [?vrf_name == '{{ import_vrf_name }}'].vrf_id | [0]" wq2: "[?fabric == '{{ fabric_name }}'] | [?vrf_name == '{{ vrf_name }}'].vlan_id | [0]" wq3: "[?fabric == '{{ fabric_name }}'] | [?vrf_name == '{{ vrf_name }}'].vrf_id | [0]" wq4: "[?name == '{{ fabric_name }}'].BGP_AS | [0]" wq5: "[?name == '{{ item }}'] | [?fabric == '{{ fabric_name }}']" - import_vrf_index: "{{ vrfs | json_query(wq1) }}" - vrf_vlan_id: "{{ vrfs | json_query(wq2) }}" - vrf_index: "{{ vrfs | json_query(wq3) }}" - import_vrf_asn: "{{ fabrics | json_query(wq4) }}" - devices: "{{ leafs | json_query(wq5) + spines | json_query(wq5) + border_gateways | json_query(wq5) }}" + import_vrf_index: "{{ vrfs.values() | list | json_query(wq1) }}" + vrf_vlan_id: "{{ vrfs.values() | list | json_query(wq2) }}" + vrf_index: "{{ vrfs.values() | list | json_query(wq3) }}" + import_vrf_asn: "{{ all_fabrics.values() | list | json_query(wq4) }}" - ansible.builtin.include_role: name: ndfc_rest_config_deploy_all + vars: + ansible_connection: httpapi diff --git a/roles/ndfc_policy_vrf_rt_import_loop/README.md b/roles/ndfc_policy_vrf_rt_import_loop/README.md deleted file mode 100644 index 2b8698b..0000000 --- a/roles/ndfc_policy_vrf_rt_import_loop/README.md +++ /dev/null @@ -1,92 +0,0 @@ -# ndfc_policy_vrf_rt_import_loop - -Import vrf ``import_vrf_name``'s route-targets into vrf ``vrf_name`` on multiple devices in fabric ``fabric_name`` using Ansible state ``state`` - -NOTE: This role doesn't work for inter-vrf route-target import/export and may be deprecated in the future. Please use ``ndfc_policy_vrf_rt_import_evpn`` or ``ndfc_policy_vrf_rt_import_evpn_loop`` instead. - -### Role Variables - -Variable | Type | Description -----------------|--------|---------------------------------------- -fabric_name | str() | The fabric in which ``device_name`` resides -vrf_name | str() | The vrf into which ``import_vrf_name``'s route-targets will be imports -import_vrf_name | str() | The vrf whose route-targets will be imported into ``vrf_name`` -state | str() | The Ansible state to apply for the import. e.g. ``deleted`` to delete the import, ``merged`` to merge the import, etc. -devices | list() | An Ansible list of ``device_name`` to which ``vrf_name`` is attached - -Fabric, device, and vrf names are are defined in the following file: - -``./roles/ndfc_common/vars/main.yml`` - -See the following for details: - -[./roles/ndfc_common/README.md](https://github.com/allenrobel/ndfc-roles/tree/master/roles/ndfc_common/README.md) - -### Example Playbook - -The example below performs a bi-directional import of route-targets between vrfs v1 and v2 on four leaf devices in fabric f1. - -```yaml ---- -# Import vrf v2 route-targets into vrf v1 on four leaf devices -- hosts: ndfc - name: Import vrf v2 route-targets into vrf v1 - gather_facts: false - vars: - state: merged - fabric_name: f1 - vrf_name: v1 - import_vrf_name: v2 - devices: - - leaf_1 - - leaf_2 - - leaf_3 - - leaf_4 - roles: - - ndfc_policy_vrf_rt_import_loop - -# Deploy -- hosts: ndfc - name: deploy and save configs - gather_facts: false - roles: - - ndfc_rest_config_deploy_all - vars: - fabric_name: f1 - -# Import vrf v1 route-targets into vrf v2 on four leaf devices -- hosts: ndfc - name: Import vrf v1 route-targets into vrf v2 - gather_facts: false - vars: - state: merged - fabric_name: f1 - vrf_name: v2 - import_vrf_name: v1 - devices: - - leaf_1 - - leaf_2 - - leaf_3 - - leaf_4 - roles: - - ndfc_policy_vrf_rt_import_loop - -# Deploy -- hosts: ndfc - name: deploy and save configs - gather_facts: false - roles: - - ndfc_rest_config_deploy_all - vars: - fabric_name: f1 -``` - -### Licensing - -GNU General Public License v3.0 or later. - -See [LICENSE](https://www.gnu.org/licenses/gpl-3.0.txt) for full text. - -### Author Information - -Allen Robel (@packetcalc) diff --git a/roles/ndfc_policy_vrf_rt_import_loop/tasks/main.yml b/roles/ndfc_policy_vrf_rt_import_loop/tasks/main.yml deleted file mode 100644 index f6398b5..0000000 --- a/roles/ndfc_policy_vrf_rt_import_loop/tasks/main.yml +++ /dev/null @@ -1,5 +0,0 @@ -# ndfc_policy_vrf_rt_import_loop/tasks/main.yml ---- -- name: main {{ state }} VRF route-target import/export - include_tasks: worker.yml - loop: "{{ devices }}" diff --git a/roles/ndfc_policy_vrf_rt_import_loop/tasks/worker.yml b/roles/ndfc_policy_vrf_rt_import_loop/tasks/worker.yml deleted file mode 100644 index ce7ba15..0000000 --- a/roles/ndfc_policy_vrf_rt_import_loop/tasks/worker.yml +++ /dev/null @@ -1,22 +0,0 @@ -# ndfc_policy_vrf_rt_import_loop/tasks/policy_vrf_rt_import.yml -- name: worker {{ state }} FABRIC {{ fabric_name }} ITEM {{ item }} VRF_NAME {{ vrf_name }} import VRF.ASN:INDEX {{ import_vrf_name }}.{{ import_vrf_asn }}:{{ import_vrf_index }} - cisco.dcnm.dcnm_policy: - state: "{{ state }}" - deploy: true - fabric: "{{ fabric_name }}" - config: - - name: vrf_context_rt - create_additional_policy: false - policy_vars: - VRF_NAME: "{{ vrf_name }}" - ASN: "{{ import_vrf_asn }}" - ALLOCATE_INDEX: "{{ import_vrf_index }}" - - switch: - - ip: "{{ devices[0].ip }}" - vars: - wq1: "[?fabric == '{{ fabric_name }}'] | [?vrf_name == '{{ import_vrf_name }}'].vrf_id | [0]" - wq2: "[?name == '{{ fabric_name }}'].BGP_AS | [0]" - wq3: "[?name == '{{ item }}'] | [?fabric == '{{ fabric_name }}']" - import_vrf_index: "{{ vrfs | json_query(wq1) }}" - import_vrf_asn: "{{ fabrics | json_query(wq2) }}" - devices: "{{ leafs | json_query(wq3) + spines | json_query(wq3) + border_gateways | json_query(wq3) }}" diff --git a/roles/ndfc_rest_config_deploy/tasks/main.yml b/roles/ndfc_rest_config_deploy/tasks/main.yml index 0b0a16f..102cbb8 100644 --- a/roles/ndfc_rest_config_deploy/tasks/main.yml +++ b/roles/ndfc_rest_config_deploy/tasks/main.yml @@ -10,6 +10,7 @@ path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics/{{ fabric_name }}/config-save" json_data: "{{ vars_dict | to_json }}" vars: + ansible_connection: httpapi vars_dict: - name: main REST POST config-deploy FABRIC {{ fabric_name }} device_name {{ device_name }} switchDbId {{ device_info.switchDbID }} @@ -18,5 +19,6 @@ path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics/{{ fabric_name }}/config-deploy/{{ device_info.switchDbID }}" json_data: "{{ vars_dict | to_json }}" vars: + ansible_connection: httpapi vars_dict: forceShowRun: "{{ forceShowRun }}" diff --git a/roles/ndfc_rest_config_deploy_all/tasks/main.yml b/roles/ndfc_rest_config_deploy_all/tasks/main.yml index 695df5e..16fae59 100644 --- a/roles/ndfc_rest_config_deploy_all/tasks/main.yml +++ b/roles/ndfc_rest_config_deploy_all/tasks/main.yml @@ -6,6 +6,7 @@ path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics/{{ fabric_name }}/config-save" json_data: "{{ vars_dict | to_json }}" vars: + ansible_connection: httpapi vars_dict: - name: main REST POST config-deploy FABRIC {{ fabric_name }} @@ -14,6 +15,7 @@ path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics/{{ fabric_name }}/config-deploy" json_data: "{{ vars_dict | to_json }}" vars: + ansible_connection: httpapi vars_dict: forceShowRun: "{{ forceShowRun }}" inclAllMSDSwitches: "{{ inclAllMSDSwitches }}" \ No newline at end of file diff --git a/roles/ndfc_rest_device_set_role/README.md b/roles/ndfc_rest_device_set_role/README.md index 821191b..2c358ad 100644 --- a/roles/ndfc_rest_device_set_role/README.md +++ b/roles/ndfc_rest_device_set_role/README.md @@ -7,7 +7,6 @@ Set role for device ``device_name``. Variable | Type | Description ----------------|-------|---------------------------------------- device_name | str() | The device to be merged -fabric_name | str() | The fabric in which ``device_name`` resides role | str() | The desired role for ``device_name`` e.g. leaf, spine, border_gateway, etc Device and Fabric names are defined in the following file: diff --git a/roles/ndfc_rest_device_set_role/tasks/main.yml b/roles/ndfc_rest_device_set_role/tasks/main.yml index 7272348..25abb67 100644 --- a/roles/ndfc_rest_device_set_role/tasks/main.yml +++ b/roles/ndfc_rest_device_set_role/tasks/main.yml @@ -1,8 +1,28 @@ -# ndfc_device_merged/tasks/main.yml ---- -- name: main merged FABRIC {{ fabric_name }} DEVICE {{ device_name }} - include_tasks: worker.yml - loop: "{{ mr1 }}" +# ndfc_rest_device_set_role/tasks/worker.yml +- ansible.builtin.include_role: + name: ndfc_device_config_get + +- ansible.builtin.include_role: + name: ndfc_device_serial_number_get vars: - mq1: "[?name == '{{ device_name }}'] | [?fabric == '{{ fabric_name }}']" - mr1: "{{ leafs | json_query(mq1) + spines | json_query(mq1) + border_gateways | json_query(mq1) }}" + device_name: "{{ device_config.name }}" + fabric_name: "{{ device_config.switch_fabric }}" + +- name: worker REST POST set device role FABRIC {{ device_config.switch_fabric }} NAME {{ device_config.name }} IP {{ device_config.ip }} SERIAL {{ device_serial_number }} payload {{ payload }} + cisco.dcnm.dcnm_rest: + method: POST + path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/switches/roles" + json_data: "{{ payload | to_json }}" + when: "device_serial_number != ''" + vars: + ansible_connection: httpapi + payload: + - serialNumber: "{{ device_serial_number }}" + role: "{{ role }}" + +- ansible.builtin.include_role: + name: ndfc_rest_config_deploy + vars: + device_name: "{{ device_config.name }}" + fabric_name: "{{ device_config.switch_fabric }}" + when: "device_serial_number != ''" diff --git a/roles/ndfc_rest_device_set_role/tasks/worker.yml b/roles/ndfc_rest_device_set_role/tasks/worker.yml deleted file mode 100644 index 06cc9b3..0000000 --- a/roles/ndfc_rest_device_set_role/tasks/worker.yml +++ /dev/null @@ -1,25 +0,0 @@ -# ndfc_rest_device_set_role/tasks/worker.yml - -- ansible.builtin.include_role: - name: ndfc_device_serial_number_get - vars: - device_name: "{{ item.name }}" - fabric_name: "{{ item.fabric }}" - -- name: worker REST POST set device role FABRIC {{ item.fabric }} NAME {{ item.name }} IP {{ item.ip }} SERIAL {{ device_serial_number }} payload {{ payload }} - cisco.dcnm.dcnm_rest: - method: POST - path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/switches/roles" - json_data: "{{ payload | to_json }}" - when: "device_serial_number != ''" - vars: - - payload: - - serialNumber: "{{ device_serial_number }}" - role: "{{ role }}" - -- ansible.builtin.include_role: - name: ndfc_rest_config_deploy - vars: - device_name: "{{ item.name }}" - fabric_name: "{{ item.fabric }}" - when: "device_serial_number != ''" diff --git a/roles/ndfc_rest_fabric_access_mode_get/tasks/main.yml b/roles/ndfc_rest_fabric_access_mode_get/tasks/main.yml index 305361e..65b26f5 100644 --- a/roles/ndfc_rest_fabric_access_mode_get/tasks/main.yml +++ b/roles/ndfc_rest_fabric_access_mode_get/tasks/main.yml @@ -4,7 +4,7 @@ # if fabric does not exist, read_only will be null --- - ansible.builtin.include_role: - name: ndfc_rest_fabric_active_fabrics + name: ndfc_rest_fabric_active_fabrics_get - name: get fabric access_mode fabric {{ fabric_name }} active_fabrics {{ active_fabrics }} cisco.dcnm.dcnm_rest: diff --git a/roles/ndfc_rest_fabric_access_mode_set/tasks/main.yml b/roles/ndfc_rest_fabric_access_mode_set/tasks/main.yml index 0d6102d..383b400 100644 --- a/roles/ndfc_rest_fabric_access_mode_set/tasks/main.yml +++ b/roles/ndfc_rest_fabric_access_mode_set/tasks/main.yml @@ -4,7 +4,7 @@ # if fabric does not exist, the role is skipped and no action is taken --- - ansible.builtin.include_role: - name: ndfc_rest_fabric_active_fabrics + name: ndfc_rest_fabric_active_fabrics_get - name: set fabric access_mode fabric {{ fabric_name }} active_fabrics {{ active_fabrics }} read_only {{ read_only }} cisco.dcnm.dcnm_rest: diff --git a/roles/ndfc_rest_fabric_active_fabrics/README.md b/roles/ndfc_rest_fabric_active_fabrics_get/README.md similarity index 86% rename from roles/ndfc_rest_fabric_active_fabrics/README.md rename to roles/ndfc_rest_fabric_active_fabrics_get/README.md index 9194112..e3bef1d 100644 --- a/roles/ndfc_rest_fabric_active_fabrics/README.md +++ b/roles/ndfc_rest_fabric_active_fabrics_get/README.md @@ -1,4 +1,4 @@ -# ndfc_rest_fabric_active_fabrics +# ndfc_rest_fabric_active_fabrics_get Returns a list of active fabrics in var ``active_fabrics`` @@ -16,7 +16,7 @@ active_fabrics | list of dict() | a list of active fabrics - hosts: ndfc gather_facts: false roles: - - ndfc_rest_fabric_active_fabrics + - ndfc_rest_fabric_active_fabrics_get ``` ### Licensing diff --git a/roles/ndfc_rest_fabric_active_fabrics/defaults/main.yml b/roles/ndfc_rest_fabric_active_fabrics_get/defaults/main.yml similarity index 100% rename from roles/ndfc_rest_fabric_active_fabrics/defaults/main.yml rename to roles/ndfc_rest_fabric_active_fabrics_get/defaults/main.yml diff --git a/roles/ndfc_rest_fabric_active_fabrics/meta/main.yml b/roles/ndfc_rest_fabric_active_fabrics_get/meta/main.yml similarity index 100% rename from roles/ndfc_rest_fabric_active_fabrics/meta/main.yml rename to roles/ndfc_rest_fabric_active_fabrics_get/meta/main.yml diff --git a/roles/ndfc_rest_fabric_active_fabrics/tasks/main.yml b/roles/ndfc_rest_fabric_active_fabrics_get/tasks/main.yml similarity index 83% rename from roles/ndfc_rest_fabric_active_fabrics/tasks/main.yml rename to roles/ndfc_rest_fabric_active_fabrics_get/tasks/main.yml index 42f7052..f0cf021 100644 --- a/roles/ndfc_rest_fabric_active_fabrics/tasks/main.yml +++ b/roles/ndfc_rest_fabric_active_fabrics_get/tasks/main.yml @@ -1,4 +1,4 @@ -# ndfc_rest_fabric_active_fabrics +# ndfc_rest_fabric_active_fabrics_get # Returns list of currently-active fabrics in var 'active_fabrics' --- - name: main REST GET fabrics @@ -6,6 +6,8 @@ method: GET path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics" register: mr1 + vars: + ansible_connection: httpapi - name: main set_fact active_fabrics set_fact: diff --git a/roles/ndfc_rest_fabric_asn_get/tasks/main.yml b/roles/ndfc_rest_fabric_asn_get/tasks/main.yml index 9a0fd8c..8c51685 100644 --- a/roles/ndfc_rest_fabric_asn_get/tasks/main.yml +++ b/roles/ndfc_rest_fabric_asn_get/tasks/main.yml @@ -4,7 +4,7 @@ # if fabric does not exist, fabric_asn will be null --- - ansible.builtin.include_role: - name: ndfc_rest_fabric_active_fabrics + name: ndfc_rest_fabric_active_fabrics_get - name: get fabric info fabric {{ fabric_name }} cisco.dcnm.dcnm_rest: @@ -12,6 +12,8 @@ path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics/{{ fabric_name }}" register: mr1 when: fabric_name in active_fabrics + vars: + ansible_connection: httpapi - name: "main set_fact fabric_asn {{ mr1.response.DATA.asn }} if fabric exists" set_fact: diff --git a/roles/ndfc_rest_fabric_delete/tasks/main.yml b/roles/ndfc_rest_fabric_delete/tasks/main.yml index 1e69b09..4d36524 100644 --- a/roles/ndfc_rest_fabric_delete/tasks/main.yml +++ b/roles/ndfc_rest_fabric_delete/tasks/main.yml @@ -1,10 +1,12 @@ # ndfc_rest_fabric_delete/tasks/main.yml --- - ansible.builtin.include_role: - name: ndfc_rest_fabric_active_fabrics + name: ndfc_rest_fabric_active_fabrics_get - name: main REST DELETE FABRIC {{ fabric_name }} from ACTIVE_FABRICS {{ active_fabrics }} cisco.dcnm.dcnm_rest: method: DELETE path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics/{{ fabric_name }}" when: "fabric_name in active_fabrics" + vars: + ansible_connection: httpapi diff --git a/roles/ndfc_rest_fabric_external_create/tasks/main.yml b/roles/ndfc_rest_fabric_external_create/tasks/main.yml index 06d9faf..eb0041f 100644 --- a/roles/ndfc_rest_fabric_external_create/tasks/main.yml +++ b/roles/ndfc_rest_fabric_external_create/tasks/main.yml @@ -1,19 +1,19 @@ # ndfc_rest_fabric_external_create/tasks/main.yml --- - ansible.builtin.include_role: - name: ndfc_rest_fabric_active_fabrics + name: ndfc_rest_fabric_active_fabrics_get # TODO: add relevant user-configurable parameters to common_vars and update the # below accordingly. - name: main set_fact external_fabric {{ fabric_name }} set_fact: - BGP_AS: "{{ external_fabrics | json_query(mq1) }}" - DCI_SUBNET_RANGE: "{{ external_fabrics | json_query(mq2) }}" - DCI_SUBNET_TARGET_MASK: "{{ external_fabrics | json_query(mq3) }}" - IS_READ_ONLY: "{{ external_fabrics | json_query(mq4) }}" - LOOPBACK0_IP_RANGE: "{{ external_fabrics | json_query(mq5) }}" - POWER_REDUNDANCY_MODE: "{{ external_fabrics | json_query(mq6) }}" - SUBINTERFACE_RANGE: "{{ external_fabrics | json_query(mq7) }}" + BGP_AS: "{{ external_fabrics.values() | list | json_query(mq1) }}" + DCI_SUBNET_RANGE: "{{ external_fabrics.values() | list | json_query(mq2) }}" + DCI_SUBNET_TARGET_MASK: "{{ external_fabrics.values() | list | json_query(mq3) }}" + IS_READ_ONLY: "{{ external_fabrics.values() | list | json_query(mq4) }}" + LOOPBACK0_IP_RANGE: "{{ external_fabrics.values() | list | json_query(mq5) }}" + POWER_REDUNDANCY_MODE: "{{ external_fabrics.values() | list | json_query(mq6) }}" + SUBINTERFACE_RANGE: "{{ external_fabrics.values() | list | json_query(mq7) }}" vars: mq1: "[?name == '{{ fabric_name }}'].BGP_AS | [0]" mq2: "[?name == '{{ fabric_name }}'].DCI_SUBNET_RANGE | [0]" @@ -31,6 +31,7 @@ json_data: "{{ vars_dict | to_json }}" when: "fabric_name not in active_fabrics" vars: + ansible_connection: httpapi vars_dict: fabricName: "{{ fabric_name }}" templateName: "External_Fabric" diff --git a/roles/ndfc_rest_fabric_msd_child_add/tasks/main.yml b/roles/ndfc_rest_fabric_msd_child_add/tasks/main.yml index c179d29..9e52e7c 100644 --- a/roles/ndfc_rest_fabric_msd_child_add/tasks/main.yml +++ b/roles/ndfc_rest_fabric_msd_child_add/tasks/main.yml @@ -1,7 +1,7 @@ # ndfc_rest_fabric_msd_add_child/tasks/main.yml --- - ansible.builtin.include_role: - name: ndfc_rest_fabric_active_fabrics + name: ndfc_rest_fabric_active_fabrics_get # query fabric-associations for child_fabric's fabric_parent - name: main REST GET fabric_associations @@ -9,6 +9,8 @@ method: GET path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics/msd/fabric-associations/" register: mr2 + vars: + ansible_connection: httpapi - name: main set_fact fabric_parent set_fact: fabric_parent: "{{ mr2.response.DATA | json_query(mq2) }}" @@ -23,6 +25,7 @@ json_data: "{{ vars_dict | to_json }}" when: "msd_fabric in active_fabrics and child_fabric in active_fabrics and fabric_parent[0].fabricParent == 'None'" vars: + ansible_connection: httpapi vars_dict: destFabric: "{{ msd_fabric }}" sourceFabric: "{{ child_fabric }}" diff --git a/roles/ndfc_rest_fabric_msd_child_remove/tasks/main.yml b/roles/ndfc_rest_fabric_msd_child_remove/tasks/main.yml index 66a24bf..5dcf8eb 100644 --- a/roles/ndfc_rest_fabric_msd_child_remove/tasks/main.yml +++ b/roles/ndfc_rest_fabric_msd_child_remove/tasks/main.yml @@ -1,7 +1,7 @@ # ndfc_rest_fabric_msd_remove_child/tasks/main.yml --- - ansible.builtin.include_role: - name: ndfc_rest_fabric_active_fabrics + name: ndfc_rest_fabric_active_fabrics_get # query fabric-associations for child_fabric's fabric_parent - name: main REST GET fabric_associations @@ -9,6 +9,8 @@ method: GET path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics/msd/fabric-associations/" register: mr2 + vars: + ansible_connection: httpapi - name: main set_fact fabric_parent set_fact: fabric_parent: "{{ mr2.response.DATA | json_query(mq2) }}" @@ -23,6 +25,7 @@ json_data: "{{ vars_dict | to_json }}" when: "msd_fabric in active_fabrics and child_fabric in active_fabrics and fabric_parent[0].fabricParent != 'None'" vars: + ansible_connection: httpapi vars_dict: destFabric: "{{ msd_fabric }}" sourceFabric: "{{ child_fabric }}" diff --git a/roles/ndfc_rest_fabric_msd_create/tasks/main.yml b/roles/ndfc_rest_fabric_msd_create/tasks/main.yml index 367d1bb..f16ef1f 100644 --- a/roles/ndfc_rest_fabric_msd_create/tasks/main.yml +++ b/roles/ndfc_rest_fabric_msd_create/tasks/main.yml @@ -1,33 +1,14 @@ # ndfc_rest_fabric_msd_create/tasks/main.yml --- - ansible.builtin.include_role: - name: ndfc_rest_fabric_active_fabrics + name: ndfc_rest_fabric_active_fabrics_get -# TODO: add relevant user-configurable parameters to common_vars and update the -# below accordingly. -- name: main set_fact FABRIC {{ msd_fabric }} +- name: worker set_fact msd_fabric name {{ fabric_name }} set_fact: - L2_SEGMENT_ID_RANGE: "{{ msd_fabrics | json_query(mq2) }}" - L3_PARTITION_ID_RANGE: "{{ msd_fabrics | json_query(mq3) }}" - ANYCAST_GW_MAC: "{{ msd_fabrics | json_query(mq4) }}" - MS_LOOPBACK_ID: "{{ msd_fabrics | json_query(mq5) }}" - BORDER_GWY_CONNECTIONS: "{{ msd_fabrics | json_query(mq6) }}" - MS_UNDERLAY_AUTOCONFIG: "{{ msd_fabrics | json_query(mq7) }}" - DELAY_RESTORE: "{{ msd_fabrics | json_query(mq8) }}" - LOOPBACK100_IP_RANGE: "{{ msd_fabrics | json_query(mq9) }}" - DCI_SUBNET_RANGE: "{{ msd_fabrics | json_query(mq10) }}" - DCI_SUBNET_TARGET_MASK: "{{ msd_fabrics | json_query(mq11) }}" + _config: "{{ msd_fabrics | json_query(mq2) }}" vars: - mq2: "[?name == '{{ msd_fabric }}'].L2_SEGMENT_ID_RANGE | [0]" - mq3: "[?name == '{{ msd_fabric }}'].L3_PARTITION_ID_RANGE | [0]" - mq4: "[?name == '{{ msd_fabric }}'].ANYCAST_GW_MAC | [0]" - mq5: "[?name == '{{ msd_fabric }}'].MS_LOOPBACK_ID | [0]" - mq6: "[?name == '{{ msd_fabric }}'].BORDER_GWY_CONNECTIONS | [0]" - mq7: "[?name == '{{ msd_fabric }}'].MS_UNDERLAY_AUTOCONFIG | [0]" - mq8: "[?name == '{{ msd_fabric }}'].DELAY_RESTORE | [0]" - mq9: "[?name == '{{ msd_fabric }}'].LOOPBACK100_IP_RANGE | [0]" - mq10: "[?name == '{{ msd_fabric }}'].DCI_SUBNET_RANGE | [0]" - mq11: "[?name == '{{ msd_fabric }}'].DCI_SUBNET_TARGET_MASK | [0]" + mq2: "{{ msd_fabric }}" + - name: main REST POST msd_fabric {{ msd_fabric }} active_fabrics {{ active_fabrics }} cisco.dcnm.dcnm_rest: @@ -36,19 +17,20 @@ json_data: "{{ vars_dict | to_json }}" when: "msd_fabric not in active_fabrics" vars: + ansible_connection: httpapi vars_dict: fabricName: "{{ msd_fabric }}" templateName: "MSD_Fabric" nvPairs: FABRIC_NAME: "{{ msd_fabric }}" - L2_SEGMENT_ID_RANGE: "{{ L2_SEGMENT_ID_RANGE }}" - L3_PARTITION_ID_RANGE: "{{ L3_PARTITION_ID_RANGE }}" + L2_SEGMENT_ID_RANGE: "{{ _config.L2_SEGMENT_ID_RANGE }}" + L3_PARTITION_ID_RANGE: "{{ _config.L3_PARTITION_ID_RANGE }}" default_vrf: "Default_VRF_Universal" default_network: "Default_Network_Universal" vrf_extension_template: "Default_VRF_Extension_Universal" network_extension_template: "Default_Network_Extension_Universal" - ANYCAST_GW_MAC: "{{ ANYCAST_GW_MAC }}" - MS_LOOPBACK_ID: "{{ MS_LOOPBACK_ID }}" + ANYCAST_GW_MAC: "{{ _config.ANYCAST_GW_MAC }}" + MS_LOOPBACK_ID: "{{ _config.MS_LOOPBACK_ID }}" TOR_AUTO_DEPLOY: false FABRIC_TYPE: MFD FF: MSD @@ -59,11 +41,11 @@ MS_IFC_BGP_PASSWORD_ENABLE_PREV: "" MS_IFC_BGP_AUTH_KEY_TYPE_PREV: "" MS_IFC_BGP_PASSWORD_PREV: "" - BORDER_GWY_CONNECTIONS: "{{ BORDER_GWY_CONNECTIONS }}" + BORDER_GWY_CONNECTIONS: "{{ _config.BORDER_GWY_CONNECTIONS }}" RP_SERVER_IP: "" BGP_RP_ASN: "" - MS_UNDERLAY_AUTOCONFIG: "{{ MS_UNDERLAY_AUTOCONFIG }}" - DELAY_RESTORE: "{{ DELAY_RESTORE }}" + MS_UNDERLAY_AUTOCONFIG: "{{ _config.MS_UNDERLAY_AUTOCONFIG }}" + DELAY_RESTORE: "{{ _config.DELAY_RESTORE }}" CLOUDSEC_AUTOCONFIG: false CLOUDSEC_KEY_STRING: "" CLOUDSEC_ALGORITHM: "" @@ -72,8 +54,8 @@ MS_IFC_BGP_PASSWORD_ENABLE: false MS_IFC_BGP_PASSWORD: "" MS_IFC_BGP_AUTH_KEY_TYPE: "" - LOOPBACK100_IP_RANGE: "{{ LOOPBACK100_IP_RANGE }}" - DCI_SUBNET_RANGE: "{{ DCI_SUBNET_RANGE }}" - DCI_SUBNET_TARGET_MASK: "{{ DCI_SUBNET_TARGET_MASK }}" + LOOPBACK100_IP_RANGE: "{{ _config.LOOPBACK100_IP_RANGE }}" + DCI_SUBNET_RANGE: "{{ _config.DCI_SUBNET_RANGE }}" + DCI_SUBNET_TARGET_MASK: "{{ _config.DCI_SUBNET_TARGET_MASK }}" enableScheduledBackup: "" scheduledTime: "" diff --git a/roles/ndfc_rest_fabric_create/README.md b/roles/ndfc_rest_fabric_switch_create/README.md similarity index 91% rename from roles/ndfc_rest_fabric_create/README.md rename to roles/ndfc_rest_fabric_switch_create/README.md index 4296d14..eba89d7 100644 --- a/roles/ndfc_rest_fabric_create/README.md +++ b/roles/ndfc_rest_fabric_switch_create/README.md @@ -1,4 +1,4 @@ -# ndfc_rest_fabric_create +# ndfc_rest_fabric_switch_create Create fabric ``fabric_name`` @@ -24,7 +24,7 @@ See the following for details: - hosts: ndfc gather_facts: false roles: - - ndfc_rest_fabric_create + - ndfc_rest_fabric_switch_create vars: fabric_name: f1 ``` diff --git a/roles/ndfc_rest_fabric_create/defaults/main.yml b/roles/ndfc_rest_fabric_switch_create/defaults/main.yml similarity index 100% rename from roles/ndfc_rest_fabric_create/defaults/main.yml rename to roles/ndfc_rest_fabric_switch_create/defaults/main.yml diff --git a/roles/ndfc_rest_fabric_create/meta/main.yml b/roles/ndfc_rest_fabric_switch_create/meta/main.yml similarity index 100% rename from roles/ndfc_rest_fabric_create/meta/main.yml rename to roles/ndfc_rest_fabric_switch_create/meta/main.yml diff --git a/roles/ndfc_rest_fabric_create/tasks/main.yml b/roles/ndfc_rest_fabric_switch_create/tasks/main.yml similarity index 53% rename from roles/ndfc_rest_fabric_create/tasks/main.yml rename to roles/ndfc_rest_fabric_switch_create/tasks/main.yml index 1266270..0f6eb49 100644 --- a/roles/ndfc_rest_fabric_create/tasks/main.yml +++ b/roles/ndfc_rest_fabric_switch_create/tasks/main.yml @@ -1,16 +1,32 @@ -# ndfc_rest_fabric_create/tasks/main.yml +# ndfc_rest_fabric_switch_create/tasks/main.yml --- +- name: set_fact all_fabrics + ansible.builtin.set_fact: + all_fabrics: "{{ msd_fabrics | combine(switch_fabrics, external_fabrics) }}" + - ansible.builtin.include_role: - name: ndfc_rest_fabric_active_fabrics + name: ndfc_rest_fabric_active_fabrics_get + +# - name: set_fact BGP_AS +# ansible.builtin.set_fact: +# BGP_AS: "{{ all_fabrics.values() | list | json_query(mq1) }}" +# # BGP_AS: "{{ all_fabrics.values() | list }}" +# vars: +# mq1: "[?name == '{{ fabric_name }}'].BGP_AS | [0]" + +# - name: debug BGP_AS +# debug: +# var: BGP_AS + - name: main set_fact FABRIC {{ fabric_name }} set_fact: - BGP_AS: "{{ fabrics | json_query(mq1) }}" - ANYCAST_RP_IP_RANGE: "{{ fabrics | json_query(mq2) }}" - LOOPBACK0_IP_RANGE: "{{ fabrics | json_query(mq3) }}" - LOOPBACK1_IP_RANGE: "{{ fabrics | json_query(mq4) }}" - SUBNET_RANGE: "{{ fabrics | json_query(mq5) }}" - FABRIC_MTU: "{{ fabrics | json_query(mq6) }}" - REPLICATION_MODE: "{{ fabrics | json_query(mq7) }}" + BGP_AS: "{{ all_fabrics.values() | list | json_query(mq1) }}" + ANYCAST_RP_IP_RANGE: "{{ all_fabrics.values() | list | json_query(mq2) }}" + LOOPBACK0_IP_RANGE: "{{ all_fabrics.values() | list | json_query(mq3) }}" + LOOPBACK1_IP_RANGE: "{{ all_fabrics.values() | list | json_query(mq4) }}" + SUBNET_RANGE: "{{ all_fabrics.values() | list | json_query(mq5) }}" + FABRIC_MTU: "{{ all_fabrics.values() | list | json_query(mq6) }}" + REPLICATION_MODE: "{{ all_fabrics.values() | list | json_query(mq7) }}" vars: mq1: "[?name == '{{ fabric_name }}'].BGP_AS | [0]" mq2: "[?name == '{{ fabric_name }}'].ANYCAST_RP_IP_RANGE | [0]" @@ -27,6 +43,7 @@ json_data: "{{ vars_dict | to_json }}" when: "fabric_name not in active_fabrics" vars: + ansible_connection: httpapi vars_dict: BGP_AS: "{{ BGP_AS }}" ANYCAST_RP_IP_RANGE: "{{ ANYCAST_RP_IP_RANGE }}" diff --git a/roles/ndfc_rest_interface_no_shutdown/tasks/main.yml b/roles/ndfc_rest_interface_no_shutdown/tasks/main.yml index 20d1811..aeab956 100644 --- a/roles/ndfc_rest_interface_no_shutdown/tasks/main.yml +++ b/roles/ndfc_rest_interface_no_shutdown/tasks/main.yml @@ -1,8 +1,37 @@ -# ndfc_rest_interface_no_shutdown/tasks/main.yml ---- -- name: main rest_interface_no_shutdown FABRIC {{ fabric_name }} DEVICE {{ device_name }} INTERFACE {{ interface_name }} - include_tasks: worker.yml - loop: "{{ mr1 }}" +# ndfc_rest_interface_no_shutdown/tasks/worker.yml +- ansible.builtin.include_role: + name: ndfc_device_config_get + +- name: worker query FABRIC {{ device_config.switch_fabric }} NAME {{ device_config.name }} IP {{ device_config.ip }} + cisco.dcnm.dcnm_inventory: + fabric: "{{ device_config.switch_fabric }}" + state: query + config: + - seed_ip: "{{ device_config.ip }}" + register: wr1 vars: - mq1: "[?name == '{{ device_name }}'] | [?fabric == '{{ fabric_name }}']" - mr1: "{{ leafs | json_query(mq1) + spines | json_query(mq1) + border_gateways | json_query(mq1) }}" + ansible_connection: httpapi + +- ansible.builtin.include_role: + name: ndfc_device_serial_number_get + +- name: worker REST POST interface no_shutdown FABRIC {{ device_config.switch_fabric }} NAME {{ device_config.name }} IP {{ device_config.ip }} SERIAL {{ device_serial_number }} INTERFACE {{ interface_name }} payload {{ payload }} + cisco.dcnm.dcnm_rest: + method: POST + path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/interface/adminstatus" + json_data: "{{ payload | to_json }}" + vars: + ansible_connection: httpapi + payload: + operation: "noshut" + interfaces: + - serialNumber: "{{ device_serial_number }}" + ifName: "{{ interface_name }}" + when: "device_serial_number != ''" + +- ansible.builtin.include_role: + name: ndfc_rest_config_deploy + vars: + device_name: "{{ device_config.name }}" + fabric_name: "{{ device_config.switch_fabric }}" + when: "device_serial_number != ''" diff --git a/roles/ndfc_rest_interface_no_shutdown/tasks/worker.yml b/roles/ndfc_rest_interface_no_shutdown/tasks/worker.yml deleted file mode 100644 index 5b4e230..0000000 --- a/roles/ndfc_rest_interface_no_shutdown/tasks/worker.yml +++ /dev/null @@ -1,31 +0,0 @@ -# ndfc_rest_interface_no_shutdown/tasks/worker.yml -- name: worker query FABRIC {{ item.fabric }} NAME {{ item.name }} IP {{ item.ip }} - cisco.dcnm.dcnm_inventory: - fabric: "{{ item.fabric }}" - state: query - config: - - seed_ip: "{{ item.ip }}" - register: wr1 - -- name: worker set_fact device serial number - set_fact: - serial: "{{ wr1.response | json_query(q2) }}" - vars: - q2: "[0].serialNumber" - -- name: worker REST POST interface no_shutdown FABRIC {{ item.fabric }} NAME {{ item.name }} IP {{ item.ip }} SERIAL {{ serial }} INTERFACE {{ interface_name }} payload {{ payload }} - cisco.dcnm.dcnm_rest: - method: POST - path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/interface/adminstatus" - json_data: "{{ payload | to_json }}" - when: "serial != ''" - vars: - - payload: - operation: "noshut" - interfaces: - - serialNumber: "{{ serial }}" - ifName: "{{ interface_name }}" - -- ansible.builtin.include_role: - name: ndfc_rest_config_deploy_all - when: "serial != ''" diff --git a/roles/ndfc_rest_interface_shutdown/tasks/main.yml b/roles/ndfc_rest_interface_shutdown/tasks/main.yml index fec2782..35ce394 100644 --- a/roles/ndfc_rest_interface_shutdown/tasks/main.yml +++ b/roles/ndfc_rest_interface_shutdown/tasks/main.yml @@ -1,8 +1,35 @@ -# ndfc_rest_interface_shutdown/tasks/main.yml ---- -- name: main rest_interface_shutdown FABRIC {{ fabric_name }} DEVICE {{ device_name }} INTERFACE {{ interface_name }} - include_tasks: worker.yml - loop: "{{ mr1 }}" +# ndfc_rest_interface_shutdown/tasks/worker.yml +- ansible.builtin.include_role: + name: ndfc_device_config_get + +- name: worker query FABRIC {{ device_config.switch_fabric }} NAME {{ device_config.name }} IP {{ device_config.ip }} + cisco.dcnm.dcnm_inventory: + fabric: "{{ device_config.switch_fabric }}" + state: query + config: + - seed_ip: "{{ device_config.ip }}" + register: wr1 + +- ansible.builtin.include_role: + name: ndfc_device_serial_number_get + +- name: worker REST POST interface shutdown FABRIC {{ device_config.switch_fabric }} NAME {{ device_config.name }} IP {{ device_config.ip }} SERIAL {{ device_serial_number }} INTERFACE {{ interface_name }} payload {{ payload }} + cisco.dcnm.dcnm_rest: + method: POST + path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/interface/adminstatus" + json_data: "{{ payload | to_json }}" + when: "device_serial_number != ''" vars: - mq1: "[?name == '{{ device_name }}'] | [?fabric == '{{ fabric_name }}']" - mr1: "{{ leafs | json_query(mq1) + spines | json_query(mq1) + border_gateways | json_query(mq1) }}" + ansible_connection: httpapi + payload: + operation: "shut" + interfaces: + - serialNumber: "{{ device_serial_number }}" + ifName: "{{ interface_name }}" + +- ansible.builtin.include_role: + name: ndfc_rest_config_deploy + vars: + device_name: "{{ device_config.name }}" + fabric_name: "{{ device_config.switch_fabric }}" + when: "device_serial_number != ''" diff --git a/roles/ndfc_rest_interface_shutdown/tasks/worker.yml b/roles/ndfc_rest_interface_shutdown/tasks/worker.yml deleted file mode 100644 index b6641b2..0000000 --- a/roles/ndfc_rest_interface_shutdown/tasks/worker.yml +++ /dev/null @@ -1,31 +0,0 @@ -# ndfc_rest_interface_shutdown/tasks/worker.yml -- name: worker query FABRIC {{ item.fabric }} NAME {{ item.name }} IP {{ item.ip }} - cisco.dcnm.dcnm_inventory: - fabric: "{{ item.fabric }}" - state: query - config: - - seed_ip: "{{ item.ip }}" - register: wr1 - -- name: worker set_fact device serial number - set_fact: - serial: "{{ wr1.response | json_query(q2) }}" - vars: - q2: "[0].serialNumber" - -- name: worker REST POST interface shutdown FABRIC {{ item.fabric }} NAME {{ item.name }} IP {{ item.ip }} SERIAL {{ serial }} INTERFACE {{ interface_name }} payload {{ payload }} - cisco.dcnm.dcnm_rest: - method: POST - path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/interface/adminstatus" - json_data: "{{ payload | to_json }}" - when: "serial != ''" - vars: - - payload: - operation: "shut" - interfaces: - - serialNumber: "{{ serial }}" - ifName: "{{ interface_name }}" - -- ansible.builtin.include_role: - name: ndfc_rest_config_deploy_all - when: "serial != ''" diff --git a/roles/ndfc_rest_rediscover/README.md b/roles/ndfc_rest_rediscover/README.md index 013b2b1..969521d 100644 --- a/roles/ndfc_rest_rediscover/README.md +++ b/roles/ndfc_rest_rediscover/README.md @@ -7,7 +7,6 @@ Rediscover device ``device_name`` in fabric ``fabric_name`` Variable | Type | Description ----------------|-------|---------------------------------------- device_name | str() | The device to be rediscovered -fabric_name | str() | The fabric in which ``device_name`` resides Device and Fabric names are defined in the following file: diff --git a/roles/ndfc_rest_rediscover/tasks/main.yml b/roles/ndfc_rest_rediscover/tasks/main.yml index d91a84d..73f2826 100644 --- a/roles/ndfc_rest_rediscover/tasks/main.yml +++ b/roles/ndfc_rest_rediscover/tasks/main.yml @@ -1,8 +1,31 @@ -# ndfc_rest_rediscover/tasks/main.yml ---- -- name: main query FABRIC {{ fabric_name }} DEVICE {{ device_name }} - include_tasks: worker.yml - loop: "{{ mr1 }}" +# ndfc_rest_rediscover/tasks/worker.yml + +- ansible.builtin.include_role: + name: ndfc_device_config_get + +- name: worker query FABRIC {{ device_config.switch_fabric }} ROLE {{ device_config.role }} NAME {{ device_config.name }} IP {{ device_config.ip }} + cisco.dcnm.dcnm_inventory: + fabric: "{{ device_config.switch_fabric }}" + state: query + config: + - seed_ip: "{{ device_config.ip }}" + register: wr1 vars: - mq1: "[?name == '{{ device_name }}'] | [?fabric == '{{ fabric_name }}']" - mr1: "{{ leafs | json_query(mq1) + spines | json_query(mq1) + border_gateways | json_query(mq1) }}" + ansible_connection: httpapi + +- name: worker set_fact device_id FABRIC {{ device_config.switch_fabric }} ROLE {{ device_config.role }} NAME {{ device_config.name }} IP {{ device_config.ip }} + set_fact: + device_id: "{{ wr1.response | json_query(q2) | to_json }}" + vars: + q2: "[0].switchDbID" + +- name: worker REST POST rediscoverSwitch FABRIC {{ device_config.switch_fabric }} ROLE {{ device_config.role }} NAME {{ device_config.name }} IP {{ device_config.ip }} DEVICE_ID {{ device_id }} + cisco.dcnm.dcnm_rest: + method: POST + path: "/appcenter/cisco/ndfc/api/v1/lan-discovery/rediscoverSwitch" + json_data: "{{ vars_list | to_json }}" + when: "device_id != None" + vars: + ansible_connection: httpapi + vars_list: + - "{{ device_id }}" diff --git a/roles/ndfc_rest_rediscover/tasks/worker.yml b/roles/ndfc_rest_rediscover/tasks/worker.yml deleted file mode 100644 index d95ad4d..0000000 --- a/roles/ndfc_rest_rediscover/tasks/worker.yml +++ /dev/null @@ -1,24 +0,0 @@ -# ndfc_rest_rediscover/tasks/worker.yml -- name: worker query FABRIC {{ item.fabric }} ROLE {{ item.role }} NAME {{ item.name }} IP {{ item.ip }} - cisco.dcnm.dcnm_inventory: - fabric: "{{ item.fabric }}" - state: query - config: - - seed_ip: "{{ item.ip }}" - register: wr1 - -- name: worker set_fact device_id FABRIC {{ item.fabric }} ROLE {{ item.role }} NAME {{ item.name }} IP {{ item.ip }} - set_fact: - device_id: "{{ wr1.response | json_query(q2) | to_json }}" - vars: - q2: "[0].switchDbID" - -- name: worker REST POST rediscoverSwitch FABRIC {{ item.fabric }} ROLE {{ item.role }} NAME {{ item.name }} IP {{ item.ip }} DEVICE_ID {{ device_id }} - cisco.dcnm.dcnm_rest: - method: POST - path: "/appcenter/cisco/ndfc/api/v1/lan-discovery/rediscoverSwitch" - json_data: "{{ vars_list | to_json }}" - when: "device_id != None" - vars: - vars_list: - - "{{ device_id }}" diff --git a/roles/ndfc_rest_service_node_add/README.md b/roles/ndfc_rest_service_node_add/README.md index d7715b1..a6dba36 100644 --- a/roles/ndfc_rest_service_node_add/README.md +++ b/roles/ndfc_rest_service_node_add/README.md @@ -18,7 +18,7 @@ ndfc_service_node_create | firewall, load_balancer, virtual_network_function Variable | Type | Description ------------------|-------|---------------------------------------- -service_node_name | str() | The service node to create +service_node_name | str() | The service node to add Service node parameters are defined in the following file under ``service_nodes` diff --git a/roles/ndfc_rest_service_node_add/tasks/main.yml b/roles/ndfc_rest_service_node_add/tasks/main.yml index 95ed943..35c3b0e 100644 --- a/roles/ndfc_rest_service_node_add/tasks/main.yml +++ b/roles/ndfc_rest_service_node_add/tasks/main.yml @@ -1,26 +1,26 @@ # ndfc_rest_service_node_add/tasks/main.yml --- - ansible.builtin.include_role: - name: ndfc_rest_fabric_active_fabrics + name: ndfc_rest_fabric_active_fabrics_get - name: worker set_fact service_node {{ service_node_name }} set_fact: - external_fabric_name: "{{ service_nodes | json_query(mq2) }}" - service_node_type: "{{ service_nodes | json_query(mq3) }}" - service_node_form_factor: "{{ service_nodes | json_query(mq4) }}" - service_node_peer_name: "{{ service_nodes | json_query(mq5) }}" - service_node_interface_name: "{{ service_nodes | json_query(mq6) }}" - attached_fabric_name: "{{ service_nodes | json_query(mq7) }}" - attached_switch_name: "{{ service_nodes | json_query(mq8) }}" - attached_switch_interface_name: "{{ service_nodes | json_query(mq9) }}" - vpc_switches_attached: "{{ service_nodes | json_query(mq10) }}" - link_template_name: "{{ service_nodes | json_query(mq11) }}" - interface_speed: "{{ service_nodes | json_query(mq12) }}" - interface_mtu: "{{ service_nodes | json_query(mq13) }}" - interface_allowed_vlans: "{{ service_nodes | json_query(mq14) }}" - interface_bpduguard_enabled: "{{ service_nodes | json_query(mq15) }}" - interface_porttype_fast_enabled: "{{ service_nodes | json_query(mq16) }}" - interface_admin_state: "{{ service_nodes | json_query(mq17) }}" + external_fabric_name: "{{ service_nodes.values() | list | json_query(mq2) }}" + service_node_type: "{{ service_nodes.values() | list | json_query(mq3) }}" + service_node_form_factor: "{{ service_nodes.values() | list | json_query(mq4) }}" + service_node_peer_name: "{{ service_nodes.values() | list | json_query(mq5) }}" + service_node_interface_name: "{{ service_nodes.values() | list | json_query(mq6) }}" + attached_fabric_name: "{{ service_nodes.values() | list | json_query(mq7) }}" + attached_switch_name: "{{ service_nodes.values() | list | json_query(mq8) }}" + attached_switch_interface_name: "{{ service_nodes.values() | list | json_query(mq9) }}" + vpc_switches_attached: "{{ service_nodes.values() | list | json_query(mq10) }}" + link_template_name: "{{ service_nodes.values() | list | json_query(mq11) }}" + interface_speed: "{{ service_nodes.values() | list | json_query(mq12) }}" + interface_mtu: "{{ service_nodes.values() | list | json_query(mq13) }}" + interface_allowed_vlans: "{{ service_nodes.values() | list | json_query(mq14) }}" + interface_bpduguard_enabled: "{{ service_nodes.values() | list | json_query(mq15) }}" + interface_porttype_fast_enabled: "{{ service_nodes.values() | list | json_query(mq16) }}" + interface_admin_state: "{{ service_nodes.values() | list | json_query(mq17) }}" vars: mq2: "[?service_node_name == '{{ service_node_name }}'].external_fabric_name | [0]" mq3: "[?service_node_name == '{{ service_node_name }}'].service_node_type | [0]" @@ -53,6 +53,7 @@ json_data: "{{ vars_dict | to_json }}" when: "attached_fabric_name in active_fabrics" vars: + ansible_connection: httpapi vars_dict: fabricName: "{{ external_fabric_name }}" # required e.g. "myExtFabric" name: "{{ service_node_name }}" # required e.g. "myServiceNode1" diff --git a/roles/ndfc_service_node_deleted/tasks/main.yml b/roles/ndfc_service_node_deleted/tasks/main.yml index 3f294c9..a0aa79c 100644 --- a/roles/ndfc_service_node_deleted/tasks/main.yml +++ b/roles/ndfc_service_node_deleted/tasks/main.yml @@ -1,17 +1,17 @@ # ndfc_rest_service_node_deleted/tasks/main.yml --- - ansible.builtin.include_role: - name: ndfc_rest_fabric_active_fabrics + name: ndfc_rest_fabric_active_fabrics_get - name: worker set_fact service_node {{ service_node_name }} set_fact: - external_fabric_name: "{{ service_nodes | json_query(mq2) }}" - service_node_type: "{{ service_nodes | json_query(mq3) }}" - service_node_form_factor: "{{ service_nodes | json_query(mq4) }}" - service_node_interface_name: "{{ service_nodes | json_query(mq6) }}" - attached_fabric_name: "{{ service_nodes | json_query(mq7) }}" - attached_switch_name: "{{ service_nodes | json_query(mq8) }}" - attached_switch_interface_name: "{{ service_nodes | json_query(mq9) }}" + external_fabric_name: "{{ service_nodes.values() | list | json_query(mq2) }}" + service_node_type: "{{ service_nodes.values() | list | json_query(mq3) }}" + service_node_form_factor: "{{ service_nodes.values() | list | json_query(mq4) }}" + service_node_interface_name: "{{ service_nodes.values() | list | json_query(mq6) }}" + attached_fabric_name: "{{ service_nodes.values() | list | json_query(mq7) }}" + attached_switch_name: "{{ service_nodes.values() | list | json_query(mq8) }}" + attached_switch_interface_name: "{{ service_nodes.values() | list | json_query(mq9) }}" vars: mq2: "[?service_node_name == '{{ service_node_name }}'].external_fabric_name | [0]" mq3: "[?service_node_name == '{{ service_node_name }}'].service_node_type | [0]" @@ -22,9 +22,8 @@ mq9: "[?service_node_name == '{{ service_node_name }}'].attached_switch_interface_name | [0]" - ansible.builtin.include_role: - name: ndfc_device_ipv4_address_get + name: ndfc_device_ipv4_address_local_get vars: - fabric_name: "{{ attached_fabric_name }}" device_name: "{{ attached_switch_name }}" - name: main service_node_deleted attached_fabric_name {{ attached_fabric_name }} service_node {{ service_node_name }} type {{ service_node_type | lower }} form_factor {{ service_node_form_factor | lower }} ipv4 {{ device_ipv4_address }} @@ -40,3 +39,5 @@ attach_interface: "{{ attached_switch_interface_name }}" switches: - "{{ device_ipv4_address }}" + vars: + ansible_connection: httpapi diff --git a/roles/ndfc_service_node_merged/tasks/main.yml b/roles/ndfc_service_node_merged/tasks/main.yml index 7306cfb..d53cdc7 100644 --- a/roles/ndfc_service_node_merged/tasks/main.yml +++ b/roles/ndfc_service_node_merged/tasks/main.yml @@ -1,17 +1,17 @@ # ndfc_rest_service_node_merged/tasks/main.yml --- - ansible.builtin.include_role: - name: ndfc_rest_fabric_active_fabrics + name: ndfc_rest_fabric_active_fabrics_get - name: worker set_fact service_node {{ service_node_name }} set_fact: - external_fabric_name: "{{ service_nodes | json_query(mq2) }}" - service_node_type: "{{ service_nodes | json_query(mq3) }}" - service_node_form_factor: "{{ service_nodes | json_query(mq4) }}" - service_node_interface_name: "{{ service_nodes | json_query(mq6) }}" - attached_fabric_name: "{{ service_nodes | json_query(mq7) }}" - attached_switch_name: "{{ service_nodes | json_query(mq8) }}" - attached_switch_interface_name: "{{ service_nodes | json_query(mq9) }}" + external_fabric_name: "{{ service_nodes.values() | list | json_query(mq2) }}" + service_node_type: "{{ service_nodes.values() | list | json_query(mq3) }}" + service_node_form_factor: "{{ service_nodes.values() | list | json_query(mq4) }}" + service_node_interface_name: "{{ service_nodes.values() | list | json_query(mq6) }}" + attached_fabric_name: "{{ service_nodes.values() | list | json_query(mq7) }}" + attached_switch_name: "{{ service_nodes.values() | list | json_query(mq8) }}" + attached_switch_interface_name: "{{ service_nodes.values() | list | json_query(mq9) }}" vars: mq2: "[?service_node_name == '{{ service_node_name }}'].external_fabric_name | [0]" mq3: "[?service_node_name == '{{ service_node_name }}'].service_node_type | [0]" @@ -22,9 +22,8 @@ mq9: "[?service_node_name == '{{ service_node_name }}'].attached_switch_interface_name | [0]" - ansible.builtin.include_role: - name: ndfc_device_ipv4_address_get + name: ndfc_device_ipv4_address_local_get vars: - fabric_name: "{{ attached_fabric_name }}" device_name: "{{ attached_switch_name }}" - name: main service_node_merged attached_fabric_name {{ attached_fabric_name }} service_node {{ service_node_name }} type {{ service_node_type | lower }} form_factor {{ service_node_form_factor | lower }} ipv4 {{ device_ipv4_address }} @@ -40,3 +39,5 @@ attach_interface: "{{ attached_switch_interface_name }}" switches: - "{{ device_ipv4_address }}" + vars: + ansible_connection: httpapi diff --git a/roles/ndfc_vpc_interface_merged_all/README.md b/roles/ndfc_vpc_interface_merged_all/README.md index 530a49d..a035e6d 100644 --- a/roles/ndfc_vpc_interface_merged_all/README.md +++ b/roles/ndfc_vpc_interface_merged_all/README.md @@ -1,23 +1,17 @@ # ndfc_vpc_interface_merged_all -Merge all vpc interfaces for vpc peer ``vpc_name`` in fabric ``fabric_name`` +Merge all vpc interfaces for vpc peer ``vpc_name`` ### Role Variables Variable | Type | Description ----------------|-------|---------------------------------------- -fabric_name | str() | The fabric in which ``vpc_name`` resides -vpc_name | str() | The name of the vpc peering to create +vpc_name | str() | The name of the vpc peer for which interfaces will be merged -``fabric_name`` and ``vpc_name`` are defined in the following file: +``vpc_name`` is defined in the following file within the ``vpc_peers`` dictionary: ``./roles/ndfc_common/vars/main.yml`` -Specifically: - -``fabric_name`` is defined in the ``fabrics`` list - -``vpc_name`` is defined in the ``vpc_peers`` list See the following for details: diff --git a/roles/ndfc_vpc_interface_merged_all/tasks/main.yml b/roles/ndfc_vpc_interface_merged_all/tasks/main.yml index 71e4ab1..12c6ef4 100644 --- a/roles/ndfc_vpc_interface_merged_all/tasks/main.yml +++ b/roles/ndfc_vpc_interface_merged_all/tasks/main.yml @@ -1,6 +1,6 @@ # ndfc_vpc_interface_merged_all/tasks/main.yml - name: main merged FABRIC {{ fabric_name }} VPC {{ vpc_name }} vpc_interface include_tasks: worker.yml - loop: "{{ vpc_interfaces | json_query(mq1) }}" + loop: "{{ vpc_interfaces.values() | list | json_query(mq1) }}" vars: - mq1: "[?fabric == '{{ fabric_name }}'] | [?vpc_name == '{{ vpc_name }}']" + mq1: "[?vpc_name == '{{ vpc_name }}']" diff --git a/roles/ndfc_vpc_interface_merged_all/tasks/worker.yml b/roles/ndfc_vpc_interface_merged_all/tasks/worker.yml index 7d6cd76..4270bae 100644 --- a/roles/ndfc_vpc_interface_merged_all/tasks/worker.yml +++ b/roles/ndfc_vpc_interface_merged_all/tasks/worker.yml @@ -14,8 +14,10 @@ - seed_ip: "{{ ip }}" register: wr1 vars: + ansible_connection: httpapi wq1: "[?fabric == '{{ item.fabric }}'] | [?vpc_name == '{{ item.vpc_name }}'].peer_1_ip | [0]" - ip: "{{ vpc_peers | json_query(wq1)}}" + ip: "{{ vpc_peers.values() | list | json_query(wq1)}}" + - name: worker set_fact {{ item.fabric }} {{ item.vpc_name }} {{ item.vpc_port_id }} - p1_serial, p1_vpc, p1_db_id, p1_ip set_fact: p1_serial: "{{ wr1.response | json_query(wq2) }}" @@ -37,8 +39,9 @@ - seed_ip: "{{ ip }}" register: wr2 vars: + ansible_connection: httpapi wq6: "[?fabric == '{{ item.fabric }}'] | [?vpc_name == '{{ item.vpc_name }}'].peer_2_ip | [0]" - ip: "{{ vpc_peers | json_query(wq6)}}" + ip: "{{ vpc_peers.values() | list | json_query(wq6)}}" - name: worker set_fact {{ item.fabric }} {{ item.vpc_name }} {{ item.vpc_port_id }} - p2_serial, p2_vpc, p2_db_id, p2_ip set_fact: @@ -76,3 +79,5 @@ peer2_allowed_vlans: "{{ item.peer2_allowed_vlans }}" peer1_description: "{{ item.vpc_port_id }} {{ item.interface_mode }}" peer2_description: "{{ item.vpc_port_id }} {{ item.interface_mode }}" + vars: + ansible_connection: httpapi diff --git a/roles/ndfc_vrf_all/tasks/main.yml b/roles/ndfc_vrf_all/tasks/main.yml index fb697e7..ee3c595 100644 --- a/roles/ndfc_vrf_all/tasks/main.yml +++ b/roles/ndfc_vrf_all/tasks/main.yml @@ -2,6 +2,6 @@ --- - name: main {{ state }} FABRIC {{ fabric_name }} include_tasks: worker.yml - loop: "{{ vrfs | json_query(mq1) }}" + loop: "{{ vrfs.values() | list | json_query(mq1) }}" vars: mq1: "[?fabric == '{{ fabric_name }}']" diff --git a/roles/ndfc_vrf_config_get/README.md b/roles/ndfc_vrf_config_get/README.md new file mode 100644 index 0000000..ac4d7b0 --- /dev/null +++ b/roles/ndfc_vrf_config_get/README.md @@ -0,0 +1,42 @@ +# ndfc_device_deleted + +Delete device ``device_name`` from fabric ``fabric_name`` using ``cisco.dcnm.dcnm_inventory`` + +### Role Variables + +Variable | Type | Description +----------------|-------|---------------------------------------- +device_name | str() | The device to be deleted +fabric_name | str() | The fabric in which device_name resides + +Device and fabric names are defined in the following file: + +``./roles/ndfc_common/vars/main.yml``) + +See the following for details: + +[./roles/ndfc_common/README.md](https://github.com/allenrobel/ndfc-roles/tree/master/roles/ndfc_common/README.md) + + +### Example Playbook + +```yaml +--- +- hosts: ndfc + gather_facts: false + roles: + - ndfc_device_deleted + vars: + fabric_name: f1 + device_name: spine_1 +``` + +### Licensing + +GNU General Public License v3.0 or later. + +See [LICENSE](https://www.gnu.org/licenses/gpl-3.0.txt) for full text. + +### Author Information + +Allen Robel (@packetcalc) diff --git a/roles/ndfc_vrf_config_get/meta/main.yml b/roles/ndfc_vrf_config_get/meta/main.yml new file mode 100644 index 0000000..699d071 --- /dev/null +++ b/roles/ndfc_vrf_config_get/meta/main.yml @@ -0,0 +1,11 @@ +galaxy_info: + author: Allen Robel + description: Principal Engineer + company: Cisco Systems, Inc. + license: license (GPL-2.0-or-later, MIT, etc) + min_ansible_version: 2.1 + galaxy_tags: + - ndfc + - cisco +dependencies: + - ndfc_common diff --git a/roles/ndfc_vrf_config_get/tasks/main.yml b/roles/ndfc_vrf_config_get/tasks/main.yml new file mode 100644 index 0000000..c76d7c0 --- /dev/null +++ b/roles/ndfc_vrf_config_get/tasks/main.yml @@ -0,0 +1,7 @@ +# ndfc_vrf_config_get/tasks/main.yml +--- +- name: set_fact vrf_config {{ vrf_name }} + ansible.builtin.set_fact: + vrf_config: "{{ vrfs | json_query(vrf_config_get_q1) }}" + vars: + vrf_config_get_q1: "{{ vrf_name }}" diff --git a/roles/ndfc_vrf_config_get/vars/main.yml b/roles/ndfc_vrf_config_get/vars/main.yml new file mode 100644 index 0000000..f2bcdf0 --- /dev/null +++ b/roles/ndfc_vrf_config_get/vars/main.yml @@ -0,0 +1 @@ +ansible_connection: local diff --git a/roles/ndfc_vrf_query/README.md b/roles/ndfc_vrf_query/README.md index ea753f7..0d8a79a 100644 --- a/roles/ndfc_vrf_query/README.md +++ b/roles/ndfc_vrf_query/README.md @@ -1,18 +1,59 @@ # ndfc_vrf_query -Query VRF ``vrf_name`` in fabric ``fabric_name`` and return json object ``info`` +Query VRF ``vrf_name`` and return json object ``vrf_info`` which contains vrf information for ``vrf_name`` from the NDFC controller. ### Role Variables Variable | Type | Description ----------------|-------|---------------------------------------- -fabric_name | str() | The fabric in which ``vrf_name`` resides -vrf_name | str() | The vrf to query +vrf_name | str() | The vrf to query. -Fabric and vrf parameters, including ``fabric_name`` and ``vrf_name``, are defined in the following file: +vrf parameters, including ``vrf_name``, are defined in the following file: ``./roles/ndfc_common/vars/main.yml`` +NOTE, ``vrf_name`` above corresponds to the ``name:`` key within the vrfs dictionary in the file noted above. The ``name:`` key is unique across all defined vrfs, whereas the ``vrf_name:`` key is not unique and cannot be used with this role. By way of example, in the entry below, you would use the value of ``name:`` rather than the value of ``vrf_name``. The example playbook below shows the correct value to use. + +#### Example entry in the vrfs dictionary + +```yaml + f2_v1: + name: f2_v1 + fabric: "{{ switch_fabrics.f2.name }}" + vrf_name: v1 + vrf_id: 63031 + vlan_id: 3031 + vrf_template: Default_VRF_Universal + vrf_extension_template: Default_VRF_Extension_Universal + service_vrf_template: null + attach: + - ip_address: "{{ devices.leaf_5.ip }}" + - ip_address: "{{ devices.leaf_6.ip }}" + - ip_address: "{{ devices.leaf_7.ip }}" + - ip_address: "{{ devices.leaf_8.ip }}" +``` + +#### Example playbook to query the above vrf + +```yaml +--- +- hosts: ndfc + gather_facts: false + roles: + - ndfc_vrf_query + vars: + vrf_name: f2_v1 + tasks: + - debug: + msg: "vrf_info.parent.fabric: {{ vrf_info.parent.fabric }}" + - debug: + msg: "vrf_info.parent.vrfId: {{ vrf_info.parent.vrfId }}" + - debug: + msg: "vrf_info.parent.vrfStatus: {{ vrf_info.parent.vrfStatus }}" +``` + + + See the following for details: [./roles/ndfc_common/README.md](https://github.com/allenrobel/ndfc-roles/tree/master/roles/ndfc_common/README.md) @@ -26,16 +67,15 @@ See the following for details: roles: - ndfc_vrf_query vars: - fabric_name: f1 - vrf_name: v1 + vrf_name: msd_v2 tasks: - block: - debug: - msg: "info.parent.fabric: {{ info.parent.fabric }}" + msg: "vrf_info.parent.fabric: {{ vrf_info.parent.fabric }}" - debug: - msg: "info.parent.vrfId: {{ info.parent.vrfId }}" + msg: "vrf_info.parent.vrfId: {{ vrf_info.parent.vrfId }}" - debug: - msg: "info.parent.vrfStatus: {{ info.parent.vrfStatus }}" + msg: "vrf_info.parent.vrfStatus: {{ vrf_info.parent.vrfStatus }}" ``` ### Licensing diff --git a/roles/ndfc_vrf_query/tasks/main.yml b/roles/ndfc_vrf_query/tasks/main.yml index f876ed8..3a9d2ea 100644 --- a/roles/ndfc_vrf_query/tasks/main.yml +++ b/roles/ndfc_vrf_query/tasks/main.yml @@ -1,8 +1,20 @@ -# ndfc_vrf_replaced/tasks/main.yml +# ndfc_vrf_query/tasks/worker.yml --- -- name: main query FABRIC {{ fabric_name }} VRF {{ vrf_name }} - include_tasks: worker.yml - loop: "{{ mr1 }}" +- ansible.builtin.include_role: + name: ndfc_vrf_config_get + +- name: worker query FABRIC {{ vrf_config.fabric }} VRF {{ vrf_config.vrf_name }} + cisco.dcnm.dcnm_vrf: + fabric: "{{ vrf_config.fabric }}" + state: query + config: + - vrf_name: "{{ vrf_config.vrf_name }}" + register: mr1 vars: - mq1: "[?fabric == '{{ fabric_name }}'] | [?vrf_name == '{{ vrf_name }}']" - mr1: "{{ vrfs | json_query(mq1) }}" + ansible_connection: httpapi + +# playbooks can cull information from the vrf_info object +- name: set_fact info + set_fact: + vrf_info: "{{ mr1.response[0] }}" + diff --git a/roles/ndfc_vrf_query/tasks/worker.yml b/roles/ndfc_vrf_query/tasks/worker.yml deleted file mode 100644 index 978dd98..0000000 --- a/roles/ndfc_vrf_query/tasks/worker.yml +++ /dev/null @@ -1,13 +0,0 @@ -# ndfc_vrf_query/tasks/worker.yml -- name: worker query FABRIC {{ item.fabric }} VRF {{ item.vrf_name }} - cisco.dcnm.dcnm_vrf: - fabric: "{{ item.fabric }}" - state: query - config: - - vrf_name: "{{ item.vrf_name }}" - register: mr1 - -# playbooks can cull information from the info object -- name: set_fact info - set_fact: - info: "{{ mr1.response[0] }}" diff --git a/roles/ndfc_vrf_replaced/README.md b/roles/ndfc_vrf_replaced/README.md index 49fe1ce..d4bb31d 100644 --- a/roles/ndfc_vrf_replaced/README.md +++ b/roles/ndfc_vrf_replaced/README.md @@ -6,14 +6,15 @@ Replace vrf ``vrf_name`` in fabric ``fabric_name`` with the current user-defined Variable | Type | Description ----------------|-------|---------------------------------------- -fabric_name | str() | The fabric in which ``vrf_name`` resides vrf_name | str() | The vrf to update -Fabric and vrf parameters, including ``fabric_name`` and ``vrf_name``, are defined in the following file: +NOTE, ``vrf_name`` above corresponds to the ``name:`` key within the vrfs dictionary in the file noted below. The ``name:`` key is unique across all defined vrfs, whereas the ``vrf_name:`` key is not unique and cannot be used with this role. See the example vrf entry and playbook below which demonstrate the value to use in your playbook. + +The parameter ``vrf_name`` is defined in the ``vrfs`` dictionary in following file: ``./roles/ndfc_common/vars/main.yml`` -Specifically, vrfs are defined in the ``vrfs`` list in the above file. User-defined parameters include: +User parameters in the the ``vrfs`` dictionary include: Variable | Example | Type | Description -----------------------|----------------|--------------|------------------- @@ -27,29 +28,31 @@ service_vrf_template | ServiceVrf | str() | Service vrf template attach | See example | list of dict | List of mgmt0 ip addresses of switches on which the VRF is configured attach.ip_address | 192.168.1.1 | IP address | mgmt0 address of the switch to which the vrf is attached -Example entry in vrfs list: +#### Example entry in vrfs dictionary ```yaml vrfs: -- fabric: "{{ fabrics[0].name }}" - vrf_name: v1 - vrf_id: 9003031 - vlan_id: 3031 - vrf_template: Default_VRF_Universal - vrf_extension_template: Default_VRF_Extension_Universal - service_vrf_template: null - attach: - - ip_address: "{{ leafs[0].ip }}" - - ip_address: "{{ leafs[1].ip }}" - - ip_address: "{{ leafs[2].ip }}" - - ip_address: "{{ leafs[3].ip }}" + f2_v1: + name: f2_v1 + fabric: "{{ switch_fabrics.f2.name }}" + vrf_name: v1 + vrf_id: 63031 + vlan_id: 3031 + vrf_template: Default_VRF_Universal + vrf_extension_template: Default_VRF_Extension_Universal + service_vrf_template: null + attach: + - ip_address: "{{ devices.leaf_5.ip }}" + - ip_address: "{{ devices.leaf_6.ip }}" + - ip_address: "{{ devices.leaf_7.ip }}" + - ip_address: "{{ devices.leaf_8.ip }}" ``` See the following for details: [./roles/ndfc_common/README.md](https://github.com/allenrobel/ndfc-roles/tree/master/roles/ndfc_common/README.md) -## Example Playbook +## Example Playbook (referencing the above example vrf entry) ```yaml --- @@ -58,8 +61,7 @@ See the following for details: roles: - ndfc_vrf_replaced vars: - fabric_name: f1 - vrf_name: v2 + vrf_name: f2_v1 ``` ### Licensing diff --git a/roles/ndfc_vrf_replaced/tasks/main.yml b/roles/ndfc_vrf_replaced/tasks/main.yml index a49d8f7..f0d3a39 100644 --- a/roles/ndfc_vrf_replaced/tasks/main.yml +++ b/roles/ndfc_vrf_replaced/tasks/main.yml @@ -1,8 +1,16 @@ -# ndfc_vrf_replaced/tasks/main.yml ---- -- name: main replaced FABRIC {{ fabric_name }} VRF {{ vrf_name }} - include_tasks: worker.yml - loop: "{{ mr1 }}" - vars: - mq1: "[?fabric == '{{ fabric_name }}'] | [?vrf_name == '{{ vrf_name }}']" - mr1: "{{ vrfs | json_query(mq1) }}" +# ndfc_vrf_replaced/tasks/worker.yml +- ansible.builtin.include_role: + name: ndfc_vrf_config_get + +- name: replaced FABRIC {{ vrf_config.fabric }} VRF {{ vrf_config.vrf_name }} VRF_ID {{ vrf_config.vrf_id }} VLAN {{ vrf_config.vlan_id }} + cisco.dcnm.dcnm_vrf: + fabric: "{{ vrf_config.fabric }}" + state: replaced + config: + - vrf_name: "{{ vrf_config.vrf_name }}" + vrf_id: "{{ vrf_config.vrf_id }}" + vlan_id: "{{ vrf_config.vlan_id }}" + vrf_template: Default_VRF_Universal + vrf_extension_template: Default_VRF_Extension_Universal + service_vrf_template: null + attach: "{{ vrf_config.attach }}" diff --git a/roles/ndfc_vrf_replaced/tasks/worker.yml b/roles/ndfc_vrf_replaced/tasks/worker.yml deleted file mode 100644 index 8586b44..0000000 --- a/roles/ndfc_vrf_replaced/tasks/worker.yml +++ /dev/null @@ -1,13 +0,0 @@ -# ndfc_vrf_replaced/tasks/worker.yml -- name: worker replaced FABRIC {{ item.fabric }} VRF {{ item.vrf_name }} VRF_ID {{ item.vrf_id }} VLAN {{ item.vlan_id }} - cisco.dcnm.dcnm_vrf: - fabric: "{{ item.fabric }}" - state: replaced - config: - - vrf_name: "{{ item.vrf_name }}" - vrf_id: "{{ item.vrf_id }}" - vlan_id: "{{ item.vlan_id }}" - vrf_template: Default_VRF_Universal - vrf_extension_template: Default_VRF_Extension_Universal - service_vrf_template: null - attach: "{{ item.attach }}"