尝试让ansible删除cisco路由器上的文件时超时

时间:2018-03-27 16:38:28

标签: command ansible cisco

当我尝试从我的cisco IOS路由器的闪存中删除文件时,我的剧本中出现错误。下面是代码,下面是我得到的错误

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

2 个答案:

答案 0 :(得分:3)

因此命令要求确认,/r无法正常工作。根据Ansible的文档,您可以在ios_command模块中使用“prompt”参数。

文档示例 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

在您的情况下,您应该手动运行命令以查看提示内容和所需答案,然后填写promptanswer参数。

从闪存中删除示例使用正确参数进行更新

  - 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

答案 1 :(得分:0)

想发布此邮件,以防将来有人在这里绊倒。典型的文件提示对话框如下,实际上需要对两个单独的提示进行响应。

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中处理两个提示非常困难,因此我在网络交换机上配置了“文件提示安静”。 此配置将使切换提示仅用于确认,并且易于在您的剧本中进行确认。

- command: Delete {{ old_image_path }}
  prompt: Delete {{ old_image_path }}\? \[confirm\]
  answer: 'y'