Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iosxr_command with wait_for is not detecting the contains string and times out #528

Open
jbrentfoster opened this issue Jan 14, 2025 · 0 comments

Comments

@jbrentfoster
Copy link

SUMMARY

I'm using Ansible to execute a command on a Cisco IOS-XR router. The command initiates a software upgrade. When the "synchronous" key word is added to the command, the command prompt will not return until the operation is complete. The router will periodically update the status of the upgrade and will finally return the command prompt when complete (often resulting in a reload).
The Ansible task is using wait_for and looking at the result[0[ output to find completed without error. However, this does not work and it hangs util the timeout is reached (1800 seconds).

ISSUE TYPE
  • Bug Report
COMPONENT NAME

iosxr_command

ANSIBLE VERSION
ansible [core 2.17.7]
  config file = /home/vxr/ansible-xr-upgrade/ansible.cfg
  configured module search path = ['/home/vxr/.ansible/collections/ansible_collections/napalm/napalm/plugins/modules']
  ansible python module location = /home/vxr/xrupgrade_venv/lib/python3.10/site-packages/ansible
  ansible collection location = /home/vxr/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/vxr/xrupgrade_venv/bin/ansible
  python version = 3.10.12 (main, Nov  6 2024, 20:22:13) [GCC 11.4.0] (/home/vxr/xrupgrade_venv/bin/python3)
  jinja version = 3.1.5
  libyaml = True
COLLECTION VERSION
(xrupgrade_venv) vxr@ubuntu22:~/ansible-xr-upgrade$ ansible-galaxy collection list community.general

# /home/vxr/xrupgrade_venv/lib/python3.10/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 9.5.2
CONFIGURATION
(xrupgrade_venv) vxr@ubuntu22:~/ansible-xr-upgrade$ ansible-config dump --only-changed
CONFIG_FILE() = /home/vxr/ansible-xr-upgrade/ansible.cfg
DEFAULT_ACTION_PLUGIN_PATH(/home/vxr/ansible-xr-upgrade/ansible.cfg) = ['/home/vxr/.ansible/collections/ansible_collections/napalm/napalm/>
DEFAULT_MODULE_PATH(/home/vxr/ansible-xr-upgrade/ansible.cfg) = ['/home/vxr/.ansible/collections/ansible_collections/napalm/napalm/plugins>
HOST_KEY_CHECKING(/home/vxr/ansible-xr-upgrade/ansible.cfg) = False
OS / ENVIRONMENT

Ubuntu 22.04.4 LTS running as VM in VMware host

STEPS TO REPRODUCE

The Ansible task is:

        - name: "Running CLI install image"
          iosxr_command:
            commands:
              - command: 'install replace /harddisk:/8000-x64-7.11.1.iso noprompt reload commit synchronous'
            wait_for:
              - result[0] contains completed without error
          vars:
            ansible_command_timeout: 1800
          register: iosxr_install

This initiates the software upgrade and the script will wait for up to 1800 seconds before timing out.
It should stop when it detects the string "completed without error".
However, it always times out.
If you following the upgrade directly on the router (mirroring what Ansible would be seeing), you can see it completes and the completed without error string is received.

1/13/2025 4:45 PM • 
RP/0/RP0/CPU0:c8k-1#install attach
Mon Jan 13 21:41:17.796 UTC
Attached to:
  install replace /harddisk:/8000-x64-7.11.1.iso reload commit
Transaction 3
Press Ctrl-C to return to the exec prompt. This will not cancel the install operation

Current activity: Verify input and download ISO ...
Current activity: Extract main ISO contents to internal repository if needed .......
Current activity: Veto check .
Current activity: Package add or other package operation
Current activity: Apply by reload

Transaction 3: Pre-reload steps completed without error, reloading
 .
Connection to 172.26.228.240 closed.

It seems the wait_for is not working.

Note: The timeout is set for 1800 seconds (30 minutes), but this task usually takes less than 10 minutes on the router.

EXPECTED RESULTS

Expect the Ansible task to complete when the software upgrade is applied and the completed without error string is received.

ACTUAL RESULTS

The task simply times out.

1/13/2025 5:14 PM • 
Perform task: TASK: Running CLI install image (N)o/(y)es/(c)ontinue: **********************************************************************

TASK [Running CLI install image] **********************************************************************************************************
task path: /home/vxr/ansible-xr-upgrade/playbook.yml:165
redirecting (type: connection) ansible.builtin.network_cli to ansible.netcommon.network_cli
redirecting (type: modules) ansible.builtin.iosxr_command to cisco.iosxr.iosxr_command
redirecting (type: action) ansible.builtin.iosxr to cisco.iosxr.iosxr
redirecting (type: action) ansible.builtin.iosxr to cisco.iosxr.iosxr
redirecting (type: action) ansible.builtin.iosxr to cisco.iosxr.iosxr
redirecting (type: modules) ansible.builtin.iosxr_command to cisco.iosxr.iosxr_command
The full traceback is:
  File "/home/vxr/xrupgrade_venv/lib/python3.10/site-packages/ansible_collections/cisco/iosxr/plugins/module_utils/network/iosxr/iosxr.py", line 492, in run_commands
    return connection.run_commands(commands=commands, check_rc=check_rc)
  File "/home/vxr/xrupgrade_venv/lib/python3.10/site-packages/ansible/module_utils/connection.py", line 199, in __rpc__
    raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)
fatal: [c8k-1]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "commands": [
                {
                    "command": "install replace /harddisk:/8000-x64-7.11.1.iso noprompt reload commit synchronous"
                }
            ],
            "interval": 1,
            "match": "all",
            "retries": 10,
            "wait_for": [
                "result[0] contains Apply by reload"
            ]
        }
    },
    "msg": "command timeout triggered, timeout value is 1800 secs.\nSee the timeout setting options in the Network Debug and Troubleshooting Guide."
}

PLAY RECAP ********************************************************************************************************************************
c8k-1                      : ok=2    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant