Using the AOS-CX Ansible Collection
Installing and using the AOS-CX collection
There are two approaches to using the AOS-CX modules: role and collection. A guide for the latter is detailed here. For the alternative method, see the instructions for using the AOS-CX Ansible Role.
In order to use the AOS-CX Ansible collection to configure AOS-CX hosts, REST API access must be enabled on each host. Please follow the steps outlined here: Enabling the AOS-CX API.
What is an Ansible collection?
In Ansible, a collection is used to bundle up and distribute Ansible content, including items such as playbooks, roles, modules, and plugins.
Installing the Collection
Our AOS-CX Ansible modules are packaged in the AOS-CX collection. They are also packaged in the AOS-CX role. For instructions on installing and using the modules with the alternative role approach, please see this page.
To install the collection, issue the "ansible-galaxy" command:
ansible-galaxy collection install arubanetworks.aoscx
If you plan on using the AOS-CX collection in an Ansible Tower environment, make sure to provide the full path to a location in which Ansible Tower looks for installed collections. Ansible Tower looks in multiple places for installed collections. For example, one such path is /usr/share/ansible/collections
:
ansible-galaxy collection install arubanetworks.aoscx -p /usr/share/ansible/collections
To upgrade your existing installation of the collection to the latest updated collection, simply re-run the appropriate "ansible-galaxy" command listed above with the -f
option. Ansible will check to see if the existing collection is out of date and if so, install the latest version.
In version 3.0.0+ of the AOS-CX collection, we've redesigned the role to make use of our Python SDK for AOS-CX Pyaoscx v2 to handle all REST-API based calls and modules. This requires Python3 to be installed as well as the pyaoscx>=2.0.0
package.
pip3 install pyaoscx>=2.0.0
.
For a detailed description of requirements and installation steps refer to the documentation of the AOS-CX collection.
AOS-CX Module Support and Compatibility
All of Aruba's Ansible modules can be run with both Ansible Engine and the Ansible GUIs (Ansible Tower and AWX). The sole requirement is Ansible version 2.9.0 or later and the pyaoscx v2
Python package.
Module | 8400 | 8325 | 8320 | 6400 | 6300 |
---|---|---|---|---|---|
aoscx_acl | ✅ | ✅ | ✅ | ✅ | ✅ |
aoscx_acl_interface | ✅ | ✅ | ✅ | ✅ | ✅ |
aoscx_acl_vlan | ✅ | ✅ | ✅ | ✅ | ✅ |
aoscx_backup_config | ✅ | ✅ | ✅ | ✅ | ✅ |
aoscx_banner | ✅ | ✅ | ✅ | ✅ | ✅ |
aoscx_boot_firmware | ✅ | ✅ | ✅ | ✅ | ✅ |
aoscx_checkpoint | ✅ | ✅ | ✅ | ✅ | ✅ |
aoscx_command | ✅ | ✅ | ✅ | ✅ | ✅ |
aoscx_config | ✅ | ✅ | ✅ | ✅ | ✅ |
aoscx_dns | ✅ | ✅ | ✅ | ✅ | ✅ |
aoscx_facts | ✅ | ✅ | ✅ | ✅ | ✅ |
aoscx_l2_interface | ✅ | ✅ | ✅ | ✅ | ✅ |
aoscx_l3_interface | ✅ | ✅ | ✅ | ✅ | ✅ |
aoscx_static_route | ✅ | ✅ | ✅ | ✅ | ✅ |
aoscx_upload_config | ✅ | ✅ | ✅ | ✅ | ✅ |
aoscx_upload_firmware | ✅ | ✅ | ✅ | ✅ | ✅ |
aoscx_vlan | ✅ | ✅ | ✅ | ✅ | ✅ |
aoscx_vlan_interface | ✅ | ✅ | ✅ | ✅ | ✅ |
aoscx_vrf | ✅ | ✅ | ✅ | ✅ | ✅ |
aoscx_vsx | ✅ | ✅ | ✅ | ✅ | ✅ |
Platform | Firmware |
---|---|
8400 | XL.10.04.001 and later |
8325 | GL.10.04.001 and later |
8320 | TL.10.04.001 and later |
6400 | FL.10.04.001 and later |
6300 | FL.10.04.001 and later |
6200 | FL.10.04.001 and later |
SSH/CLI Modules
All of our modules in the AOS-CX collection are written to use REST API for connection and configuration with a few exceptions, save for a couple of exceptions. The modules aoscx_config
and aoscx_command
use SSH to connect to the AOS-CX switch to execute CLI commands. These modules can be used in addition to or instead of the REST API modules provided in the role.
- To use the SSH/CLI modules
aoscx_config
andaoscx_command
, SSH access must be enabled on your AOS-CX device. It is enabled by default.- If necessary, re-enable SSH access on the device with the following command:
switch(config)# ssh server vrf mgmt
- If necessary, re-enable SSH access on the device with the following command:
- The control machine's
known_hosts
file must contain the target device's public key.- Alternatively, host key checking by the control machine may be disabled, although this is not recommended. To disable host key checking, modify the ansible.cfg file (located by default at
/etc/ansible/ansible.cfg
) to include:
host_key_checking = false
- Alternatively, host key checking by the control machine may be disabled, although this is not recommended. To disable host key checking, modify the ansible.cfg file (located by default at
Limitations and Notes
- The default command timeout is 30 seconds. If a command takes more than 30
seconds to execute, the task will time out.- If you regularly encounter the
command timeout triggered, timeout value is 30 secs
error, consider setting the environment variable
ANSIBLE_PERSISTENT_COMMAND_TIMEOUT
to a greater value. See Ansible documentation here.
- If you regularly encounter the
Inventory Setup
In addition to installing the AOS-CX collection, you must also add any AOS-CX hosts to the Ansible inventory. For each AOS-CX switch, the following inventory variables must be defined:
ansible_host
: IP address of the switch inA.B.C.D
format; for IPv6 hosts use a string and enclose the IP address in square brackets (e.g.'[2001::1]'
)ansible_user
: Username for the switch in plaintextansible_password
: Password for the switch in plaintextansible_network_os
: Must always be set toarubanetworks.aoscx.aoscx
ansible_connection
: Set toarubanetworks.aoscx.aoscx
to use REST API modules,network_cli
to use SSH/CLI modules, andhttpapi
for legacy REST API method.- See below for info on using both REST API modules and SSH/CLI modules on a host
ansible_aoscx_validate_certs
: Set toTrue
orFalse
depending if Ansible should bypass validating certificates to connect to AOS-CX. Only required whenansible_connection
is set toarubanetworks.aoscx.aoscx
ansible_aoscx_use_proxy
: Set toTrue
orFalse
depending if Ansible should bypass environment proxies to connect to AOS-CX. Only required whenansible_connection
is set toarubanetworks.aoscx.aoscx
.ansible_httpapi_use_ssl
: Must always beTrue
as AOS-CX uses port 443 for REST. Only required whenansible_connection
is set tohttpapi
.ansible_httpapi_validate_certs
: May be set to eitherTrue
orFalse
depending on whether Ansible should attempt to validate SSL certificates on the device. Only required whenansible_connection
is set tohttpapi
.ansible_acx_no_proxy
: May be set to eitherTrue
orFalse
depending on whether Ansible should bypass environment proxies when connecting to the switch. Only required whenansible_connection
is set tohttpapi
.
Example inventories for REST API (each with one host)
INI
aoscx_1 ansible_host=10.0.0.1 ansible_user=admin ansible_password=password ansible_network_os=arubanetworks.aoscx.aoscx ansible_connection=arubanetworks.aoscx.aoscx ansible_aoscx_validate_certs=False ansible_aoscx_use_proxy=False
YAML
all:
hosts:
aoscx_1:
ansible_host: 10.0.0.1
ansible_user: admin
ansible_password: password
ansible_network_os: arubanetworks.aoscx.aoscx
ansible_connection: arubanetworks.aoscx.aoscx # REST API via pyaoscx connection method
ansible_aoscx_validate_certs: False
ansible_aoscx_use_proxy: False
Example inventories for SSH/CLI (each with one host)
INI
aoscx_1 ansible_host=10.0.0.1 ansible_user=admin ansible_password=password ansible_connection=network_cli ansible_network_os=arubanetworks.aoscx.aoscx
YAML
all:
hosts:
aoscx_1:
ansible_host: 10.0.0.1
ansible_user: admin
ansible_password: password
ansible_connection: network_cli # SSH connection method
ansible_network_os: arubanetworks.aoscx.aoscx
Example Playbook
Note the inclusion of the collection with collections:
and - ...
:
---
- hosts: all
collections:
- arubanetworks.aoscx
tasks:
- name: Create L3 Interface 1/1/3
aoscx_l3_interface:
interface: 1/1/3
description: Uplink_Interface
ipv4: ['10.20.1.3/24']
ipv6: ['2001:db8::1234/64']
Using Both REST API and SSH/CLI Modules on a Host
To use both REST API and SSH/CLI modules on the same host, you must create separate plays such that each play uses either only REST API modules or only SSH/CLI modules. A play cannot mix and match REST API and SSH/CLI module calls.
In each play, ansible_connection
must possess the appropriate value according to the modules used. If the play uses REST API modules, that value should be arubanetworks.aoscx.aoscx
. If the play uses SSH/CLI modules, that value should be network_cli
.
A recommended approach to successfully using both types of modules for a host is as follows:
- Set the host variables such that Ansible will connect to the host using REST API, like seen above.
- In the playbook, in each play wherein the SSH/CLI modules are used, set the
ansible_connection
tonetwork_cli
.
The inventory should look something like this:
all:
hosts:
aoscx_1:
ansible_host: 10.0.0.1
ansible_user: admin
ansible_password: password
ansible_network_os: arubanetworks.aoscx.aoscx
ansible_connection: arubanetworks.aoscx.aoscx # REST API via pyaoscx connection method
ansible_aoscx_validate_certs: False
ansible_aoscx_use_proxy: False
and the playbook like this (note how the second play, which uses the SSH/CLI module aoscx_command
, sets the ansible_connection
value accordingly):
- hosts: all
collections:
- arubanetworks.aoscx
tasks:
- name: Adding or Updating Banner
aoscx_banner:
banner_type: banner
banner: "Hi!"
- hosts: all
collections:
- arubanetworks.aoscx
vars:
ansible_connection: network_cli
tasks:
- name: Execute show run on the switch
aoscx_command:
commands: ['show run']
Updated over 3 years ago