Developer

last person joined: 12 hours ago 

Expand all | Collapse all

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

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

    Posted May 14, 2019 06:52 PM

    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

     

     



  • 2.  RE: How to install/use CLI modules and tasks for Switch and CX in Ansible

    Posted May 17, 2019 02:45 AM
      |   view attached

    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

    The error appears to have been in '/home/ilia/ANS/pb_anycli3.yml': line 9, column 11, but may
    be elsewhere in the file depending on the exact syntax problem.

    The offending line appears to be:

    block:
    - set_fact:
    ^ here
    "}

     

     

    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.

    Attachment(s)

    txt
    pb_anycli3.txt   1 KB 1 version


  • 3.  RE: How to install/use CLI modules and tasks for Switch and CX in Ansible

    Posted May 20, 2019 01:04 AM

    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

    The error appears to have been in '/home/ilia/ANS/pb_ssh.yml': line 7, column 7, but may
    be elsewhere in the file depending on the exact syntax problem.

    The offending line appears to be:

    -
    name: SSH Commands
    ^ here
    "} PLAY RECAP ********************************************************************************************************************************************************************************************************************************** switch1 : ok=0 changed=0 unreachable=0 failed=1 root@psg-ans01:/home/ilia/ANS#

    Help much appreciated.



  • 4.  RE: How to install/use CLI modules and tasks for Switch and CX in Ansible

    Posted May 20, 2019 01:02 PM

    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! :)



  • 5.  RE: How to install/use CLI modules and tasks for Switch and CX in Ansible

    Posted May 20, 2019 09:41 PM

    Thank you, that works now!

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



  • 6.  RE: How to install/use CLI modules and tasks for Switch and CX in Ansible

    Posted May 21, 2019 11:31 AM

    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!



  • 7.  RE: How to install/use CLI modules and tasks for Switch and CX in Ansible

    Posted May 26, 2019 05:00 AM

    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

     



  • 8.  RE: How to install/use CLI modules and tasks for Switch and CX in Ansible

    Posted Jun 12, 2019 11:25 AM

    Fixed! Thank you for that! :D



  • 9.  RE: How to install/use CLI modules and tasks for Switch and CX in Ansible

    Posted Sep 08, 2019 08:17 AM

    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



  • 10.  RE: How to install/use CLI modules and tasks for Switch and CX in Ansible

    Posted Sep 09, 2019 03:17 AM

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



  • 11.  RE: How to install/use CLI modules and tasks for Switch and CX in Ansible

    Posted Sep 15, 2019 07:17 AM

    Thanks for your reply.

     

    Regarding powershall - nice!, but would love to see port-access with ansible module.

     



  • 12.  RE: How to install/use CLI modules and tasks for Switch and CX in Ansible

    Posted Sep 17, 2019 02:18 AM

    Hello, 

     

    I have installed all the Aruba ansible modules and switch module. I can connect to Aruba switch using the Aruba ansible modules and make changes however I cannot use the SSH module. 

     

    I get the below error when I use the SSH module. Any idea what could be the issue? 

     

    ERROR! 'arubaos_switch_ssh_cli' is not a valid attribute for a Play

     



  • 13.  RE: How to install/use CLI modules and tasks for Switch and CX in Ansible

    Posted Sep 17, 2019 12:22 PM

    Hi tarunagghi!

     

    Could you please open another thread with a copy of what your playbook looks like as well as the error you're seeing??

     

    From what it sounds like, it could be an issue with Ansible finding the arubaos_switch_ssh_cli module or indentation, but I can't say for sure without seeing the code.

     

    Thank you!