Typically, most desired configurations can be done through our Aruba Switching Modules found on our GitHub: https://github.com/aruba/aruba-ansible-modules
But if you find yourself wanting to do something that our modules can't do, there are a few options!
Remember, Ansible and it's modules must be installed on your Linux Ansible Control Machine, for information on how to install Ansible and the Aruba Switching Modules watch this video on the ABC Networking Channel: Intro to Ansible and Aruba Switching Modules
Now I'll go over how to install and use the CLI modules that use REST and SSH:
1. Clone our Aruba Switch Ansible Workflows Github, this Github holds the SSH CLI modules for each platform as well as tasks that structure ArubaOS Switch and CX REST API calls:
git clone https://github.com/aruba/aruba-switch-ansible.git
2. Copy the directories library/ and aruba_task_lists/ into the directory where your playbooks are stored. If your current directory is where your playbooks are located use the following commands:
cp -rf library/ .
cp -rf aruba_task_lists/ .
3. For ArubaOS-Switch, you can use the anycli.yml task to execute AnyCLI REST API commands, including show commands. Note that there is no equivalent REST API command available for CX today.
You can see how to use the AnyCLI task as well as the other tasks here:
https://github.com/aruba/aruba-switch-ansible/blob/public-devel/arubaoss_tasks_config_example.yml
- name: Configure Vlan 233
include: aruba_task_lists/aos_switch/anycli.yml command="{{item}}"
with_items:
- "conf"
- "vlan 233"
- "ip address 10.1.1.3 255.255.255.0"
- name: Show vlans
include: aruba_task_lists/aos_switch/anycli.yml command="show vlans"
register: cli_output
4. For ArubaOS-Switch and ArubaOS-CX, you can use the SSH CLI modules in the library/ directory to execute CLI commands as well as show commands. Remember this is using SSH to connect to your device, which means it may take more time to execute the command. Before using the modules, you'll have to define the device's ansible_connection to be local. You can do that through 1 of 2 ways, either in your inventory file:
ansible_host: 10.1.2.3
ansible_user: admin
ansible_password: admin
ansible_connection: local # required
OR you can define the connection variable in the playbook, this will override the ansible_connection variable defined in your inventory when using this playbook:
- hosts: switch1
connection: local
tasks:
Here are some examples below of how to use these modules for configuration and show commands. Keep in mind that in some of the examples I am passing Variables, but you're able to put information directly into the modules:
Example for Switch:
- name: Enable Interface 5
arubaos_switch_ssh_cli:
ip: "{{ansible_host}}"
user: "{{ansible_user}}"
password: "{{ansible_password}}"
command_list: ["conf", "interface 5", "enable"]
- name: Get output of show vlans
arubaos_switch_ssh_cli:
ip: "{{ansible_host}}"
user: "{{ansible_user}}"
password: "{{ansible_password}}"
show_command: ["show vlans"]
register: ssh_output
Example for CX:
- name: Enable Interface 3
arubaos_cx_ssh_cli:
ip: 10.1.1.1
user: admin
password: "{{ansible_password}}"
commands: ["conf", "interface 1/1/5", "no shutdown"]
- name: Get output of show running
arubaos_cx_ssh_cli:
ip: 10.1.1.1
user: admin
password: "{{ansible_password}}"
commands: ["show running-config"]
register: output
You can see more examples of how to use these modules in the following files:
https://github.com/aruba/aruba-switch-ansible/blob/master/aruba_task_lists/aos_switch/ssh_cli_module_user.yml
https://github.com/aruba/aruba-switch-ansible/blob/master/library/arubaos_cx_ssh_cli.py