# Problems with ios\_command and prompt '\[y/n\]'

**URL:** <https://forum.ansible.com/t/problems-with-ios-command-and-prompt-y-n/32135>\
**Category:** Ansible Project\
**Created:** [February 4, 2020, 2:28pm UTC](https://forum.ansible.com/t/problems-with-ios-command-and-prompt-y-n/32135 "2020-02-04T14:28:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Heinz\_Meier](https://avatars.discourse-cdn.com/v4/letter/h/7ba0ec/32.png) [@Heinz\_Meier](https://forum.ansible.com/u/Heinz_Meier)\
**Post date:** [February 4, 2020, 2:28pm UTC](https://forum.ansible.com/t/problems-with-ios-command-and-prompt-y-n/32135/1 "2020-02-04T14:28:09Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![Heinz\_Meier](https://avatars.discourse-cdn.com/v4/letter/h/7ba0ec/32.png) [@Heinz\_Meier](https://forum.ansible.com/u/Heinz_Meier)\
**Post date:** [February 4, 2020, 2:33pm UTC](https://forum.ansible.com/t/problems-with-ios-command-and-prompt-y-n/32135/2 "2020-02-04T14:33:00Z")

</div>

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.”  
}

---

<div class="post-metadata">

**Author:** ![ganeshrn](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ganeshrn/32/1021_2.png) [@ganeshrn](https://forum.ansible.com/u/ganeshrn)\
**Post date:** [February 4, 2020, 3:01pm UTC](https://forum.ansible.com/t/problems-with-ios-command-and-prompt-y-n/32135/3 "2020-02-04T15:01:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Heinz\_Meier](https://avatars.discourse-cdn.com/v4/letter/h/7ba0ec/32.png) [@Heinz\_Meier](https://forum.ansible.com/u/Heinz_Meier)\
**Post date:** [February 4, 2020, 3:27pm UTC](https://forum.ansible.com/t/problems-with-ios-command-and-prompt-y-n/32135/4 "2020-02-04T15:27:36Z")

</div>

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.”

---

<div class="post-metadata">

**Author:** ![Heinz\_Meier](https://avatars.discourse-cdn.com/v4/letter/h/7ba0ec/32.png) [@Heinz\_Meier](https://forum.ansible.com/u/Heinz_Meier)\
**Post date:** [February 4, 2020, 3:30pm UTC](https://forum.ansible.com/t/problems-with-ios-command-and-prompt-y-n/32135/5 "2020-02-04T15:30:36Z")

</div>

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
