Developer

 View Only
last person joined: 8 days ago 

Expand all | Collapse all

arubanetworks.aos_switch - Reboot Command for Aruba 2540 (CLI Connection)

This thread has been viewed 10 times
  • 1.  arubanetworks.aos_switch - Reboot Command for Aruba 2540 (CLI Connection)

    Posted Aug 26, 2022 10:03 AM
    Hi,
    I am in the process of creating Ansible Playbooks for Aruba 2540 switches which apparently come from the factory with a YC.16.01.0002 ROM
    booting from primary with YC.16.07.0003 - which means they have an API version that is to old to work with the modules provided by arubanetworks.aos_switch collection.

    After quite some work and the help of the collection maintainers we came up with a solution for a play that uses the cli connection
    --- 
    2- hosts: all 
    3 gather_facts: False 
    4 collections: 
    5 - arubanetworks.aos_switch 
    6 vars: 
    7 ansible_connection: network_cli 
    8 tasks: 
    9 - name: Upload via TFTP 
    10 arubaoss_command: 
    11 commands: 
    12 - command: 'copy tftp flash 192.168.160.190 YC_16_09_0020.swi secondary' 
    13 prompt: 
    14 - '.*Continue.*' 
    15 answer: 
    16 - y 
    17 - name: Show Flash to confirm upload 
    18 arubaoss_command: 
    19 commands: 
    20 - command: 'show flash'

    which is working great :)

    now all I need is the command structure for arubaoss_command: which does let me reboot into the ROM of my choosing.

    after that I can finally rely on the collection modules to configure all the switches \o/

    I hope someone can point me to the right direction to being able to create a play for arubaoss_command:

    so far I came up with this:

    ---
    - hosts: all
      gather_facts: True
      collections:
        - arubanetworks.aos_switch
      vars:
        ansible_connection: network_cli
      tasks:
        - name: Reboot ze Switch.
          arubaoss_command:
            commands:
            - command: 'boot system flash secondary'
              prompt:
                - '.*continue*'
              answer:
                - y
              prompt:
                - '.*save*'
              answer:
                - n


    which does just run into a timeout - how do I tell command to abandon the connection? it does not seem to have any effect unfortunately..
    apparently the leading dots for the prompt catcher is necessary - without it I get an error:

     "Failed to compile one or more terminal prompt regexes: nothing to repeat at position 0.\nPrompts provided: [b'*save*']"

    any help is much appreciated!



  • 2.  RE: arubanetworks.aos_switch - Reboot Command for Aruba 2540 (CLI Connection)

    Posted 28 days ago
    Hi @Bernhardvlee !

    I believe the error is with repeating the parameters - try changing your playbook to the following to see if it helps:
    ---
    - hosts: all
      gather_facts: True
      collections:
        - arubanetworks.aos_switch
      vars:
        ansible_connection: network_cli
      tasks:
        - name: Reboot ze Switch.
          arubaoss_command:
            commands:
            - command: 'boot system flash secondary'
              prompt:
                - '.*continue*'
                - '.*save*'
              answer:
                - y
                - n​

    Also you can add the following to wait for the switch to finish rebooting:​
            - name: Wait for the switch to come online after reboot.
              wait_for:
                host: "{{ ansible_host }}"
                port: 22
                sleep: 10
                timeout: 900​



  • 3.  RE: arubanetworks.aos_switch - Reboot Command for Aruba 2540 (CLI Connection)

    Posted 27 days ago
    thank you so much Tiffany - the problem was indeed with the repeating of prompt and answer keywords.

    your version works and does cause the switch reboot. unfortunately ansible / the command module does not handle the connection going away:

    ConnectionError
    and
    "msg": "Negative size passed to PyBytes_FromStringAndSize"


    nice touch with the <wait_for> and using <ansible_host> var - maybe we can also use async for the reboot task and make ansible abandon the task completely or wait and poll..

    full error:

    The full traceback is:
    File "/tmp/ansible_arubaoss_command_payload_s1u7auam/ansible_arubaoss_command_payload.zip/ansible_collections/arubanetworks/aos_switch/plugins/module_utils/arubaoss.py", line 432, in run_cli_commands
    return conn.run_commands(commands=commands, check_rc=check_rc)
    File "/tmp/ansible_arubaoss_command_payload_s1u7auam/ansible_arubaoss_command_payload.zip/ansible/module_utils/connection.py", line 200, in __rpc__
    raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)
    fatal: [aosswitch_1]: FAILED! => {
    "changed": false,
    "invocation": {
    "module_args": {
    "api_version": "None",
    "commands": [
    {
    "answer": [
    "y",
    "n"
    ],
    "check_all": false,
    "command": "boot system flash secondary",
    "newline": true,
    "prompt": [
    ".*continue*",
    ".*save*"
    ],
    "sendonly": false
    }
    ],
    "host": null,
    "interval": 1,
    "match": "all",
    "output_file": null,
    "password": null,
    "port": null,
    "provider": {
    "api_version": null,
    "host": "10.10.0.254",
    "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
    "port": 80,
    "ssh_keyfile": null,
    "timeout": 60,
    "transport": "aossapi",
    "use_proxy": false,
    "use_ssl": false,
    "username": "ladmin",
    "validate_certs": false
    },
    "retries": 10,
    "ssh_keyfile": null,
    "timeout": null,
    "use_ssl": null,
    "username": null,
    "validate_certs": false,
    "wait_for": null
    }
    },
    "msg": "Negative size passed to PyBytes_FromStringAndSize"
    }

    btw why does it say port: 80 - shouldnt it use 22 for ssh / cli connection? there is no API call involved, or is there?