junipernetworks.junos.junos_ospfv2 模块 – OSPFv2 资源模块

注意

此模块是 junipernetworks.junos 集合(版本 9.1.0)的一部分。

如果您使用的是 ansible 包,您可能已经安装了此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install junipernetworks.junos。您需要进一步的要求才能使用此模块,请参阅要求 了解详细信息。

要在 playbook 中使用它,请指定:junipernetworks.junos.junos_ospfv2

junipernetworks.junos 1.0.0 中的新增功能

概要

  • 此模块管理运行 Juniper JUNOS 的设备上的 OSPFv2 配置。

要求

执行此模块的主机上需要以下要求。

  • ncclient (>=v0.6.4)

  • xmltodict (>=0.12.0)

参数

参数

注释

config

列表 / 元素=字典

OSPFv2 进程配置的列表。

areas

列表 / 元素=字典

OSPFv2 区域配置的列表。

area_id

字符串 / 必需

区域 ID,可以是整数或 IP 地址。

area_range

字符串

配置区域的地址范围。

包含此选项是为了兼容性,请在 2025-07-01 之后删除/弃用。

此选项的替代方案是 area_ranges,它是一个列表。

area_ranges

列表 / 元素=字典

配置区域的 IP 地址范围。

address

字符串

指定 IP 地址。

exact

布尔值

强制对此区域范围的通告进行精确匹配。

选项

  • false

  • true

override_metric

整数

覆盖此区域范围的动态指标。

restrict

布尔值

限制此区域范围的通告。

选项

  • false

  • true

interfaces

列表 / 元素=字典

此区域中的接口列表。

authentication

字典

指定身份验证类型

md5

列表 / 元素=字典

MD5 身份验证密钥

key

字符串

指定密钥值

key_id

整数

指定密钥标识

start_time

字符串

指定密钥传输的开始时间 (YYYY-MM-DD.HH:MM)

password

字符串

指定身份验证密钥。

type

字典

要使用的身份验证类型。

包含此选项是为了兼容性,请在 2025-07-01 之后删除/弃用。

bandwidth_based_metrics

列表 / 元素=字典

指定基于带宽的指标列表

bandwidth

字符串

应用指标的带宽。

选项

  • "1g"

  • "10g"

metric

整数

指定指标

flood_reduction

布尔值

启用洪泛减少。

选项

  • false

  • true

metric

整数

应用于接口的指标。

name

字符串 / 必需

接口的名称。

passive

布尔值

指定被动

选项

  • false

  • true

priority

整数

接口的优先级。

timers

字典

指定计时器

dead_interval

整数

死亡间隔(秒)。

hello_interval

整数

Hello 间隔(秒)。

poll_interval

整数

轮询间隔(秒)。

retransmit_interval

整数

重传间隔(秒)。

transit_delay

整数

传输延迟(秒)。

stub

字典

用于将区域配置为末梢区域的设置。

default_metric

整数

此区域中默认路由的指标。

set

布尔值

将区域配置为末梢区域。

选项

  • false

  • true

external_preference

整数

外部路由的优先级。

overload

字典

指定过载模式重置的时间

allow_route_leaking

布尔值

配置过载时允许路由泄漏。

选项

  • false

  • true

as_external

布尔值

使用最大可用指标通告为外部路由。

选项

  • false

  • true

stub_network

布尔值

使用最大指标通告末梢网络。

选项

  • false

  • true

timeout

整数

过载模式重置的时间(秒)。

preference

整数

内部路由的优先级。

prefix_export_limit

整数

可以导出的最大外部前缀数。

reference_bandwidth

字符串

用于计算指标默认值的带宽。

选项

  • "1g"

  • "10g"

rfc1583compatibility

布尔值

设置 RFC1583 兼容性

选项

  • false

  • true

router_id

字符串

OSPFv2 路由器 ID。

spf_options

字典

配置 SPF 的选项。

delay

整数

在运行 SPF 之前等待的时间(秒)。

holddown

整数

在运行 SPF 之前保持的时间(秒)。

no_ignore_our_externals

布尔值

不忽略自身生成的外部和 NSSA LSA。

选项

  • false

  • true

rapid_runs

整数

在保持之前最大快速 SPF 运行的次数(秒)。

running_config

字符串

此选项仅与状态 parsed 一起使用。

此选项的值应是通过执行命令 show protocols ospf 从 Junos 设备收到的输出。

状态 parsedrunning_config 选项读取配置,并根据资源模块的 argspec 将其转换为 Ansible 结构化数据,然后该值将作为结果中的 parsed 键返回

state

字符串

配置应保留的状态。

选项

  • "merged" ←(默认)

  • "replaced"

  • "overridden"

  • "deleted"

  • "gathered"

  • "rendered"

  • "parsed"

注释

注意

  • 此模块需要在被管理的设备上启用 netconf 系统服务。

  • 此模块与连接 netconf 一起使用。

  • 请参阅Junos OS 平台选项

  • 已针对 JunOS v18.4R1 进行测试

示例

# Using merged
#
# Before state
# ------------
#
# admin# show protocols ospf

- name: Merge provided OSPFv2 configuration into running config.
  junipernetworks.junos.junos_ospfv2:
    config:
      - reference_bandwidth: 10g
        areas:
          - area_id: 0.0.0.100
            area_ranges:
              - address: 10.200.17.0/24
                exact: true
                restrict: true
                override_metric: 2000
              - address: 10.200.15.0/24
                exact: true
                restrict: true
                override_metric: 2000
                stub:
                  default_metric: 100
                  set: true
                interfaces:
                  - name: so-0/0/0.0
                    priority: 3
                    metric: 5
                    flood_reduction: false
                    passive: true
                    bandwidth_based_metrics:
                      - bandwidth: 1g
                        metric: 5
                      - bandwidth: 10g
                        metric: 40
                    timers:
                      dead_interval: 4
                      hello_interval: 2
                      poll_interval: 2
                      retransmit_interval: 2
        rfc1583compatibility: false
    state: merged

# Task Output:
# ------------
#
# before: []
#
# commands:
# - <nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
#   <nc:ospf><nc:reference-bandwidth>10g</nc:reference-bandwidth><nc:no-rfc-1583/>
#   <nc:area><nc:name>0.0.0.100</nc:name><nc:area-range><nc:name>10.200.17.0/24</nc:name><nc:exact/>
#   <nc:restrict/><nc:override-metric>2000</nc:override-metric></nc:area-range><nc:area-range>
#   <nc:name>10.200.15.0/24</nc:name><nc:exact/><nc:restrict/><nc:override-metric>2000</nc:override-metric>
#   </nc:area-range><nc:interface><nc:name>so-0/0/0.0</nc:name><nc:priority>3</nc:priority>
#   <nc:metric>5</nc:metric><nc:passive/><nc:bandwidth-based-metrics><nc:bandwidth><nc:name>1g</nc:name>
#   <nc:metric>5</nc:metric></nc:bandwidth><nc:bandwidth><nc:name>10g</nc:name><nc:metric>40</nc:metric>
#   </nc:bandwidth></nc:bandwidth-based-metrics><nc:dead-interval>4</nc:dead-interval>
#   <nc:hello-interval>2</nc:hello-interval><nc:poll-interval>2</nc:poll-interval>
#   <nc:retransmit-interval>2</nc:retransmit-interval></nc:interface><nc:stub>
#   <nc:default-metric>100</nc:default-metric></nc:stub></nc:area></nc:ospf></nc:protocols>
#
# after:
# - areas:
#   - area_id: 0.0.0.100
#     area_range: '[''10.200.17.0/24'', ''10.200.15.0/24'']'
#     area_ranges:
#     - address: 10.200.17.0/24
#       exact: true
#       override_metric: 2000
#       restrict: true
#     - address: 10.200.15.0/24
#       exact: true
#       override_metric: 2000
#       restrict: true
#     interfaces:
#     - bandwidth_based_metrics:
#       - bandwidth: 1g
#         metric: 5
#       - bandwidth: 10g
#         metric: 40
#       metric: 5
#       name: so-0/0/0.0
#       passive: true
#       priority: 3
#       timers:
#         dead_interval: 4
#         hello_interval: 2
#         poll_interval: 2
#         retransmit_interval: 2
#     stub:
#       default_metric: 100
#       set: true
#   reference_bandwidth: 10g
#   rfc1583compatibility: false

# After state
# -----------
#
# admin# show protocols ospf
# reference-bandwidth 10g;
# no-rfc-1583;
# area 0.0.0.100 {
#     stub default-metric 100;
#     area-range 10.200.17.0/24 {
#         restrict;
#         exact;
#         override-metric 2000;
#     }
#     area-range 10.200.15.0/24 {
#         restrict;
#         exact;
#         override-metric 2000;
#     }
#     interface so-0/0/0.0 {
#         passive;
#         bandwidth-based-metrics {
#             bandwidth 1g metric 5;
#             bandwidth 10g metric 40;
#         }
#         metric 5;
#         priority 3;
#         retransmit-interval 2;
#         hello-interval 2;
#         dead-interval 4;
#         poll-interval 2;
#     }
# }
#
# Using replaced
#
# Before state
# ------------
#
# admin# show protocols ospf
# reference-bandwidth 10g;
# no-rfc-1583;
# area 0.0.0.100 {
#     stub default-metric 100;
#     area-range 10.200.17.0/24 {
#         restrict;
#         exact;
#         override-metric 2000;
#     }
#     area-range 10.200.15.0/24 {
#         restrict;
#         exact;
#         override-metric 2000;
#     }
#     interface so-0/0/0.0 {
#         passive;
#         bandwidth-based-metrics {
#             bandwidth 1g metric 5;
#             bandwidth 10g metric 40;
#         }
#         metric 5;
#         priority 3;
#         retransmit-interval 2;
#         hello-interval 2;
#         dead-interval 4;
#         poll-interval 2;
#     }
# }

- name: Replace existing Junos OSPFv2 config with provided config
  junipernetworks.junos.junos_ospfv2:
    config:
      - reference_bandwidth: 10g
        areas:
          - area_id: 0.0.0.100
            area_ranges:
              - address: 10.200.17.0/24
                exact: true
                restrict: true
              - address: 10.200.16.0/24
                exact: true
                restrict: true
                override_metric: 1000
            stub:
              default_metric: 100
              set: true
            interfaces:
              - name: so-0/0/0.0
                priority: 3
                metric: 5
                flood_reduction: false
                passive: true
                bandwidth_based_metrics:
                  - bandwidth: 1g
                    metric: 5
                  - bandwidth: 10g
                    metric: 40
                timers:
                  dead_interval: 4
                  hello_interval: 2
                  poll_interval: 2
                  retransmit_interval: 2
        rfc1583compatibility: false
    state: replacedd

# Task Output:
# ------------
#
# before:
#   - areas:
#     - area_id: 0.0.0.100
#       area_range: '[''10.200.17.0/24'', ''10.200.15.0/24'']'
#       area_ranges:
#       - address: 10.200.17.0/24
#         exact: true
#         override_metric: 2000
#         restrict: true
#       - address: 10.200.15.0/24
#         exact: true
#         override_metric: 2000
#         restrict: true
#       interfaces:
#       - bandwidth_based_metrics:
#         - bandwidth: 1g
#           metric: 5
#         - bandwidth: 10g
#           metric: 40
#         metric: 5
#         name: so-0/0/0.0
#         passive: true
#         priority: 3
#         timers:
#           dead_interval: 4
#           hello_interval: 2
#           poll_interval: 2
#           retransmit_interval: 2
#       stub:
#         default_metric: 100
#         set: true
#     reference_bandwidth: 10g
#     rfc1583compatibility: false
#
# commands:
# - <nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
#   <nc:ospf><nc:area delete="delete">0.0.0.100</nc:area></nc:ospf><nc:ospf>
#   <nc:reference-bandwidth>10g</nc:reference-bandwidth><nc:no-rfc-1583/><nc:area>
#   <nc:name>0.0.0.100</nc:name><nc:area-range><nc:name>10.200.17.0/24</nc:name><nc:exact/>
#   <nc:restrict/></nc:area-range><nc:area-range><nc:name>10.200.16.0/24</nc:name><nc:exact/>
#   <nc:restrict/><nc:override-metric>1000</nc:override-metric></nc:area-range><nc:interface>
#   <nc:name>so-0/0/0.0</nc:name><nc:priority>3</nc:priority><nc:metric>5</nc:metric><nc:passive/>
#   <nc:bandwidth-based-metrics><nc:bandwidth><nc:name>1g</nc:name><nc:metric>5</nc:metric>
#   </nc:bandwidth><nc:bandwidth><nc:name>10g</nc:name><nc:metric>40</nc:metric></nc:bandwidth>
#   </nc:bandwidth-based-metrics><nc:dead-interval>4</nc:dead-interval><nc:hello-interval>2</nc:hello-interval>
#   <nc:poll-interval>2</nc:poll-interval><nc:retransmit-interval>2</nc:retransmit-interval></nc:interface>
#   <nc:stub><nc:default-metric>100</nc:default-metric></nc:stub></nc:area></nc:ospf></nc:protocols>
#
# after:
#   - areas:
#     - area_id: 0.0.0.100
#       area_range: '[''10.200.17.0/24'', ''10.200.16.0/24'']'
#       area_ranges:
#       - address: 10.200.17.0/24
#         exact: true
#         restrict: true
#       - address: 10.200.16.0/24
#         exact: true
#         override_metric: 1000
#         restrict: true
#       interfaces:
#       - bandwidth_based_metrics:
#         - bandwidth: 1g
#           metric: 5
#         - bandwidth: 10g
#           metric: 40
#         metric: 5
#         name: so-0/0/0.0
#         passive: true
#         priority: 3
#         timers:
#           dead_interval: 4
#           hello_interval: 2
#           poll_interval: 2
#           retransmit_interval: 2
#       stub:
#         default_metric: 100
#         set: true
#     reference_bandwidth: 10g
#     rfc1583compatibility: false
#
# After state
# -----------
#
# admin# show protocols ospf
# reference-bandwidth 10g;
# no-rfc-1583;
# area 0.0.0.100 {
#     stub default-metric 100;
#     area-range 10.200.17.0/24 {
#         restrict;
#         exact;
#     }
#     area-range 10.200.16.0/24 {
#         restrict;
#         exact;
#         override-metric 1000;
#     }
#     interface so-0/0/0.0 {
#         passive;
#         bandwidth-based-metrics {
#             bandwidth 1g metric 5;
#             bandwidth 10g metric 40;
#         }
#         metric 5;
#         priority 3;
#         retransmit-interval 2;
#         hello-interval 2;
#         dead-interval 4;
#         poll-interval 2;
#     }
# }
#
# Using overridden
#
# Before state
# ------------
#
# admin# show protocols ospf
# reference-bandwidth 10g;
# no-rfc-1583;
# area 0.0.0.100 {
#     stub default-metric 100;
#     area-range 10.200.17.0/24 {
#         restrict;
#         exact;
#     }
#     area-range 10.200.16.0/24 {
#         restrict;
#         exact;
#         override-metric 1000;
#     }
#     interface so-0/0/0.0 {
#         passive;
#         bandwidth-based-metrics {
#             bandwidth 1g metric 5;
#             bandwidth 10g metric 40;
#         }
#         metric 5;
#         priority 3;
#         retransmit-interval 2;
#         hello-interval 2;
#         dead-interval 4;
#         poll-interval 2;
#     }
# }

- name: Override runnig OSPFv2 config with provided config
  junipernetworks.junos.junos_ospfv2:
    config:
      - reference_bandwidth: 10g
        areas:
          - area_id: 0.0.0.110
            area_ranges:
              - address: 20.200.17.0/24
                exact: true
                restrict: true
                override_metric: 2000
              - address: 20.200.15.0/24
                exact: true
                restrict: true
                override_metric: 2000
            stub:
              default_metric: 200
              set: true
            interfaces:
              - name: so-0/0/0.0
                priority: 3
                metric: 5
                flood_reduction: false
                passive: true
                bandwidth_based_metrics:
                  - bandwidth: 1g
                    metric: 5
                  - bandwidth: 10g
                    metric: 40
    state: overridden

# Task Output:
# ------------
#
# before:
# - areas:
#   - area_id: 0.0.0.100
#     area_range: '[''10.200.17.0/24'', ''10.200.16.0/24'']'
#     area_ranges:
#     - address: 10.200.17.0/24
#       exact: true
#       restrict: true
#     - address: 10.200.16.0/24
#       exact: true
#       override_metric: 1000
#       restrict: true
#     interfaces:
#     - bandwidth_based_metrics:
#       - bandwidth: 1g
#         metric: 5
#       - bandwidth: 10g
#         metric: 40
#       metric: 5
#       name: so-0/0/0.0
#       passive: true
#       priority: 3
#       timers:
#         dead_interval: 4
#         hello_interval: 2
#         poll_interval: 2
#         retransmit_interval: 2
#     stub:
#       default_metric: 100
#       set: true
#   reference_bandwidth: 10g
#   rfc1583compatibility: false
#
# commands:
# - <nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
#   <nc:ospf><nc:area delete="delete">0.0.0.100</nc:area></nc:ospf><nc:ospf>
#   <nc:reference-bandwidth>10g</nc:reference-bandwidth><nc:area><nc:name>0.0.0.110</nc:name>
#   <nc:area-range><nc:name>20.200.17.0/24</nc:name><nc:exact/><nc:restrict/>
#   <nc:override-metric>2000</nc:override-metric></nc:area-range><nc:area-range>
#   <nc:name>20.200.15.0/24</nc:name><nc:exact/><nc:restrict/><nc:override-metric>2000</nc:override-metric>
#   </nc:area-range><nc:interface><nc:name>so-0/0/0.0</nc:name><nc:priority>3</nc:priority>
#   <nc:metric>5</nc:metric><nc:passive/><nc:bandwidth-based-metrics><nc:bandwidth><nc:name>1g</nc:name>
#   <nc:metric>5</nc:metric></nc:bandwidth><nc:bandwidth><nc:name>10g</nc:name><nc:metric>40</nc:metric>
#   </nc:bandwidth></nc:bandwidth-based-metrics></nc:interface><nc:stub>
#   <nc:default-metric>200</nc:default-metric></nc:stub></nc:area></nc:ospf></nc:protocols>
#
# after:
#   - areas:
#     - area_id: 0.0.0.110
#       area_range: '[''20.200.17.0/24'', ''20.200.15.0/24'']'
#       area_ranges:
#       - address: 20.200.17.0/24
#         exact: true
#         override_metric: 2000
#         restrict: true
#       - address: 20.200.15.0/24
#         exact: true
#         override_metric: 2000
#         restrict: true
#       interfaces:
#       - bandwidth_based_metrics:
#         - bandwidth: 1g
#           metric: 5
#         - bandwidth: 10g
#           metric: 40
#         metric: 5
#         name: so-0/0/0.0
#         passive: true
#         priority: 3
#       stub:
#         default_metric: 200
#         set: true
#     reference_bandwidth: 10g
#     rfc1583compatibility: false

# After state
# -----------
#
# admin# show protocols ospf
# reference-bandwidth 10g;
# no-rfc-1583;
# area 0.0.0.110 {
#     stub default-metric 200;
#     area-range 20.200.17.0/24 {
#         restrict;
#         exact;
#         override-metric 2000;
#     }
#     area-range 20.200.15.0/24 {
#         restrict;
#         exact;
#         override-metric 2000;
#     }
#     interface so-0/0/0.0 {
#         passive;
#         bandwidth-based-metrics {
#             bandwidth 1g metric 5;
#             bandwidth 10g metric 40;
#         }
#         metric 5;
#         priority 3;
#     }
# }
# Using deleted
#
# Before state
# ------------
#
# admin# show protocols ospf
# reference-bandwidth 10g;
# no-rfc-1583;
# area 0.0.0.110 {
#     stub default-metric 200;
#     area-range 20.200.17.0/24 {
#         restrict;
#         exact;
#         override-metric 2000;
#     }
#     area-range 20.200.15.0/24 {
#         restrict;
#         exact;
#         override-metric 2000;
#     }
#     interface so-0/0/0.0 {
#         passive;
#         bandwidth-based-metrics {
#             bandwidth 1g metric 5;
#             bandwidth 10g metric 40;
#         }
#         metric 5;
#         priority 3;
#     }
# }

- name: Delete OSPFv2 running config.
  junipernetworks.junos.junos_ospfv2:
    config:
    state: deleted

# Task Output:
# ------------
#
# before:
#   - areas:
#     - area_id: 0.0.0.110
#       area_range: '[''20.200.17.0/24'', ''20.200.15.0/24'']'
#       area_ranges:
#       - address: 20.200.17.0/24
#         exact: true
#         override_metric: 2000
#         restrict: true
#       - address: 20.200.15.0/24
#         exact: true
#         override_metric: 2000
#         restrict: true
#       interfaces:
#       - bandwidth_based_metrics:
#         - bandwidth: 1g
#           metric: 5
#         - bandwidth: 10g
#           metric: 40
#         metric: 5
#         name: so-0/0/0.0
#         passive: true
#         priority: 3
#       stub:
#         default_metric: 200
#         set: true
#     reference_bandwidth: 10g
#     rfc1583compatibility: false
#
# commands:
# - <nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
#   <nc:ospf><nc:area delete="delete">0.0.0.100</nc:area><nc:reference-bandwidth delete="delete"/>
#   <nc:no-rfc-1583 delete="delete"/></nc:ospf></nc:protocols>
#
# after: []
#
#
# After state
# -----------
#
# admin# show protocols ospf

# Using gathered
#
# Before state
# ------------
#
# admin# show protocols ospf
# reference-bandwidth 10g;
# no-rfc-1583;
# area 0.0.0.100 {
#     stub default-metric 100;
#     area-range 10.200.17.0/24 {
#         restrict;
#         exact;
#         override-metric 2000;
#     }
#     area-range 10.200.15.0/24 {
#         restrict;
#         exact;
#         override-metric 2000;
#     }
#     interface so-0/0/0.0 {
#         passive;
#         bandwidth-based-metrics {
#             bandwidth 1g metric 5;
#             bandwidth 10g metric 40;
#         }
#         metric 5;
#         priority 3;
#         retransmit-interval 2;
#         hello-interval 2;
#         dead-interval 4;
#         poll-interval 2;
#     }
# }

- name: Gather Junos OSPFv2 running-configuration
  junipernetworks.junos.junos_ospfv2:
    config:
    state: gathered
#
#
# Task Output:
# ------------
#
# gathered:
#
#  - areas:
# - area_id: 0.0.0.100
#   area_range: '[''10.200.17.0/24'', ''10.200.15.0/24'']'
#   area_ranges:
#   - address: 10.200.17.0/24
#     exact: true
#     override_metric: 2000
#     restrict: true
#   - address: 10.200.15.0/24
#     exact: true
#     override_metric: 2000
#     restrict: true
#   interfaces:
#   - bandwidth_based_metrics:
#     - bandwidth: 1g
#       metric: 5
#     - bandwidth: 10g
#       metric: 40
#     metric: 5
#     name: so-0/0/0.0
#     passive: true
#     priority: 3
#     timers:
#       dead_interval: 4
#       hello_interval: 2
#       poll_interval: 2
#       retransmit_interval: 2
#   stub:
#     default_metric: 100
#     set: true
# reference_bandwidth: 10g
# rfc1583compatibility: false

# Using parsed
# parsed.cfg
# ------------
# <?xml version="1.0" encoding="UTF-8"?>
# <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f">
#     <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC">
#         <version>18.4R1-S2.4</version>
#         <protocols>
#             <ospf>
#             <reference-bandwidth>10g</reference-bandwidth>
#             <no-rfc-1583/>
#             <area>
#                 <name>0.0.0.100</name>
#                 <stub>
#                     <default-metric>100</default-metric>
#                 </stub>
#                 <area-range>
#                     <name>10.200.16.0/24</name>
#                     <exact/>
#                     <override-metric>10000</override-metric>
#                 </area-range>
#                 <area-range>
#                     <name>10.200.11.0/24</name>
#                     <restrict/>
#                     <exact/>
#                 </area-range>
#                 <interface>
#                     <name>so-0/0/0.0</name>
#                     <passive>
#                     </passive>
#                     <bandwidth-based-metrics>
#                         <bandwidth>
#                             <name>1g</name>
#                             <metric>5</metric>
#                         </bandwidth>
#                         <bandwidth>
#                             <name>10g</name>
#                             <metric>40</metric>
#                         </bandwidth>
#                     </bandwidth-based-metrics>
#                     <metric>5</metric>
#                     <priority>3</priority>
#                     <retransmit-interval>2</retransmit-interval>
#                     <hello-interval>2</hello-interval>
#                     <dead-interval>4</dead-interval>
#                     <poll-interval>2</poll-interval>
#                 </interface>
#             </area>
#         </ospf>
#         </protocols>
#         <routing-options>
#             <static>
#                 <route>
#                     <name>172.16.17.0/24</name>
#                     <discard />
#                 </route>
#             </static>
#             <router-id>10.200.16.75</router-id>
#             <autonomous-system>
#                 <as-number>65432</as-number>
#             </autonomous-system>
#         </routing-options>
#     </configuration>
# </rpc-reply>


- name: Parsed the ospfv2 config into structured ansible resource facts.
  junipernetworks.junos.junos_ospfv2:
    running_config: "{{ lookup('file', './parsed.cfg') }}"
    state: parsed
#
# Task Output:
# ------------
#
# parsed:
# - areas:
#     - area_id: 0.0.0.100
#       area_range: '[''10.200.16.0/24'', ''10.200.11.0/24'']'
#       area_ranges:
#       - address: 10.200.16.0/24
#         exact: true
#         override_metric: 10000
#       - address: 10.200.11.0/24
#         exact: true
#         restrict: true
#       interfaces:
#       - bandwidth_based_metrics:
#         - bandwidth: 1g
#           metric: 5
#         - bandwidth: 10g
#           metric: 40
#         metric: 5
#         name: so-0/0/0.0
#         passive: true
#         priority: 3
#         timers:
#           dead_interval: 4
#           hello_interval: 2
#           poll_interval: 2
#           retransmit_interval: 2
#       stub:
#         default_metric: 100
#         set: true
#     reference_bandwidth: 10g
#     rfc1583compatibility: false
#     router_id: 10.200.16.75

# Using rendered
#
- name: Render the commands for provided  configuration
  junipernetworks.junos.junos_ospfv2:
    config:
      - reference_bandwidth: 10g
        areas:
          - area_id: 0.0.0.100
            area_ranges:
              - address: 10.200.17.0/24
                exact: true
                restrict: true
                override_metric: 2000
              - address: 10.200.15.0/24
                exact: true
                restrict: true
                override_metric: 2000
            stub:
              default_metric: 100
              set: true
            interfaces:
              - name: so-0/0/0.0
                priority: 3
                metric: 5
                flood_reduction: false
                passive: true
                bandwidth_based_metrics:
                  - bandwidth: 1g
                    metric: 5
                  - bandwidth: 10g
                    metric: 40
                timers:
                  dead_interval: 4
                  hello_interval: 2
                  poll_interval: 2
                  retransmit_interval: 2
        rfc1583compatibility: false
    state: rendered

# Task Output:
# ------------
#
# rendered: "<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
# <nc:ospf><nc:reference-bandwidth>10g</nc:reference-bandwidth><nc:no-rfc-1583/><nc:area><nc:name>0.0.0.100</nc:name>
# <nc:area-range><nc:name>10.200.17.0/24</nc:name><nc:exact/><nc:restrict/><nc:override-metric>2000</nc:override-metric>
# </nc:area-range><nc:area-range><nc:name>10.200.15.0/24</nc:name><nc:exact/><nc:restrict/>
# <nc:override-metric>2000</nc:override-metric></nc:area-range><nc:interface><nc:name>so-0/0/0.0</nc:name>
# <nc:priority>3</nc:priority><nc:metric>5</nc:metric><nc:passive/><nc:bandwidth-based-metrics><nc:bandwidth>
# <nc:name>1g</nc:name><nc:metric>5</nc:metric></nc:bandwidth><nc:bandwidth><nc:name>10g</nc:name>
# <nc:metric>40</nc:metric></nc:bandwidth></nc:bandwidth-based-metrics><nc:dead-interval>4</nc:dead-interval>
# <nc:hello-interval>2</nc:hello-interval><nc:poll-interval>2</nc:poll-interval>
# <nc:retransmit-interval>2</nc:retransmit-interval></nc:interface><nc:stub>
# <nc:default-metric>100</nc:default-metric></nc:stub></nc:area></nc:ospf></nc:protocols>"

返回值

通用返回值记录在此处,以下是此模块特有的字段

描述

after

字典

模块调用后的结果配置。

返回: 当更改时

示例: "返回的配置始终与上述参数的格式相同。\n"

before

字典

模块调用之前的配置。

返回: 始终

示例: "返回的配置始终与上述参数的格式相同。\n"

commands

列表 / 元素=字符串

推送到远程设备的命令集。

返回: 始终

示例: ["<nc:protocols xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">< nc:ospf><nc:area delete=\"delete\">0.0.0.100</nc:area><nc:reference-bandwidth delete=\"delete\"/> <nc:no-rfc-1583 delete=\"delete\"/></nc:ospf></nc:protocols>", "xml 2", "xml 3"]

gathered

列表 / 元素=字符串

从远程设备收集的关于网络资源的结构化数据的事实。

返回:stategathered

示例: ["此输出将始终与模块参数规范的格式相同。\n"]

parsed

列表 / 元素=字符串

根据模块参数规范,将running_config选项中提供的设备原生配置解析为结构化数据。

返回:stateparsed

示例: ["此输出将始终与模块参数规范的格式相同。\n"]

rendered

列表 / 元素=字符串

任务中提供的配置以设备原生格式(离线)呈现。

返回:staterendered

示例: ["<nc:protocols xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"]

作者

  • Daniel Mellado (@dmellado)

  • Rohit Thakur (@rohitthakur2590)