techkid
techkid

Reputation: 139

Timeout when trying to have ansible delete a file on cisco routers

Im having errors in my playbook when I try to delete files from the flash of my cisco IOS router. Below is the code and underneath is the error I am getting

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

Upvotes: 0

Views: 1631

Answers (2)

Nathan Bailey
Nathan Bailey

Reputation: 1

Wanted to post this in-case someone else stumbles here in the future. The typical file prompt dialog is as follows and actually requires response for two separate prompts.

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]

Dealing with two prompts in ansible proved difficult, so I configured "file prompt quiet" on the network switch. This configuration will make the switch prompt only for confirmation and its easy to confirm in your playbook.

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

Upvotes: 0

Jeff Gebhardt - MSFT
Jeff Gebhardt - MSFT

Reputation: 309

So the command is asking for confirmation and /r is not working. According to Ansible's documentation you can use the "prompt" parameter with the ios_command module.

Example from Documentation 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

And in your case, you should run the command manually to see what the prompt is and the required answer, then fill in the prompt and answer parameters.

Example delete from flash (Update with correct parameters)

  - 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

Upvotes: 3

Related Questions