You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ansible Cisco.Iosxr集合在虚拟Cisco IOS XR路由器上运行异常求助

适配Cisco XRd的Ansible配置方案

问题背景

使用cisco.iosxr.iosxr_config模块备份XRd(容器化IOS XR控制平面,版本7.8.1)时,模块会执行XRd不支持的show inventory命令导致报错;使用cisco.ios集合虽能完成备份,但配置VRF时因命令语法差异出现错误;当前采用ansible.netcommon.netconf_config模块操作繁琐,寻求更合适的Ansible集合或方案。

可行解决方案

1. 升级/调整cisco.iosxr集合的使用

XRd作为虚拟控制平面无硬件inventory,部分旧版本cisco.iosxr集合未兼容此场景:

  • 升级集合:更新到最新版cisco.iosxr集合,官方后续版本已修复XRd下跳过show inventory的逻辑:
    ansible-galaxy collection install cisco.iosxr --upgrade
    
  • 手动备份规避内置检查:若升级后仍有问题,可直接用iosxr_command模块手动备份,跳过iosxr_config的备份逻辑:
    - name: Manual config backup with cisco.iosxr
      hosts: CERouters
      gather_facts: false
      tasks:
        - name: Fetch running config
          cisco.iosxr.iosxr_command:
            commands: show running-config
          register: running_config
    
        - name: Save to local file
          copy:
            content: "{{ running_config.stdout[0] }}"
            dest: "./backups/{{ inventory_hostname }}_backup.txt"
    

2. 使用ansible.netcommon通用网络模块(推荐)

ansible.netcommon提供的通用CLI模块无需依赖厂商特定集合,完全适配XRd命令集,操作灵活:

  • 配置备份示例:
    - name: Backup XRd running config
      hosts: CERouters
      gather_facts: false
      tasks:
        - name: Capture running config
          ansible.netcommon.cli_command:
            command: show running-config
          register: config_output
    
        - name: Save backup file
          copy:
            content: "{{ config_output.stdout }}"
            dest: "./backups/{{ inventory_hostname }}_{{ ansible_date_time.date }}.cfg"
    
  • VRF配置示例(结合Jinja2模板):
    编写Jinja2模板vrf_template.j2:
    vrf definition {{ vrf_name }}
     address-family ipv4
      route-target import {{ rt_import }}
      route-target export {{ rt_export }}
     exit-address-family
    
    Playbook中调用模板配置:
    - name: Configure VRF on XRd
      hosts: CERouters
      gather_facts: false
      vars:
        vrf_name: "PROD_VRF"
        rt_import: "100:1"
        rt_export: "100:1"
      tasks:
        - name: Apply VRF config
          ansible.netcommon.cli_config:
            config: "{{ lookup('template', 'vrf_template.j2') }}"
    

3. 关于cisco.ios集合的VRF配置问题(不推荐)

cisco.ios集合针对IOS设备设计,与XR命令语法差异明显(如XR的VRF需在address-family下配置路由目标),若坚持使用需完全适配XR语法修改模板,但后续维护成本高,不建议采用。

总结

  • 优先选择ansible.netcommon的通用CLI模块,兼顾备份与配置需求,适配XRd场景且操作简洁;
  • 若偏好厂商集合,升级cisco.iosxr到最新版本可解决show inventory报错问题。

内容的提问来源于stack exchange,提问作者r3volutionxxx

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 10:02:08