Reset
Fabric
Tasks

Step 1 - Close Fabric Overview in NDFC

Return to NDFC and close the fabric overview:

After closing the fabric view, you should be back at the main NDFC Fabrics dashboard:


Step 2 - Create Ansible Playbook to Reset the Staging Fabric

Return to your VSCode window.

This step is to create a quick Ansible playbook to wipe and remove the staging fabric. This step is performed so that your NDFC instance starts with a clean slate and no fabrics. The idea in this section is to demonstrate how you can use an existing framework, Ansible in this case, in different ways and in preparation for the next section that is fully declarative in intent.


touch ~/workspace/ndfclab/ansible/reset.yml  
cat << EOF > ~/workspace/ndfclab/ansible/reset.yml 
---
# This Ansible playbook is used to reset NDFC by removing all switches and fabrics.

- name: Reset NDFC Fabric(s)
  hosts: ndfc
  gather_facts: false

  tasks:
    - name: Set NDFC Reset Control Variable
      ansible.builtin.set_fact:
        fabric_reset: False

    - name: Get Current NDFC Fabric(s)
      cisco.dcnm.dcnm_rest:
        method: GET
        path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics"
      register: result

    - name: Display Current NDFC Fabrics
      ansible.builtin.debug:
        msg: "{{ item.fabricName }}"
      loop: "{{ result.response.DATA }}"
      loop_control:
        label: "{{ item.fabricName }}"

    - name: Display Count of Current NDFC Fabrics
      ansible.builtin.debug:
        msg: "Number of NDFC Fabrics - {{ result.response.DATA | length }}"

    - name: Update NDFC Reset Control Variable if Fabric(s) Exist
      ansible.builtin.set_fact:
        fabric_reset: True
      when: result.response.DATA | length >= 1

    - name: Get Current NDFC Fabrics from Response and Remove if Any Fabrics Exist
      when: fabric_reset
      block:
        # This is another way to create a list of items from a response using JSON Path Query
        # - name: Get Current NDFC Fabrics from Response using a JSON Path Query
        #   ansible.builtin.set_fact:
        #     current_fabrics: "{{ result.response.DATA | community.general.json_query('[*].fabricName') }}"

        - name: Remove Switches from Fabrics in NDFC
          cisco.dcnm.dcnm_inventory:
            fabric: "{{ item.fabricName }}"
            state: deleted
          loop: "{{ result.response.DATA }}"
          loop_control:
            label: "{{ item.fabricName }}"

        - name: Delete Current Fabrics from NDFC
          cisco.dcnm.dcnm_fabric:
            config: >-
              {%- set current_fabrics = [] -%}
              {%- set fabrics = result.response.DATA | community.general.json_query('[*].fabricName') -%}
              {%- for fabric in fabrics | default([]) -%}
              {%- set _ = current_fabrics.append(dict(FABRIC_NAME=fabric)) -%}
              {%- endfor -%}
              {{ current_fabrics }}
            state: deleted

        # This is another method to delete fabrics using the fallback cisco.dcnm.dcnm_rest module
        # - name: Delete Current Fabrics from NDFC
        #   cisco.dcnm.dcnm_rest:
        #     method: DELETE
        #     path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics/{{ item.fabricName }}"
        #   loop: "{{ result.response.DATA }}"
        #   loop_control:
        #     label: "{{ item.fabricName }}"

    - name: Get Current NDFC Fabric(s)
      cisco.dcnm.dcnm_rest:
        method: GET
        path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics"
      register: result

    - name: Display Count of Current NDFC Fabrics
      ansible.builtin.debug:
        msg: "Number of NDFC Fabrics - {{ result.response.DATA | length }}"

EOF


Step 3 - Execute Ansible Playbook to Reset the Staging Fabric

From the root ansible project directory execute the following command.


cd ~/workspace/ndfclab/ansible


ansible-playbook -i hosts.stage.yml reset.yml

Upon a successful run of the playbook your output should look as follows:

  PLAY [Reset NDFC Fabric(s)] *********************************************************************************************************************************************************************************************

  TASK [Set NDFC Reset Control Variable] **********************************************************************************************************************************************************************************
  ok: [10.15.0.11]

  TASK [Get Current NDFC Fabric(s)] ***************************************************************************************************************************************************************************************
  ok: [10.15.0.11]

  TASK [Display Current NDFC Fabrics] *************************************************************************************************************************************************************************************
  ok: [10.15.0.11] => (item=fabric-stage) => {
      "msg": "fabric-stage"
  }

  TASK [Display Count of Current NDFC Fabrics] ****************************************************************************************************************************************************************************
  ok: [10.15.0.11] => {
      "msg": "Number of NDFC Fabrics - 1"
  }

  TASK [Update NDFC Reset Control Variable if Fabric(s) Exist] ************************************************************************************************************************************************************
  ok: [10.15.0.11]

  TASK [Remove Switches from Fabrics in NDFC] ********************************************************************************************************************************************************
  changed: [10.15.0.11] => (item=fabric-stage)

  TASK [Delete Current Fabrics from NDFC] *********************************************************************************************************************************************************************************
  changed: [10.15.0.11]

  TASK [Get Current NDFC Fabric(s)] ***************************************************************************************************************************************************************************************
  ok: [10.15.0.11]

  TASK [Display Count of Current NDFC Fabrics] ****************************************************************************************************************************************************************************
  ok: [10.15.0.11] => {
      "msg": "Number of NDFC Fabrics - 0"
  }

  PLAY RECAP **************************************************************************************************************************************************************************************************************
  10.15.0.11                 : ok=9    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
  

Examine the output above. The number of NDFC Fabrics should indicate the following:

(Beginning of script) - Number of NDFC Fabrics - 1
(End of script) - Number of NDFC Fabrics - 0

This is accurate because the staging fabric was deleted so that you can rebuild it from scratch using VXLAN as Code.


Step 4 - Verify Staging Fabric was Removed

Return to NDFC in your browser where you should still be sitting at the Fabrics dashboard. After the playbook has run, verify the staging fabric is removed.

Note

If your stage-fabric is still showing, please try clicking the refresh button in the top-right of the Fabrics pane.


There should be no fabrics listed. Now that you have reset your NDFC instance, let's start building your fabric from the ground up using VXLAN as Code.