aruba / aos-switch-ansible-collection

Ansible collection for AOS-Switch switches
67 stars 17 forks source link

Timeout while running arubaoss_command #25

Open LedaxPia opened 2 years ago

LedaxPia commented 2 years ago

Hey there! I ran into another issue while running my Playbook. The Playbook is looking like this:

---
-  hosts: switch01
   collections:
     - arubanetworks.aos_switch
   vars:
     ansible_connection: network_cli
     ansible_command_timeout: 120
   tasks:
     - name: Upload new config
       arubaoss_command:
         commands:
           - command:  "copy tftp startup-config 172.16.XX.XXX orig.cfg"
             prompt:
               - "Device may be rebooted, do you want to continue [y/n]?"
             answer:
               - y
         output_file: /etc/ansible/output.cfg

The output file of the playbook looks like this even though the switch successfully gets the command and reboots during the 120 seconds:

command: copy tftp startup-config 172.16.XX.XXX orig.cfg
response: timeout value 120 seconds reached while trying to send command: copy tftp startup-config 172.16.XX.XXX orig.cfg

and the output of ansible: {"changed": false, "stdout": ["timeout value 120 seconds reached while trying to send command: copy tftp startup-config 172.16.XX.XXX orig.cfg"], "stdout_lines": [["timeout value 120 seconds reached while trying to send command: copy tftp startup-config 172.16.XX.XXX orig.cfg"]]}

Some more information: CentOS 7 with ansible 2.9.27 and Python 3.6.8 Aruba 2530 8G PoE+-Switches with YA.16.10.0016

ansible.cfg:

[defaults]
host_key_checking = false
NETWORK_GROUP_MODULES = arubaoss

Inventory:

all:
  children:
    switch:
      hosts:
        switch01:
          ansible_connection: local
          ansible_host: 172.16.XX.XX
          ansible_network_os: arubanetworks.aos_switch.arubaoss
          ansible_password: XXXXXXXXXXXX
          ansible_python_interpreter: /usr/bin/python3
          ansible_user: XXXXXXXXXX

Thanks for looking into this!

tchiapuziowong commented 2 years ago

hi @LedaxPia this is due to Ansible unable to match on the prompt you specified. Ansible uses regex to match what you provide as a prompt to what's being shown via the switch CLI.

To make sure it matches correctly here is the proper prompt value:

---
-  hosts: switch01
   collections:
     - arubanetworks.aos_switch
   vars:
     ansible_connection: network_cli
     ansible_command_timeout: 120
   tasks:
     - name: Upload new config
       arubaoss_command:
         commands:
           - command:  "copy tftp startup-config 172.16.XX.XXX orig.cfg"
             prompt:
               - "Device may be rebooted, do you want to continue \[y\/n\]\?"
             answer:
               - y
         output_file: /etc/ansible/output.cfg

alternatively this also works:

prompt:
  - .*\[y\/n\]\?

I use this site to practice my regex expressions on, ensure that the "Python" language is selected on the left side!

Please try that again and see if your issue is resolved with the proper regex prompt!

LedaxPia commented 2 years ago

Hey, thanks for looking into this! So with the first regex I got a:

Syntax Error while loading YAML. 
found unknown escape character
The offending line appears to be:
             prompt:
               - "Device may be rebooted, do you want to continue \[y\/n\]\?"
                                                                  ^ here

With the second regex (.*[y\/n]\?) I came to the same problem: Rolling out the new config on the switch is working fine but Ansible still gives me the same timeout-error. :/

tchiapuziowong commented 2 years ago

Did you try using single quotations ' instead of the double "

the syntax error seems to be an interpretation/formatting issue