Ansible playbook development for network automation: Worked Example — Automation and Configuration (NVIDIA-Certified Professional: AI Networking)
Ansible Playbook Development for Network Automation: Worked Example Automation is a critical skill for the NVIDIA-Certified Professional: AI...
Ansible Playbook Development for Network Automation: Worked Example
Automation is a critical skill for the NVIDIA-Certified Professional: AI Networking certification, especially for managing complex AI networking environments efficiently. This worked example focuses on developing an Ansible playbook to automate network switch configuration using NVUE templates, a key component in NVIDIA's AI networking ecosystem.
Scenario
You are tasked with automating the configuration of multiple NVIDIA Mellanox switches to apply consistent VLAN and interface settings. The goal is to create an Ansible playbook that deploys NVUE templates to these switches, ensuring uniform configuration and reducing manual errors.
Step 1: Define the Objective
The playbook must:
- Connect to a list of Mellanox switches via SSH
- Deploy a predefined NVUE template to configure VLANs and interfaces
- Verify the configuration was applied successfully
Step 2: Prepare NVUE Template
Create an NVUE template file vlan_interface_config.nvue containing the desired configuration. For example:
vlan 100 { description "AI_Network_VLAN" interfaces [ "eth1/1", "eth1/2" ] }
This template defines VLAN 100 with a description and assigns it to interfaces eth1/1 and eth1/2.
Step 3: Create the Ansible Inventory
List the target switches in an inventory file inventory.ini:
[mellanox_switches] switch1 ansible_host=192.168.1.10 switch2 ansible_host=192.168.1.11
Step 4: Develop the Ansible Playbook
Create a playbook deploy_nvue.yml with the following structure:
--- - name: Deploy NVUE templates to Mellanox switches hosts: mellanox_switches gather_facts: no connection: network_cli tasks: - name: Copy NVUE template to switch copy: src: vlan_interface_config.nvue dest: /tmp/vlan_interface_config.nvue-
name: Apply NVUE template command: nvue apply /tmp/vlan_interface_config.nvue
-
name: Verify VLAN configuration command: nvue show vlan 100 register: vlan_output
-
name: Display VLAN configuration output debug: var: vlan_output.stdout
Step 5: Explanation of Each Task
- Copy NVUE template: Transfers the local NVUE template file to the switch's temporary directory.
- Apply NVUE template: Executes the NVUE command to apply the configuration from the template file.
- Verify VLAN configuration: Runs a command to show the VLAN 100 details and registers the output.
- Display output: Prints the verification output to confirm successful configuration.
Step 6: Run the Playbook
Execute the playbook with the command:
ansible-playbook -i inventory.ini deploy_nvue.ymlThis will connect to each switch, deploy the NVUE template, apply the configuration, and verify the changes.
Step 7: Review and Troubleshoot
After execution, check the debug output for each switch to ensure VLAN 100 is configured as expected. If errors occur, verify SSH connectivity, NVUE template syntax, and switch compatibility.
Summary
This example demonstrates how to develop an Ansible playbook tailored for NVIDIA AI Networking environments to automate switch configuration using NVUE templates. Mastery of such automation techniques is essential for the NVIDIA-Certified Professional: AI Networking exam and real-world deployment scenarios.
More in this topic
Ready to test your knowledge?
Put what you've learned into practice with a quick quiz and track your progress.
Test your knowledge →