Problems with ios_command and prompt '[y/n]'

Hi,

I have a problem with the ios_command and the C9200L switch when updating the IOS-XE. One step of the upgrade is

On step is to remove inactive IOS versions:

install remove inactive
(…)
Do you want to remove the above files? [y/n]

the part of the playbook looks like:

Error output is:

The full traceback is:
File “/tmp/ansible_ios_command_payload_hxb3x8bq/ansible_ios_command_payload.zip/ansible/module_utils/network/ios/ios.py”, line 135, in run_commands
return connection.run_commands(commands=commands, check_rc=check_rc)
File “/tmp/ansible_ios_command_payload_hxb3x8bq/ansible_ios_command_payload.zip/ansible/module_utils/connection.py”, line 185, in rpc
raise ConnectionError(to_text(msg, errors=‘surrogate_then_replace’), code=code)

fatal: [switch]: FAILED! => {
“changed”: false,
“invocation”: {
“module_args”: {
“auth_pass”: null,
“authorize”: null,
“commands”: [
{
“answer”: “y”,
“check_all”: false,
“command”: “install remove inactive”,
“newline”: true,
“output”: null,
“prompt”: “\[y\/n\]”,
“sendonly”: false
}
],
“host”: null,
“interval”: 1,
“match”: “all”,
“password”: null,
“port”: null,
“provider”: null,
“retries”: 10,
“ssh_keyfile”: null,
“timeout”: null,
“username”: null,
“wait_for”: null
}
},
“msg”: “command timeout triggered, timeout value is 180 secs.\nSee the timeout setting options in the Network Debug and Troubleshooting Guide.”
}

The value of prompt option is a python regex hence either handle special character in prompt correctly by using escape character or remove those characters from prompt completely.

For example:

  • name: remove old OS files
    ios_command:
    commands:
  • command: install remove inactive
    prompt: Do you want to remove above files
    answer: y

Still the same problem (timeout). I copied the string direct from the switch. Any idea how to debug this in deep?

The full traceback is:
File “/tmp/ansible_ios_command_payload_dz14oih4/ansible_ios_command_payload.zip/ansible/module_utils/network/ios/ios.py”, line 135, in run_commands
return connection.run_commands(commands=commands, check_rc=check_rc)
File “/tmp/ansible_ios_command_payload_dz14oih4/ansible_ios_command_payload.zip/ansible/module_utils/connection.py”, line 185, in rpc
raise ConnectionError(to_text(msg, errors=‘surrogate_then_replace’), code=code)

fatal: [switch]: FAILED! => {
“changed”: false,
“invocation”: {
“module_args”: {
“auth_pass”: null,
“authorize”: null,
“commands”: [
{
“answer”: “y”,
“check_all”: false,
“command”: “install remove inactive”,
“newline”: true,
“output”: null,
“prompt”: “Do you want to remove the above files”,
“sendonly”: false
}
],
“host”: null,
“interval”: 1,
“match”: “all”,
“password”: null,
“port”: null,
“provider”: null,
“retries”: 10,
“ssh_keyfile”: null,
“timeout”: null,
“username”: null,
“wait_for”: null
}
},
“msg”: “command timeout triggered, timeout value is 300 secs.\nSee the timeout setting options in the Network Debug and Troubleshooting Guide.”

Solution: Do not forget the ticks around the ‘y’.

  • name: remove old OS files
    ios_command:
    commands:
  • command: install remove inactive
    prompt: Do you want to remove the above files
    answer: ‘y’
    vars:
    ansible_command_timeout: 180