Answer to prompt not passing when used cli_command module

Hello,

I am trying to upgrade cat9k switch using ansible, facing issues when trying to run the command “install Activate”.

when run “install Activate” command manually in cat9k switch, I am getting the prompt within in 30 seconds like below.

`
cat9k-1#install Activate
install_activate: START Wed Jun 10 05:05:50 PDT 2020
install_activate: Activating PACKAGE

*Jun 10 20:01:52.230: %INSTALL-5-INSTALL_START_INFO: Switch 1 R0/0: install_engine: Started install activateFollowing packages shall be activated:
/flash/cat9k-wlc.16.06.05.SPA.pkg
/flash/cat9k-webui.16.06.05.SPA.pkg
/flash/cat9k-srdriver.16.06.05.SPA.pkg
/flash/cat9k-sipspa.16.06.05.SPA.pkg
/flash/cat9k-sipbase.16.06.05.SPA.pkg
/flash/cat9k-rpboot.16.06.05.SPA.pkg
/flash/cat9k-rpbase.16.06.05.SPA.pkg
/flash/cat9k-guestshell.16.06.05.SPA.pkg
/flash/cat9k-espbase.16.06.05.SPA.pkg
/flash/cat9k-cc_srdriver.16.06.05.SPA.pkg

This operation requires a reload of the system. Do you want to proceed? [y/n]

`

Below is the playbook snippet:

`

  • name: Run install activate
    cli_command:
    command: install Activate
    prompt:
  • Press Quit(q) to exit, you may save configuration and re-enter the command. [y/n/q]
  • This operation requires a reload of the system. Do you want to proceed? [y/n]
    answer:
  • n
    vars:
    ansible_command_timeout: 300
    `

verbose output: ansible-playbook -vvv -i hosts site.yaml snippet.

`
The full traceback is:
WARNING: The below traceback may not be related to the actual failure.
File “/tmp/ansible_cli_command_payload_6575kN/ansible_cli_command_payload.zip/ansible/modules/network/cli/cli_command.py”, line 167, in main
File “/tmp/ansible_cli_command_payload_6575kN/ansible_cli_command_payload.zip/ansible/module_utils/connection.py”, line 185, in rpc
raise ConnectionError(to_text(msg, errors=‘surrogate_then_replace’), code=code)
fatal: [66.220.26.111]: FAILED! => {
“changed”: false,
“invocation”: {
“module_args”: {
“answer”: [
“n”
],
“check_all”: false,
“command”: “install Activate”,
“newline”: true,
“prompt”: [
“Press Quit(q) to exit, you may save configuration and re-enter the command. [y/n/q]”,
“This operation requires a reload of the system. Do you want to proceed? [y/n]”
],
“sendonly”: false
}
},
“msg”: “command timeout triggered, timeout value is 300 secs.\nSee the timeout setting options in the Network Debug and Troubleshooting Guide.”
}

`

How to fix this issue?

Thanks,
Mohan

I changed the prompt in the ansible-playbook like below, it worked fine.

prompt:

  • “save”
  • “reload”