Ansible:ios_config - 只有在配置行存在时才删除它

问题描述 投票:0回答:1

如果当前正在通过“no ip sla 46”运行,我需要删除路由器上的IP SLA配置,但是,如果路由器上当前不存在,则该剧本会失败。想法?

    - name: Add IP SLA test
      ios_config:
        lines:
          - udp-jitter 10.x.x.x source-ip {{ loopback }} codec g711ulaw
          - tos 184
          - tag Network Operation Center - G711ulaw EF VoIP
          - frequency 180
        parents: ip sla 46
        before: no ip sla 46
networking routing ansible yaml cisco
1个回答
0
投票

结束使用ios_command检查当前的IP SLA配置并删除(如果存在)。

- name: Find current SLA 46 config
      ios_command:
        commands: 'show run | inc sla 46'
      register: raw_sla_46

    - set_fact:
        sla_46: "{{ raw_sla_46.stdout[0] }}"

    - name: Delete IP SLA 46 if present
      ios_config:
        lines:
          - no ip sla 46
      when: sla_46 == 'ip sla 46'
      
    - name: Add IP SLA from Lo0 to DC
      ios_config:
        lines:
          - udp-jitter 10.20.0.25 17000 source-ip {{ loopback }} codec g711ulaw
          - tos 184
          - tag Network Operation Center - CHA - G711ulaw EF VoIP
          - frequency 180
        parents: ip sla 46
© www.soinside.com 2019 - 2024. All rights reserved.