[Aruba DevNet Lecture 3] Automating Simultaneous Switch Configuration: Windows Python vs. Linux Ansible

Lecture 2In , we experienced automation in 'reading' data through the New Central API.
But what makes an engineer's heart beat is 'the ability to freely adjust the equipment settings.'.

Today, we'll learn how to implement automation in two environments (Windows and Linux) using Aruba CX switches.

CX switches support REST APIs, allowing for a variety of automation and programming possibilities.


1. Which Automation Tool Should I Use? (Netmiko vs. Ansible)

  • Windows environment: If you find installing Linux burdensome? The most popular Netmiko The library is the answer.
    As long as you have Python, you can SSH into the switch from anywhere and push the settings.
  • Linux environment: What if you want full-fledged IaC (Infrastructure as Code)? AnsibleThis is the standard.
    Manage hundreds of switches simultaneously with just a YAML file, without any separate coding.

2. [Windows] Getting Started with Python Netmiko

If you are a Windows user, you only need to add one more library to the environment you set up last time.

PowerShell
python -m pip install netmiko

[cx_config.py]

Python
from netmiko import ConnectHandler

# switch connection information
device = {
    ''device_type'': ''aruba_os_cx'',
    ''host'': '192.168.1.100',
    ''username'': ''admin'',
    ''password'': ''Password!'',
}

# Apply setting command axis
commands = [
    ''vlan 10'',
    ''name Guest_VLAN'',
    ''interface 1/1/1'',
    ''vlan access 10''
]

with ConnectHandler(**device) as net_connect:
    print(""🚀 Setting up the switch..."")
    output = net_connect.send_config_set(commands)
    print(output)

3. [Linux] Implementing Powerful Batch Control with Ansible

If you have a Linux (Ubuntu/WSL) environment, you can use the official service provided by Aruba. Ansible CollectionIt is most powerful to use .

[installation]

Bash
Installing the # Ensemble and Aruba Collection
sudo apt update && sudo apt install ansible -y
ansible-galaxy collection install arubanetworks.aos_cx

[inventory.ini] – List of managed switches

INI
[cx_switches]
sw-leaf-01 ansbile_host=192.168.1.101
sw-leaf-02 ansbile_host=192.168.1.102

[cx_switches:vars]
ansible_user=admin
ansible_password=Password!
ansible_network_os=arubanetworks.aos_cx.aos_cx

[vlan_setup.yml] – A playbook that defines the actual “what to do”

YAML
---
- name: Bulk VLAN configuration on Aruba CX switches
  hosts: cx_switches
  gather_facts: no
  tasks:
    - name: Create and name VLAN 10
      arubanetworks.aos_cx.aos_cx_vlan:
        vlan_id: 10
        name: ""DevNet_VLAN""
        state: present

[execution]

Bash
ansible-playbook -i inventory.ini vlan_setup.yml

4. How to choose the right tool for your environment

“We can't say that "ensemble is always the best.".

  • One-time tasks or simple checks: On Windows NetmikoIt is efficient to quickly write scripts.
  • Regular operation and standardization: On the server AnsibleIt is advantageous for maintenance to build a configuration file (YAML) and manage the version (Git).

The key is to “reduce the time I spend typing by connecting to the console directly”, no matter what tool I use.


In conclusion

Today we have two wings: Windows and Linux.
Now your Aruba CX switches are ready to move seamlessly with a single line of code.

next semifinalsIn “Webhook and Slack Integration in Aruba Central,” we will create intelligent automation that allows the equipment to talk to me directly when a problem occurs!