尝试在思科路由器上删除文件时超时
Timeout when trying to have ansible delete a file on cisco routers
当我尝试从我的 cisco IOS 路由器的闪存中删除文件时,我的 playbook 出现错误。下面是代码,下面是我得到的错误
- ios_command:
commands: "delete flash:c1900-universalk9-mz.SPA.155-3.M.bin\r"
FAILED! => {"changed": false, "msg": "timeout trying to send command: delete flash:c1900-universalk9-mz.SPA.155-3.M.bin", "rc": 1}
所以该命令要求确认并且 /r
不工作。根据 Ansible 的文档,您可以将 "prompt" 参数与 ios_command 模块一起使用。
来自文档的示例
http://docs.ansible.com/ansible/latest/modules/ios_command_module.html
- name: run command that requires answering a prompt
ios_command:
commands:
- command: 'clear counters GigabitEthernet0/2'
prompt: 'Clear "show interface" counters on this interface [confirm]'
answer: c
在您的情况下,您应该手动 运行 命令以查看提示内容和所需答案,然后填写 prompt
和 answer
参数。
示例从闪存中删除(使用正确的参数更新)
- name: run command that requires answering a prompt
ios_command:
commands:
- command: 'delete flash:c1900-universalk9-mz.SPA.155-3.M.bin'
prompt: 'Delete "flash:c1900-universalk9-mz.SPA.155-3.M.bin" from flash [confirm]'
answer: c
想post这个in-case以后别人在这里跌跌撞撞。典型的文件提示对话框如下,实际上需要响应两个单独的提示。
switch_name#delete c2960s-universalk9-mz.152-7.E2.bin
Delete filename [c2960s-universalk9-mz.152-7.E2.bin]?
Delete flash:/c2960s-universalk9-mz.152-7.E2.bin? [confirm]
在ansible中处理两个提示很困难,所以我在网络交换机上配置了“file prompt quiet”。
此配置将使切换提示仅用于确认,并且很容易在您的剧本中确认。
- command: Delete {{ old_image_path }}
prompt: Delete {{ old_image_path }}\? \[confirm\]
answer: 'y'
当我尝试从我的 cisco IOS 路由器的闪存中删除文件时,我的 playbook 出现错误。下面是代码,下面是我得到的错误
- ios_command:
commands: "delete flash:c1900-universalk9-mz.SPA.155-3.M.bin\r"
FAILED! => {"changed": false, "msg": "timeout trying to send command: delete flash:c1900-universalk9-mz.SPA.155-3.M.bin", "rc": 1}
所以该命令要求确认并且 /r
不工作。根据 Ansible 的文档,您可以将 "prompt" 参数与 ios_command 模块一起使用。
来自文档的示例 http://docs.ansible.com/ansible/latest/modules/ios_command_module.html
- name: run command that requires answering a prompt
ios_command:
commands:
- command: 'clear counters GigabitEthernet0/2'
prompt: 'Clear "show interface" counters on this interface [confirm]'
answer: c
在您的情况下,您应该手动 运行 命令以查看提示内容和所需答案,然后填写 prompt
和 answer
参数。
示例从闪存中删除(使用正确的参数更新)
- name: run command that requires answering a prompt
ios_command:
commands:
- command: 'delete flash:c1900-universalk9-mz.SPA.155-3.M.bin'
prompt: 'Delete "flash:c1900-universalk9-mz.SPA.155-3.M.bin" from flash [confirm]'
answer: c
想post这个in-case以后别人在这里跌跌撞撞。典型的文件提示对话框如下,实际上需要响应两个单独的提示。
switch_name#delete c2960s-universalk9-mz.152-7.E2.bin
Delete filename [c2960s-universalk9-mz.152-7.E2.bin]?
Delete flash:/c2960s-universalk9-mz.152-7.E2.bin? [confirm]
在ansible中处理两个提示很困难,所以我在网络交换机上配置了“file prompt quiet”。 此配置将使切换提示仅用于确认,并且很容易在您的剧本中确认。
- command: Delete {{ old_image_path }}
prompt: Delete {{ old_image_path }}\? \[confirm\]
answer: 'y'