<p>Been there done that... 
Try prompt ']' and upgrade ansible to the version 2.8.1</p>

<pre><code>    "stdout_lines": [
        [
            "Running command on switch 1", 
            "Cleaning up unnecessary package files", 
            "No path specified, will use booted path flash:packages.conf", 
            "Cleaning flash:", 
            "  Scanning boot directory for packages ... done.", 
            "  Preparing packages list to delete ... ", 
            "    cat3k_caa-guestshell.16.03.07.SPA.pkg", 
            "      File is in use, will not delete.", 
            "    cat3k_caa-rpbase.16.03.07.SPA.pkg", 
            "      File is in use, will not delete.", 
            "    cat3k_caa-rpcore.16.03.07.SPA.pkg", 
            "      File is in use, will not delete.", 
            "    cat3k_caa-srdriver.16.03.07.SPA.pkg", 
            "      File is in use, will not delete.", 
            "    cat3k_caa-wcm.16.03.07.SPA.pkg", 
            "      File is in use, will not delete.", 
            "    cat3k_caa-webui.16.03.07.SPA.pkg", 
            "      File is in use, will not delete.", 
            "    packages.conf", 
            "      File is in use, will not delete.", 
            "  done.", 
            "  ", 
            "The following files will be deleted:", 
            "[1]:", 
            "/flash/cat3k_caa-guestshell.16.03.06.SPA.pkg", 
            "/flash/cat3k_caa-rpbase.16.03.06.SPA.pkg", 
            "/flash/cat3k_caa-rpcore.16.03.06.SPA.pkg", 
            "/flash/cat3k_caa-srdriver.16.03.06.SPA.pkg", 
            "/flash/cat3k_caa-universalk9.16.03.07.SPA.conf", 
            "/flash/cat3k_caa-wcm.16.03.06.SPA.pkg", 
            "/flash/cat3k_caa-webui.16.03.06.SPA.pkg", 
            "/flash/packages.conf.00-", 
            "", 
            "Do you want to proceed? [y/n]y", 
            "", 
            "[1]:", 
            "Deleting file flash:cat3k_caa-guestshell.16.03.06.SPA.pkg ... done.", 
            "Deleting file flash:cat3k_caa-rpbase.16.03.06.SPA.pkg ... done.", 
            "Deleting file flash:cat3k_caa-rpcore.16.03.06.SPA.pkg ... done.", 
            "Deleting file flash:cat3k_caa-srdriver.16.03.06.SPA.pkg ... done.", 
            "Deleting file flash:cat3k_caa-universalk9.16.03.07.SPA.conf ... done.", 
            "Deleting file flash:cat3k_caa-wcm.16.03.06.SPA.pkg ... done.", 
            "Deleting file flash:cat3k_caa-webui.16.03.06.SPA.pkg ... done.", 
            "Deleting file flash:packages.conf.00- ... done.", 
            "SUCCESS: Files deleted."
        ]
    ]
</code></pre>

CC BY-SA 4.0
2019-08-29T20:12:33.420Z
That....actually worked, even without upgrading Ansible. How did you know?
NetworkThenAutomate
CC BY-SA 4.0
2019-08-30T21:15:58.427Z
I think "request platform software" commands are somehow tricky regarding user interaction. I tried really hard to handle this case using Ansible ver 2.4.* at the end of 2018, but unsuccessfully. Perhaps due to paramiko behaviour. I'm pretty sure it was not a prompt syntax issue.
Had to use IB NetMRI as workaround for SW cleanup tasks.
But numerous Cisco XE integration issues were resolved in Ansible since ver 2.8. It's also possible to use "request platform software" commands now.
Modestas
CC BY-SA 4.0
2019-08-16T17:50:26.833Z
2019-08-16T17:56:47.810Z
2019-08-16T17:56:47.810Z
Modestas
<p>I'm new to the Ansible world, so I'll do my best to explain everything. If I leave something out or need to clarify, just let me know.</p>

<p>So, I've been working on upgrades for various Cisco switches/routers, and the 3850s running IOS-XE 16.x are causing me a slight issue. Basically, I want to run the command <code>request platform software package clean switch all file flash:</code> which will result in a prompt that says <code>Do you want to proceed? [y/n]</code> to which you simply enter "y" without the need for a CR.</p>

<p>It's important to note that if you were just copying/pasting configuration from a txt file, you could not paste in the "y" and you would manually need to enter it in. Doing so prevents the prompt from appearing (you can interact with the console while you wait 15-45 seconds for the output).</p>

<p>My Ansible code is waiting for the prompt, but when I run in -vvvv I do not see the output of the command and it ultimately times out. If I change the prompt to 
'[confirm]' and the response to "\r" I do see the output, but the cleanup is not taken (I can confirm because there would be more output and I can manually check after the fact).</p>

<p>I thought the prompt parameter would wait until the prompt occurs, but I'm guessing not? How does this actually work? It has not been a problem before because the prompts are generally instant. In this case, there's a delay every time.</p>

<p>Here's my code:</p>

<pre><code>- name: CLEAN UP OLD SOFTWARE
  ios_command:
    commands:
      - command: "request platform software package clean switch all file flash:"
        prompt: Do you want to proceed? \[y/n\]
        answer: "y"
  vars:
    ansible_command_timeout: 90
  when: compliant_ios_version == ansible_net_version
</code></pre>

<p>This is the result:</p>

<pre><code>WARNING: The below traceback may *not* be related to the actual failure.
  File "/tmp/ansible_ios_command_payload_XyRXx3/ansible_ios_command_payload.zip/ansible/module_utils/network/ios/ios.py", line 145, in run_commands
    return connection.run_commands(commands=commands, check_rc=check_rc)
  File "/tmp/ansible_ios_command_payload_XyRXx3/ansible_ios_command_payload.zip/ansible/module_utils/connection.py", line 182, in __rpc__
    raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)
fatal: [SWITCH1]: FAILED! =&gt; {
    "changed": false, 
    "invocation": {
        "module_args": {
            "auth_pass": null, 
            "authorize": null, 
            "commands": [
                {
                    "answer": "y", 
                    "command": "request platform software package clean switch all file flash:", 
                    "prompt": "Do you want to proceed? \\[y/n\\]"
                }
            ], 
            "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 40 secs.\nSee the timeout setting options in the Network Debug and Troubleshooting Guide."
}
        to retry, use: --limit @/opt/ansible/Test_Clean.retry

PLAY RECAP *************************************************************************************************************************
SWITCH1                   : ok=0    changed=0    unreachable=0    failed=1   

Playbook run took 0 days, 0 hours, 0 minutes, 92 seconds
</code></pre>

<p>Here's what would be displayed on the switch console:</p>

<pre><code>SWITCH1# request platform software package clean switch all file flash: 
This operation may take several minutes...
Running command on switch 1
Cleaning up unnecessary package files
  Scanning boot directory for packages ... done.
  Preparing packages list to delete ... 
    packages.conf
      File is in use, will not delete.
    cat3k_caa-guestshell.16.06.06.SPA.pkg
      File is in use, will not delete.
    cat3k_caa-rpbase.16.06.06.SPA.pkg
      File is in use, will not delete.
    cat3k_caa-rpcore.16.06.06.SPA.pkg
      File is in use, will not delete.
    cat3k_caa-srdriver.16.06.06.SPA.pkg
      File is in use, will not delete.
    cat3k_caa-webui.16.06.06.SPA.pkg
      File is in use, will not delete.
  done.

Running command on switch 2
Cleaning up unnecessary package files
  Scanning boot directory for packages ... done.
  Preparing packages list to delete ... 
    cat3k_caa-rpbase.16.06.06.SPA.pkg
      File is in use, will not delete.
    packages.conf
      File is in use, will not delete.
    cat3k_caa-guestshell.16.06.06.SPA.pkg
      File is in use, will not delete.
    cat3k_caa-rpcore.16.06.06.SPA.pkg
      File is in use, will not delete.
    cat3k_caa-srdriver.16.06.06.SPA.pkg
      File is in use, will not delete.
    cat3k_caa-webui.16.06.06.SPA.pkg
      File is in use, will not delete.
  done.

The following files will be deleted:
[switch 1]:
/flash/cat3k_caa-guestshell.16.06.05.SPA.pkg
/flash/cat3k_caa-rpbase.16.06.05.SPA.pkg
/flash/cat3k_caa-rpcore.16.06.05.SPA.pkg
/flash/cat3k_caa-srdriver.16.06.05.SPA.pkg
/flash/cat3k_caa-universalk9.16.06.06.SPA.conf
/flash/cat3k_caa-webui.16.06.05.SPA.pkg
/flash/packages.conf.00-
[switch 2]:
/flash/cat3k_caa-guestshell.16.06.05.SPA.pkg
/flash/cat3k_caa-rpbase.16.06.05.SPA.pkg
/flash/cat3k_caa-rpcore.16.06.05.SPA.pkg
/flash/cat3k_caa-srdriver.16.06.05.SPA.pkg
/flash/cat3k_caa-universalk9.16.06.06.SPA.conf
/flash/cat3k_caa-webui.16.06.05.SPA.pkg
/flash/packages.conf.00-

Do you want to proceed? [y/n]
</code></pre>

<p>I've searched around a lot and tried everything I could think of. I have not seen anyone come across this specific issue yet. Any ideas?</p>

<p>I'd appreciate any help. I'm pretty much dead in the water at this point.</p>

<ansible><networking><ios>
IOS_Command Module - Delayed Prompt Issue (Cisco 3850 - IOS XE)
NetworkThenAutomate
# IOS_Command Module - Delayed Prompt Issue (Cisco 3850 - IOS XE)

(Asked by: username_0 on 2019-08-14)

I'm new to the Ansible world, so I'll do my best to explain everything. If I leave something out or need to clarify, just let me know.
So, I've been working on upgrades for various Cisco switches/routers, and the 3850s running IOS-XE 16.x are causing me a slight issue. Basically, I want to run the command request platform software package clean switch all file flash: which will result in a prompt that says Do you want to proceed? [y/n] to which you simply enter "y" without the need for a CR.
It's important to note that if you were just copying/pasting configuration from a txt file, you could not paste in the "y" and you would manually need to enter it in. Doing so prevents the prompt from appearing (you can interact with the console while you wait 15-45 seconds for the output).
My Ansible code is waiting for the prompt, but when I run in -vvvv I do not see the output of the command and it ultimately times out. If I change the prompt to 
'[confirm]' and the response to "\r" I do see the output, but the cleanup is not taken (I can confirm because there would be more output and I can manually check after the fact).
I thought the prompt parameter would wait until the prompt occurs, but I'm guessing not? How does this actually work? It has not been a problem before because the prompts are generally instant. In this case, there's a delay every time.
Here's my code:
- name: CLEAN UP OLD SOFTWARE
  ios_command:
    commands:
      - command: "request platform software package clean switch all file flash:"
        prompt: Do you want to proceed? \[y/n\]
        answer: "y"
  vars:
    ansible_command_timeout: 90
  when: compliant_ios_version == ansible_net_version

This is the result:
WARNING: The below traceback may *not* be related to the actual failure.
  File "/tmp/ansible_ios_command_payload_XyRXx3/ansible_ios_command_payload.zip/ansible/module_utils/network/ios/ios.py", line 145, in run_commands
    return connection.run_commands(commands=commands, check_rc=check_rc)
  File "/tmp/ansible_ios_command_payload_XyRXx3/ansible_ios_command_payload.zip/ansible/module_utils/connection.py", line 182, in __rpc__
    raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)
fatal: [SWITCH1]: FAILED! => {
    "changed": false, 
    "invocation": {
        "module_args": {
            "auth_pass": null, 
            "authorize": null, 
            "commands": [
                {
                    "answer": "y", 
                    "command": "request platform software package clean switch all file flash:", 
                    "prompt": "Do you want to proceed? \\[y/n\\]"
                }
            ], 
            "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 40 secs.\nSee the timeout setting options in the Network Debug and Troubleshooting Guide."
}
        to retry, use: --limit @/opt/ansible/Test_Clean.retry

PLAY RECAP *************************************************************************************************************************
SWITCH1                   : ok=0    changed=0    unreachable=0    failed=1   

Playbook run took 0 days, 0 hours, 0 minutes, 92 seconds

Here's what would be displayed on the switch console:
SWITCH1# request platform software package clean switch all file flash: 
This operation may take several minutes...
Running command on switch 1
Cleaning up unnecessary package files
  Scanning boot directory for packages ... done.
  Preparing packages list to delete ... 
    packages.conf
      File is in use, will not delete.
    cat3k_caa-guestshell.16.06.06.SPA.pkg
      File is in use, will not delete.
    cat3k_caa-rpbase.16.06.06.SPA.pkg
      File is in use, will not delete.
    cat3k_caa-rpcore.16.06.06.SPA.pkg
      File is in use, will not delete.
    cat3k_caa-srdriver.16.06.06.SPA.pkg
      File is in use, will not delete.
    cat3k_caa-webui.16.06.06.SPA.pkg
      File is in use, will not delete.
  done.

Running command on switch 2
Cleaning up unnecessary package files
  Scanning boot directory for packages ... done.
  Preparing packages list to delete ... 
    cat3k_caa-rpbase.16.06.06.SPA.pkg
      File is in use, will not delete.
    packages.conf
      File is in use, will not delete.
    cat3k_caa-guestshell.16.06.06.SPA.pkg
      File is in use, will not delete.
    cat3k_caa-rpcore.16.06.06.SPA.pkg
      File is in use, will not delete.
    cat3k_caa-srdriver.16.06.06.SPA.pkg
      File is in use, will not delete.
    cat3k_caa-webui.16.06.06.SPA.pkg
      File is in use, will not delete.
  done.

The following files will be deleted:
[switch 1]:
/flash/cat3k_caa-guestshell.16.06.05.SPA.pkg
/flash/cat3k_caa-rpbase.16.06.05.SPA.pkg
/flash/cat3k_caa-rpcore.16.06.05.SPA.pkg
/flash/cat3k_caa-srdriver.16.06.05.SPA.pkg
/flash/cat3k_caa-universalk9.16.06.06.SPA.conf
/flash/cat3k_caa-webui.16.06.05.SPA.pkg
/flash/packages.conf.00-
[switch 2]:
/flash/cat3k_caa-guestshell.16.06.05.SPA.pkg
/flash/cat3k_caa-rpbase.16.06.05.SPA.pkg
/flash/cat3k_caa-rpcore.16.06.05.SPA.pkg
/flash/cat3k_caa-srdriver.16.06.05.SPA.pkg
/flash/cat3k_caa-universalk9.16.06.06.SPA.conf
/flash/cat3k_caa-webui.16.06.05.SPA.pkg
/flash/packages.conf.00-

Do you want to proceed? [y/n]

I've searched around a lot and tried everything I could think of. I have not seen anyone come across this specific issue yet. Any ideas?
I'd appreciate any help. I'm pretty much dead in the water at this point.

**Tags:** ansible, networking, ios


---

## 1 answers

### Answer by username_1 on 2019-08-16. Score: 1

Been there done that... 
Try prompt ']' and upgrade ansible to the version 2.8.1
    "stdout_lines": [
        [
            "Running command on switch 1", 
            "Cleaning up unnecessary package files", 
            "No path specified, will use booted path flash:packages.conf", 
            "Cleaning flash:", 
            "  Scanning boot directory for packages ... done.", 
            "  Preparing packages list to delete ... ", 
            "    cat3k_caa-guestshell.16.03.07.SPA.pkg", 
            "      File is in use, will not delete.", 
            "    cat3k_caa-rpbase.16.03.07.SPA.pkg", 
            "      File is in use, will not delete.", 
            "    cat3k_caa-rpcore.16.03.07.SPA.pkg", 
            "      File is in use, will not delete.", 
            "    cat3k_caa-srdriver.16.03.07.SPA.pkg", 
            "      File is in use, will not delete.", 
            "    cat3k_caa-wcm.16.03.07.SPA.pkg", 
            "      File is in use, will not delete.", 
            "    cat3k_caa-webui.16.03.07.SPA.pkg", 
            "      File is in use, will not delete.", 
            "    packages.conf", 
            "      File is in use, will not delete.", 
            "  done.", 
            "  ", 
            "The following files will be deleted:", 
            "[1]:", 
            "/flash/cat3k_caa-guestshell.16.03.06.SPA.pkg", 
            "/flash/cat3k_caa-rpbase.16.03.06.SPA.pkg", 
            "/flash/cat3k_caa-rpcore.16.03.06.SPA.pkg", 
            "/flash/cat3k_caa-srdriver.16.03.06.SPA.pkg", 
            "/flash/cat3k_caa-universalk9.16.03.07.SPA.conf", 
            "/flash/cat3k_caa-wcm.16.03.06.SPA.pkg", 
            "/flash/cat3k_caa-webui.16.03.06.SPA.pkg", 
            "/flash/packages.conf.00-", 
            "", 
            "Do you want to proceed? [y/n]y", 
            "", 
            "[1]:", 
            "Deleting file flash:cat3k_caa-guestshell.16.03.06.SPA.pkg ... done.", 
            "Deleting file flash:cat3k_caa-rpbase.16.03.06.SPA.pkg ... done.", 
            "Deleting file flash:cat3k_caa-rpcore.16.03.06.SPA.pkg ... done.", 
            "Deleting file flash:cat3k_caa-srdriver.16.03.06.SPA.pkg ... done.", 
            "Deleting file flash:cat3k_caa-universalk9.16.03.07.SPA.conf ... done.", 
            "Deleting file flash:cat3k_caa-wcm.16.03.06.SPA.pkg ... done.", 
            "Deleting file flash:cat3k_caa-webui.16.03.06.SPA.pkg ... done.", 
            "Deleting file flash:packages.conf.00- ... done.", 
            "SUCCESS: Files deleted."
        ]
    ]

> **Comments:**
> **username_0**: That....actually worked, even without upgrading Ansible. How did you know?  
> **username_1**: I think "request platform software" commands are somehow tricky regarding user interaction. I tried really hard to handle this case using Ansible ver 2.4.* at the end of 2018, but unsuccessfully. Perhaps due to paramiko behaviour. I'm pretty sure it was not a prompt syntax issue. Had to use IB NetMRI as workaround for SW cleanup tasks. But numerous Cisco XE integration issues were resolved in Ansible since ver 2.8. It's also possible to use "request platform software" commands now.  

---

