06-06-2023 04:15 AM
I'm trying to configure Cisco IOS XR devices with Ansible. I assume the Cisco.Iosxr collection would be suitable for such task. But the Cisco.Iosxr collection seems to envoke a command "show inventory", which does not exist on my IOS XR devices.
Cisco IOS XR Version:
RP/0/RP0/CPU0:XR3#show version Tue May 23 08:42:26.758 UTC Cisco IOS XR Software, Version 7.8.1 LNT Copyright (c) 2013-2022 by Cisco Systems, Inc. Build Information: Built By : ingunawa Built On : Wed Nov 30 13:00:28 UTC 2022 Build Host : iox-lnx-108 Workspace : /auto/srcarchive13/prod/7.8.1/xrd-control-plane/ws Version : 7.8.1 Label : 7.8.1 cisco XRd Control Plane cisco XRd-CP-C-01 processor with 512GB of memory XR3 uptime is 3 weeks, 6 days, 17 hours, 11 minutes XRd Control Plane Container
Ansible Playbook
name: Create Config Backup hosts: CERouters gather_facts: false tasks: - name: backup cisco.iosxr.iosxr_config: backup: yes
Ansible playbook output
fatal: [xr3]: FAILED! => { "changed": false, "invocation": { "module_args": { "admin": false, "after": null, "backup": true, "backup_options": null, "before": null, "comment": "configured by iosxr_config", "config": null, "disable_default_comment": false, "exclusive": false, "force": false, "label": null, "lines": null, "match": "line", "parents": null, "replace": "line", "src": null } }, "msg": "show inventory\r\n\r ^\r\n% Invalid input detected at '^' marker.\r\nRP/0/RP0/CPU0:XR3#" }
With the Cisco.Ios collection I'm able to do a backup, but get more errors when trying to configure VRF with Jinja2 templates. But I think Cisco.Iosxr should be the way to go.
My last approach would be to use the ansible.netcommon.netconf_config module to send JSON/XML commands to the Cisco IOS XR devices, which does work, but is very tedious.
Or is there another Ansible collection to configure Cisco IOS XR devices?
Thanks for any help.
03-04-2025 11:55 PM - edited 03-04-2025 11:56 PM
I had the same issue.
Some XR images do not support the command "show inventory", which would be executed in the ansible module cisco.iosxr.
You need to deal with this line in iosxr.py
data = self.get_command_output("show inventory")
My temporary solution is to write a try exception block to provide a default value to data:
try:
data = self.get_command_output("show inventory")
except:
data = 'NAME: "0/RP0", DESCR: "Cisco IOS-XRv 9000 Centralized Route Processor"\nPID: R-IOSXRV9000-RP-C , VID: V01, SN: 123456789AB\n\nNAME: "Rack 0", DESCR: "Cisco IOS-XRv 9000 Centralized Virtual Router"\nPID: R-IOSXRV9000-CC , VID: V01, SN: BA987654321'
Or you can try to use other command to get the hardware information as "show inventory" does.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide