"Here I go! On another adventure to learn another tool. Ive done python, terraform, powershell. Onto Ansible."
My goal with learning this was purely for networking equipment. Primarily Aruba networking gear. I have finally done it! I made my first Ansible play and even though this is small and a simple {show run} command. I think its important to see what you have done and to learn to be proud of your accomplishments.
After reading the Aruba documentation on Github, Ansible documentation, and some help from Claude AI. This is how i setup my first Ansible Play!
Building the Environment
I decided to build out a virtual machine at home running Ubuntu Server 24.04. I made sure to update the host by running the following:
After that we need to get python installed and setup the virtual environment.
Verify python is install
Exit the python terminal
Install python-venv
Create a python virtual environment
Activate the environment
Install Ansible Inside the Virtual Environment
You can verify that ansible is install correctly by running:
Install the Aruba AOS‑CX Ansible Collection Inside the venv. Collections are a distribution format for Ansible content that can include playbooks, roles, modules, and plugins. For this run, it will be the modules we need to execute commands on the switch.
If you are using AOS use this:
Now install SSH Transports for network_cli. Ansible’s network_cli plugin requires either Paramiko or ansible‑pylibssh to be installed.
Now is a good time to move forward with making sure your switch has ssh enabled.
I created an Ansible directory to keep things in. Such as my host file and playbooks
Create a hosts file in your ansible-cx repo. My favorite editor in linux is vi. So in this instance i would type vi hosts. DO NOT USE A FILE EXTENSION. Below is an example hosts file, I used something similar and left out my creds.
- all:
- hosts:
- switch1:
- ansible_host: 10.10.10.10
- ansible_user: admin
- ansible_password: your_password
- ansible_connection: network_cli
- ansible_network_os: arubanetworks.aoscx.aoscx
- ansible_ssh_port: 22
- switch1:
- hosts:
#If you are using AOS change the network_os to: arubanetworks.aos_switch.arubaoss
all: Top-level default group — every host in the inventory belongs to this
hosts: Keyword that declares the list of hosts under this group
switch1: Inventory hostname — this is what Ansible calls the device internally
To see more modules in a Collection, run this:
Validate that your inventory is correct with the following:
Lets create our playbook now for the commands. Again I use vi so i would type vi play.yml
- name: CX SSH Test
hosts: all
gather_facts: false
collections:- arubanetworks.aoscx
tasks: - name: Show running-config
aoscx_command:
commands:
- show running-config
- arubanetworks.aoscx
If you are using AOS collections is arubanetworks.aos_switch, and module is arubaoss_command
NOTE! Before you run this Play. Prevent Ansible from caring about the keys. Unless you import the SSH keys into known_hosts
Run the Playbook
ansible-playbook -i hosts play.yml -vvv (-vvv just means very verbose!)