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

使用Ansible在Juniper MX执行deactivate配置报语法错如何解决

错误原因

你遇到的语法报错是因为Juniper Ansible配置模块的load: merge模式默认仅支持标准set格式配置语句或结构化配置,而deactivate是Junos CLI配置模式下的操作类命令,不属于merge模式支持的语法范畴,因此解析失败。

解决方案

以下两种方案均可实现需求:

方案1(推荐):使用模块原生deactivate参数

直接调用junos_config模块内置的deactivate能力,不需要手动写命令行,兼容性最好,同时建议优先用netconf连接替代local连接(设备需提前开启set system services netconf ssh):

- name: 停用system scripts和event-options配置
  junipernetworks.junos.junos_config:
    deactivate:
      - system scripts
      - event-options
    comment: 'Ansible Upgrade - Deactivate'
    commit: true
  vars:
    ansible_connection: netconf
    ansible_network_os: junipernetworks.junos.junos
    ansible_user: <你的设备用户名>
    ansible_password: <你的设备密码>

方案2:修改load模式适配CLI命令

如果你需要沿用原有的命令写法,只需要把load参数的值从merge改为cli即可,该模式下模块会将lines内的内容识别为CLI配置模式下的原生命令,支持deactivate、delete等操作:

- name: 停用指定配置项
  junipernetworks.junos.junos_config:
    load: 'cli'
    lines:
      - deactivate system scripts
      - deactivate event-options
    comment: 'Ansible Upgrade - Deactivate'
    commit: true
  vars:
    ansible_connection: local
结果验证

任务执行成功后,登录设备执行show configuration | display inactive,可看到system scripts和event-options两段配置已被标记为inactive,符合预期效果。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.25 05:45:02