Reset Fabric
Ansible

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 of the lab is demonstrate how you can use an existing framework, Ansible in this case, to build things back with configuration intent in subsequent sections.


touch ~/workspace/ndfclab/ansible/reset_fabric.yml  
cat << EOF > ~/workspace/ndfclab/ansible/reset_fabric.yml  

---
# This Ansible Playbook is used to Reset The Fabric

- name: Reset Fabric on NDFC
  hosts: ndfc
  gather_facts: false

  tasks:
    - name: Verify NDFC {{ fabric_settings.FABRIC_NAME }} State
      cisco.dcnm.dcnm_rest:
        method: GET
        path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics"
      register: result
    
    - ansible.builtin.debug:
        msg: "Number of NDFC Fabrics - {{ result.response.DATA | length }}"

    - ansible.builtin.debug:
        msg: "{{ item.fabricName }}"
      loop: "{{ result.response.DATA }}"
      loop_control:
        label: "{{ item.fabricName }}"

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

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

    - ansible.builtin.debug:
        msg: "Fabric {{ fabric_settings.FABRIC_NAME }} has already been reset"
      when: fabric_reset == False

    - name: Remove Switches from NDFC {{ fabric_settings.FABRIC_NAME }}
      cisco.dcnm.dcnm_inventory:
        fabric: "{{ fabric_settings.FABRIC_NAME }}"
        state: deleted
      when: fabric_reset

    - name: Delete {{ fabric_settings.FABRIC_NAME }} from NDFC
      cisco.dcnm.dcnm_rest:
        method: DELETE
        path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics/{{ fabric_settings.FABRIC_NAME }}"
      when: fabric_reset

    - name: Verify NDFC {{ fabric_settings.FABRIC_NAME }} State
      cisco.dcnm.dcnm_rest:
        method: GET
        path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics"
      register: result

    - 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_fabric.yml

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

  PLAY [Reset Fabric on NDFC] *******************************************************************************************************************************************************************************

  TASK [Verify NDFC fabric-stage State] *********************************************************************************************************************************************************************
  ok: [10.15.0.11]

  TASK [ansible.builtin.debug] ******************************************************************************************************************************************************************************
  ok: [10.15.0.11] => {
      "msg": "Number of NDFC Fabrics - 1"
  }

  TASK [ansible.builtin.debug] ******************************************************************************************************************************************************************************
  ok: [10.15.0.11] => (item=fabric-stage) => {
      "msg": "fabric-stage"
  }

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

  TASK [Update NDFC Reset Control Variable if Fabric Exists] ************************************************************************************************************************************************
  ok: [10.15.0.11]

  TASK [ansible.builtin.debug] ******************************************************************************************************************************************************************************
  skipping: [10.15.0.11]

  TASK [Remove Switches from NDFC fabric-stage] *************************************************************************************************************************************************************
  ok: [10.15.0.11]

  TASK [Delete fabric-stage from NDFC] **********************************************************************************************************************************************************************
  ok: [10.15.0.11]

  TASK [Verify NDFC fabric-stage State] *********************************************************************************************************************************************************************
  ok: [10.15.0.11]

  TASK [ansible.builtin.debug] ******************************************************************************************************************************************************************************
  ok: [10.15.0.11] => {
      "msg": "Number of NDFC Fabrics - 0"
  }

  PLAY RECAP ************************************************************************************************************************************************************************************************
  10.15.0.11                 : ok=9    changed=1    unreachable=0    failed=0    skipped=1    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 Ansible.


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 Ansible.