Developer Community

Reply
Aruba Employee

How to install/use CLI modules and tasks for Switch and CX in Ansible

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. 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

 

 

Occasional Contributor I

Re: How to install/use CLI modules and tasks for Switch and CX in Ansible

Thank you for sharing this!

I am planning to use it to do following:

 - Set primary vlan ID to 10
 - Assemble ports 47 and 48 in a trunk trk1

Unlike rest of my config tasks I couldn`t find a way to perform those using aruba-ansible-modules, so I guess AnyCLI is my next best, is that right?

What would be a minimal set of lines to implement it, provided that we have file structure in place (aruba_task_lists/ and library/)? Do we need login and logout? What about task that Stores Global variables in localhost?

Currently I am getting following error and not sure what is Site in this case and what task "Store Global variables in localhost" does and how does it work. Could you please elaborate?


TASK [set_fact] *****************************************************************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'site' is undefined\n\nThe error appears to have been in '/home/ilia/ANS/pb_anycli3.yml': line 9, column 11, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n block:\n - set_fact:\n ^ here\n"}

 

 

root@psg-ans01:/home/ilia/ANS# tree
.
├── aruba_task_lists
...

│   ├── aos_switch
│   │   ├── anycli.yml
...

│   │   ├── login_switch.yml
│   │   ├── logout_switch.yml
...

├── inv_switches.yml
├── library
│   ├── arubaos_cx_ssh_cli.py
│   └── arubaos_switch_ssh_cli.py
├── pb_anycli3.yml

...

 

PS. Had to change extention of file from .yml to txt to attach it here.

Occasional Contributor I

Re: How to install/use CLI modules and tasks for Switch and CX in Ansible

Tried to use SSH to no avail as well. 

Have following test playbook:

---
-
  gather_facts: false
  hosts: switch1
  tasks:
    -
      name: SSH Commands
      arubaos_switch_ssh_cli:
        ip: "{{192.168.1.11}}"
        user: "{{manager}}"
        password: "{{pass}}"
        command_list: ["conf", "primary-vlan 10", "trunk 47-48 trk1 trunk", "show vlans"]
      register: ssh_output

Result appears to be similar to previous attempts:

root@psg-ans01:/home/ilia/ANS# ansible-playbook pb_ssh.yml -i inv_switches.yml

PLAY [switch1] ******************************************************************************************************************************************************************************************************************************

TASK [SSH Commands] *************************************************************************************************************************************************************************************************************************
fatal: [switch1]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: float object has no element 1\n\nThe error appears to have been in '/home/ilia/ANS/pb_ssh.yml': line 7, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n    -\n      name: SSH Commands\n      ^ here\n"}

PLAY RECAP **********************************************************************************************************************************************************************************************************************************
switch1                    : ok=0    changed=0    unreachable=0    failed=1

root@psg-ans01:/home/ilia/ANS#

Help much appreciated.

Aruba Employee

Re: How to install/use CLI modules and tasks for Switch and CX in Ansible

Hi Ilia!

 

It looks like the formatting of your values for ip , user, and password are incorrect.

 

In Ansible, when working with Variables you would use the format "{{ variable }}" but since it looks like you're passing in the actual values of ip, user, and password, you don't need the "{{ }}" around the values you're sending.

 

Also I noticed you have "show vlans" in the command list, you'll want to separate that from the command list to gt the proper output.

 

For example, your task should look like the following:

- hosts: switch1
  gather_facts:false
  tasks:
    - name: SSH Commands
      arubaos_switch_ssh_cli:
        ip: 192.168.1.11
        user: manager
        password: pass
        command_list: ["conf", "primary-vlan 10", "trunk 47-48 trk 1 trunk"]
show_command: ["show vlans"]
register: ssh_output

 

Try that and see if that solves your error! :)

Occasional Contributor I

Re: How to install/use CLI modules and tasks for Switch and CX in Ansible

Thank you, that works now!

I guess AnyCLI will work better once I will practice with Ansible a bit.

Aruba Employee

Re: How to install/use CLI modules and tasks for Switch and CX in Ansible

It takes a little adjusting to Ansible! But you're on the right track! If you have anymore issues or questions, feel free to post in the developer community!

Occasional Contributor I

Re: How to install/use CLI modules and tasks for Switch and CX in Ansible

Hi,

 

There is typo in Example for Switch: for arubaos_switch_ssh_cli:

- command_list: - used to configure commands
- show_command: - used for show commands

 

at the moment command_list: appears in both examples :)

 

Thanks

 

Aruba Employee

Re: How to install/use CLI modules and tasks for Switch and CX in Ansible

Fixed! Thank you for that! :D

Occasional Contributor I

Re: How to install/use CLI modules and tasks for Switch and CX in Ansible

Hello,

 

There are commands like

aaa authentication port-access eap-radius authorized

which gives 

Do you want to continue? [y/n]

when entered.

 

Any way to handle them with ssh_cli module? Since I can't find in the rest module any reference for aaa port-access (8021.x) config at all

 

Thanks

MVP Expert

Re: How to install/use CLI modules and tasks for Switch and CX in Ansible


@michaely wrote:

Hello,

 

There are commands like

aaa authentication port-access eap-radius authorized

which gives 

Do you want to continue? [y/n]

when entered.

 

Any way to handle them with ssh_cli module? Since I can't find in the rest module any reference for aaa port-access (8021.x) config at all

 

Thanks


Hi,

I think, it will be better to open a new topic...

 

and for me, there is a REST API for port-access...




PowerArubaSW: Powershell Module to use Aruba Switch API for Vlan, VlanPorts, LACP, LLDP... More info


PowerArubaCP: Powershell Module to use ClearPass API (create NAD, Guest...) More info


PowerArubaCX: Powershell Module to use ArubaCX API (get interface/vlan/ports info)


PowerArubaIAP: Powershell Module to use Aruba Instant AP




ACMP 6.4 / ACMX #107 / ACCP 6.5
Search Airheads
cancel
Showing results for 
Search instead for 
Did you mean: