Problems with ios_command and prompt '[y/n]'

883 views
Skip to first unread message

Heinz Meier

unread,
Feb 4, 2020, 9:28:10 AM2/4/20
to Ansible Project
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:

---
- hosts: cisco
  tasks:

    - name: Upgrade IOS-XE
      block:

      - name: remove old OS files
        ios_command:
          commands:
            - command: install remove inactive
              prompt: '[y/n]'
              answer: 'y'
        vars:
          ansible_command_timeout: 180

      when: (ansible_net_version != compliant_ios_version) and
            (ansible_net_model is regex("9200"))



Anytime I run this playbook this tasks fails with the timeout. 180 sec should be enough time to delete the files.

I tried to prolong the timeout value, and all combinations of the full text of the question and backslashes in front of the brackets and the forward slash.

Always timeout.

Any ideas?

Michael Schwartzkopff

Heinz Meier

unread,
Feb 4, 2020, 9:33:33 AM2/4/20
to ansible...@googlegroups.com
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."
}

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/0aae16a2-4463-4828-a3e5-bdf9190ce35e%40googlegroups.com.

Ganesh Nalawade

unread,
Feb 4, 2020, 10:02:03 AM2/4/20
to ansible...@googlegroups.com
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
--
Regards,
Ganesh B. Nalawade
Principal Engineer
Ansible by Red Hat
irc: ganeshrn

Heinz Meier

unread,
Feb 4, 2020, 10:28:04 AM2/4/20
to ansible...@googlegroups.com
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."

Heinz Meier

unread,
Feb 4, 2020, 10:31:07 AM2/4/20
to ansible...@googlegroups.com
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
Reply all
Reply to author
Forward
0 new messages