Developer

last person joined: 6 hours ago 

Expand all | Collapse all

Issue with “arubaos_switch_ssh_cli” module

Jump to Best Answer
  • 1.  Issue with “arubaos_switch_ssh_cli” module

    Posted Oct 08, 2019 05:26 PM

    This module seems working with only some show commands(such as ‘show version” and “show flash” ) but not all. Here is an example that does not work.

     

    Aruba-3810M-24G-PoEP-1-slot# show cdp

    Global CDP information

     

      Enable CDP [Yes] : Yes

      CDP mode [rxonly] : pre-standard-voice

      CDP Hold Time [180] : 180

      CDP Transmit Interval [60] : 60

     

      Port   CDP      Admin status

      ------ -------- ------------

      1      enabled  tx_rx

      2      enabled  rxonly

      3      enabled  rxonly

      4      enabled  rxonly

    …..

     

    I was trying to use below task to get the same information as above:

     

        - name: show cdp

          arubaos_switch_ssh_cli:

            ip: xxxxxx

            user: xxxx

            password: xxxx

            timeout: 180

            command_list:  [ "show cdp" ]

          register: cdp_result

     

    However, the result returned is cli_output": []

     



  • 2.  RE: Issue with “arubaos_switch_ssh_cli” module

    Posted Oct 09, 2019 03:48 AM

    I haven't seen this myself but I spotted that the output of "show cdp" contains the [ symbol. Could the code be intollerent to this special character?

     

    If you have other commands that don't work, do they contain this or other escape characters?

     

    Does " show cdp traffic " produce an error (no [ character on my switches although we don't use CDP).

     

    Ian.



  • 3.  RE: Issue with “arubaos_switch_ssh_cli” module

    Posted Oct 09, 2019 03:40 PM

    Thanks for your reply, Ian!

    I just tried and it does not look like caused by escape character, since "show cdp traffic" does not work either. See below:

    ---- Aruba output ---

    Aruba-3810M-24G-PoEP-1-slot# show cdp traffic

    CDP frame Statistics:

    Port Transmitted Received Discarded Error
    No. Frames Frames Frames Frames
    -------- ------------ ----------- ----------- --------
    24 0 46448 0 0
    24 0 46448 0 0

    ------- Ansible output ----

    changed: [localhost] => {
    "changed": true,
    "cli_output": [],
    "invocation": {
    "module_args": {
    "allow_agent": false,
    "boot_image": "primary",
    "command_list": [
    "show cdp traffic"
    ],
    "enable_sftp": false,
    "ip": "xxxxxxxx",
    "key_filename": null,
    "look_for_keys": false,
    "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
    "path_to_swi": null,
    "port": 22,
    "show_command": null,
    "state": "upgrade",
    "timeout": 180,
    "user": "admin"
    }
    },
    "message": ""
    }

     



  • 4.  RE: Issue with “arubaos_switch_ssh_cli” module

    Posted Oct 09, 2019 05:56 AM

    Hi,

     

    It is not always a good idea to try to launch a cli command

    it will be better to launch API call

    there is a /rest/vX/cdp for CDP configuration



  • 5.  RE: Issue with “arubaos_switch_ssh_cli” module

    Posted Oct 09, 2019 03:45 PM

    @alagoutte, thanks for your reply and I agree REST is better.

    however using REST does require enable it on the Aruba switch.  We try not to make configuration change on the switch unless it is absolutely necessary. If CLI module works as expected, we would prefer to stick to it at this time. 



  • 6.  RE: Issue with “arubaos_switch_ssh_cli” module

    Posted Oct 09, 2019 03:50 PM

    Hi!!

     

    The parameter should actually be "show_command_list" instead of "command_list", that should give you the result back. Could you try and let me know the result?

     

        - name: show cdp

          arubaos_switch_ssh_cli:

            ip: xxxxxx

            user: xxxx

            password: xxxx

            timeout: 180

            show_command:  [ "show cdp" ]

          register: cdp_result



  • 7.  RE: Issue with “arubaos_switch_ssh_cli” module

    Posted Oct 09, 2019 04:02 PM

    @Tiffany, thanks for you reply. 

    I actually tried both and none of them are working for “show cdp”, using “show_command” would be no response until timeout, while using “command_list” would just return nothing.

    I tried a few show command so far, looks like only “show version” and “show flask” work.



  • 8.  RE: Issue with “arubaos_switch_ssh_cli” module

    Posted Oct 09, 2019 04:08 PM

    Hmm okay so show version and show flash work but not that particular command, do you have paging enabled? It could be since that command runs over multiple pages the module isn’t matching on the prompt. Are you able to disable paging with “no page” before the command?



  • 9.  RE: Issue with “arubaos_switch_ssh_cli” module

    Posted Oct 09, 2019 04:21 PM

    hmmm...I'm not sure it is caused by "paging", the output from "show cdp traffic" is pretty small and it does not work either :(

     

    Aruba-3810M-24G-PoEP-1-slot# show cdp traffic

    CDP frame Statistics:

    Port Transmitted Received Discarded Error
    No. Frames Frames Frames Frames
    -------- ------------ ----------- ----------- --------
    24 0 46448 0 0
    24 0 46448 0 0



  • 10.  RE: Issue with “arubaos_switch_ssh_cli” module

    Posted Oct 09, 2019 04:38 PM

    @tiffany, interesting, it does work now with adding the "no page".

     

    ok: [localhost] => {
    "changed": false,
    "cli_output": [
    "",
    "
    Global CDP information

    Enable CDP [Yes] : Yes
    CDP mode [rxonly] : pre-standard-voice
    CDP Hold Time [180] : 180
    CDP Transmit Interval [60] : 60

    Port CDP Admin status
    ------ -------- ------------
    1 enabled tx_rx
    2 enabled rxonly
    3 enabled rxonly
    4 enabled rxonly
    5 enabled rxonly
    6 enabled rxonly
    7 enabled rxonly
    8 enabled rxonly
    9 enabled rxonly
    10 enabled rxonly
    11 enabled rxonly
    12 enabled rxonly
    13 enabled rxonly
    14 enabled rxonly
    15 enabled rxonly
    16 enabled rxonly
    17 enabled rxonly
    18 enabled rxonly
    19 enabled rxonly
    20 enabled rxonly
    21 enabled rxonly
    22 enabled rxonly
    23 enabled rxonly
    24 enabled rxonly

    "
    ],
    "invocation": {
    "module_args": {
    "allow_agent": false,
    "boot_image": "primary",
    "command_list": null,
    .........
    "show_command": [
    "no page",
    "show cdp"
    ],

    One thing i'm a bit confused is when to use "command_list" and when to use "show_command". In this case, I would think "command_list" would be used, however it would return [].



  • 11.  RE: Issue with “arubaos_switch_ssh_cli” module
    Best Answer

    Posted Oct 09, 2019 04:42 PM

    Hmm.. I've tested both commands on a 3810 running KB.16.07.0002 and both seem to work... Is it that you're receving nothing in the variable? Could you try the following and post the results?

        - name: show cdp
          arubaos_switch_ssh_cli:
            ip: XXXXX
            user: XXXXX
            password: XXXXX
            show_command: ["no page", "show cdp"]
          register: cdp_result
    
        - debug:
            var: cdp_result

     

    Here's my solution that's working along with the output:

    ---
    - hosts: all
      gather_facts: False
      tasks:
        - name: show cdp
          arubaos_switch_ssh_cli:
            ip: "{{ansible_host}}"
            user: "{{ansible_user}}"
            password: "{{ansible_password}}"
            show_command: ["no page", "show cdp"]
          register: cdp_result
    
        - debug:
            var: cdp_result.cli_output[1]
    
        - name: show cdp traffic
          arubaos_switch_ssh_cli:
            ip: "{{ansible_host}}"
            user: "{{ansible_user}}"
            password: "{{ansible_password}}"
            show_command: ["show cdp traffic"]
          register: cdp_traffic_result
    
        - debug:
            var: cdp_traffic_result.cli_output[0]

    OUTPUT

    PLAY [all] *********************************************************************
    
    TASK [show cdp] ****************************************************************
    [DEPRECATION WARNING]: Distribution Ubuntu 16.04 on host switch1 should use
    /usr/bin/python3, but is using /usr/bin/python for backward compatibility with
    prior Ansible releases. A future Ansible release will default to using the
    discovered platform python for this host. See https://docs.ansible.com/ansible/
    2.8/reference_appendices/interpreter_discovery.html for more information. This
    feature will be removed in version 2.12. Deprecation warnings can be disabled
    by setting deprecation_warnings=False in ansible.cfg.
    ok: [switch1]
    
    TASK [debug] *******************************************************************
    ok: [switch1] => {
        "cdp_result.cli_output[1]": "
    Global CDP information

    Enable CDP [Yes] : Yes
    CDP mode [rxonly] : rxonly


    Port CDP
    ------ --------
    1 enabled
    2 enabled
    3 enabled
    4 enabled
    5 enabled
    6 enabled
    7 enabled
    8 enabled
    9 enabled
    10 enabled
    11 enabled
    12 enabled
    13 enabled
    14 enabled
    15 enabled
    16 enabled
    17 enabled
    18 enabled
    19 enabled
    20 enabled
    21 enabled
    22 enabled
    23 enabled
    24 enabled
    A1 enabled
    A2 enabled
    A3 enabled
    A4 enabled

    " } TASK [show cdp traffic] ******************************************************** ok: [switch1] TASK [debug] ******************************************************************* ok: [switch1] => { "cdp_traffic_result.cli_output[0]": "
    CDP frame Statistics:

    Port Transmitted Received Discarded Error
    No. Frames Frames Frames Frames
    -------- ------------ ----------- ----------- --------
    " } PLAY RECAP *********************************************************************


  • 12.  RE: Issue with “arubaos_switch_ssh_cli” module

    Posted Oct 09, 2019 04:46 PM

    @tiffany, sorry i posted earlier without trying, then tried later and found out both work now with "no page". thanks!



  • 13.  RE: Issue with “arubaos_switch_ssh_cli” module

    Posted Oct 09, 2019 05:22 PM

    Yay! I'm happy to hear!!

     

    In regards to your question about using the parameters, the command_list parameter is used for commands you don't want to receive the output from, and show_command is used for commands you want the output from. The way the module works is that ALL commands in the command_list parameter will be executed first then ALL the commands in the show_command will be executed and stored in a list variable named cli_output and each entry in the list will be the output of the corresponding command.

     

    And just a note to others who are using this module, you have to register the results of the module into a variable in order to access the cli_output list variable:

     

        - name: show cdp traffic
          arubaos_switch_ssh_cli:
            ip: "{{ansible_host}}"
            user: "{{ansible_user}}"
            password: "{{ansible_password}}"
            show_command: ["show cdp traffic"]
          register: cdp_traffic_result
    
        - debug:
            var: cdp_traffic_result.cli_output[0]


  • 14.  RE: Issue with “arubaos_switch_ssh_cli” module
    Best Answer

    Posted Oct 09, 2019 10:08 PM

    @tiffany got it, thanks!



  • 15.  RE: Issue with “arubaos_switch_ssh_cli” module

    Posted Oct 09, 2019 04:18 PM

    @jxia I think this is the solution... let me know if this works or not:

     

        - name: show cdp
          arubaos_switch_ssh_cli:
            ip: xxxxx
            user: xxxxx
            password: xxxxx
            show_command: ["no page", "show cdp"]
          register: cdp_result
    
        - debug:
            var: cdp_result.cli_output[1]