junipernetworks.junos.junos_static_routes 模块 – 静态路由资源模块
注意
此模块是 junipernetworks.junos 集合 (版本 9.1.0) 的一部分。
如果您正在使用 ansible
包,则可能已经安装了此集合。它不包含在 ansible-core
中。要检查它是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用:ansible-galaxy collection install junipernetworks.junos
。您需要其他要求才能使用此模块,有关详细信息,请参阅 要求。
要在剧本中使用它,请指定:junipernetworks.junos.junos_static_routes
。
junipernetworks.junos 1.0.0 中的新增功能
概要
此模块提供对 Juniper JUNOS 设备上静态路由的声明式管理。
要求
执行此模块的主机需要以下要求。
ncclient (>=v0.6.4)
xmltodict (>=0.12)
参数
参数 |
注释 |
---|---|
静态路由选项的字典 |
|
用于静态路由的地址族 |
|
用于静态路由的 AFI 选项
|
|
静态路由配置 |
|
静态路由目标,包括前缀 |
|
静态路由的度量值 |
|
到目的地的下一跳 |
|
下一跳列表 |
|
虚拟路由转发 (VRF) 名称 |
|
此选项仅与状态 *parsed* 一起使用。 此选项的值应为通过执行命令 **show routing-options** 从 Junos 设备接收到的输出。 状态 *parsed* 从 |
|
配置应保留到的状态 选项
|
注释
注意
此模块要求在被管理的设备上启用 netconf 系统服务。
此模块与连接
netconf
一起使用。请参阅 Junos OS 平台选项。针对 JunOS v18.4R1 进行了测试
示例
# Using deleted
# Before state
# ------------
#
# admin# show routing-options
# static {
# route 192.168.47.0/24 next-hop 172.16.1.2;
# route 192.168.16.0/24 next-hop 172.16.1.2;
# }
- name: Delete provided configuration (default operation is merge)
junipernetworks.junos.junos_static_routes:
config:
- address_families:
- afi: ipv4
routes:
- dest: 192.168.16.0/24
next_hop:
- forward_router_address: 172.16.1.2
state: deleted
# Task Output
# -----------
# before:
# - address_families:
# - afi: ipv4
# routes:
# - dest: 192.168.47.0/24
# next_hop:
# - forward_router_address: 172.16.1.2
# - dest: 192.168.16.0/24
# next_hop:
# - forward_router_address: 172.16.1.2
# commands:
# - '<nc:routing-options
# xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:static><nc:route
# delete="delete"><nc:name>192.168.16.0/24</nc:name></nc:route></nc:static></nc:routing-options>'
# - '<nc:routing-instances xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>'
# after:
# - address_families:
# - afi: ipv4
# routes:
# - dest: 192.168.47.0/24
# next_hop:
# - forward_router_address: 172.16.1.2
# After state:
# ------------
#
# admin# show routing-options
# static {
# route 192.168.47.0/24 next-hop 172.16.1.2;
# }
# Using merged
# Before state
# ------------
#
# admin# show routing-options
# static {
# route 192.168.47.0/24 next-hop 172.16.1.2;
# }
- name: Merge provided configuration with device configuration (default operation
is merge)
junipernetworks.junos.junos_static_routes:
config:
- address_families:
- afi: ipv4
routes:
- dest: 192.168.16.0/24
next_hop:
- forward_router_address: 172.16.1.2
state: merged
# Task Output
# -----------
# before:
# - address_families:
# - afi: ipv4
# routes:
# - dest: 192.168.47.0/24
# next_hop:
# - forward_router_address: 172.16.1.2
# commands:
# - '<nc:routing-options
# xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:static><nc:route><nc:name>192.168.16.0/24</nc:name>
# <nc:next-hop>172.16.1.2</nc:next-hop></nc:route></nc:static></nc:routing-options>'
# - '<nc:routing-instances xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>'
# after:
# - address_families:
# - afi: ipv4
# routes:
# - dest: 192.168.47.0/24
# next_hop:
# - forward_router_address: 172.16.1.2
# - dest: 192.168.16.0/24
# next_hop:
# - forward_router_address: 172.16.1.2
# After state:
# ------------
#
# admin# show routing-options
# static {
# route 192.168.47.0/24 next-hop 172.16.1.2;
# route 192.168.16.0/24 next-hop 172.16.1.2;
# }
# Using overridden
# Before state
# ------------
#
# admin# show routing-options
# static {
# route 192.168.47.0/24 next-hop 172.16.1.2;
# route 192.168.16.0/24 next-hop 172.16.1.2;
# }
- name: Override running configuration with provided configuration (default operation
is merge)
junipernetworks.junos.junos_static_routes:
config:
- address_families:
- afi: ipv4
routes:
- dest: 192.168.16.0/24
next_hop:
- forward_router_address: 172.16.0.1
state: overridden
# Task Output:
# ------------
# before:
# - address_families:
# - afi: ipv4
# routes:
# - dest: 192.168.47.0/24
# next_hop:
# - forward_router_address: 172.16.1.2
# - dest: 192.168.16.0/24
# next_hop:
# - forward_router_address: 172.16.1.2
# commands:
# - >-
# <nc:routing-options
# xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:static><nc:route
# delete="delete"><nc:name>192.168.47.0/24</nc:name></nc:route><nc:route
# delete="delete"><nc:name>192.168.16.0/24</nc:name></nc:route></nc:static><nc:static><nc:route><nc:name>192.168.16.0/24</nc:name><nc:next-hop>172.16.0.1</nc:next-hop></nc:route></nc:static></nc:routing-options>
# - '<nc:routing-instances xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>'
# after:
# - address_families:
# - afi: ipv4
# routes:
# - dest: 192.168.16.0/24
# next_hop:
# - forward_router_address: 172.16.0.1
# After state:
# ------------
#
# admin# show routing-options
# static {
# route 192.168.16.0/24 next-hop 172.16.0.1;
# }
# Using replaced
# Before state
# ------------
#
# admin# show routing-options
# static {
# route 192.168.47.0/24 next-hop 172.16.1.2;
# route 192.168.16.0/24 next-hop 172.16.1.2;
# }
- name: Replace provided configuration with device configuration (default operation
is merge)
junipernetworks.junos.junos_static_routes:
config:
- address_families:
- afi: ipv4
routes:
- dest: 192.168.47.0/24
next_hop:
- forward_router_address: 10.200.16.2
state: replaced
# Task Output:
# ------------
# before:
# - address_families:
# - afi: ipv4
# routes:
# - dest: 192.168.47.0/24
# next_hop:
# - forward_router_address: 172.16.1.2
# - dest: 192.168.16.0/24
# next_hop:
# - forward_router_address: 172.16.1.2
# commands:
# - >-
# <nc:routing-options
# xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:static><nc:route
# delete="delete"><nc:name>192.168.47.0/24</nc:name></nc:route></nc:static><nc:static><nc:route><nc:name>192.168.47.0/24</nc:name><nc:next-hop>10.200.16.2</nc:next-hop></nc:route></nc:static></nc:routing-options>
# - '<nc:routing-instances xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>'
# after:
# - address_families:
# - afi: ipv4
# routes:
# - dest: 192.168.16.0/24
# next_hop:
# - forward_router_address: 172.16.1.2
# - dest: 192.168.47.0/24
# next_hop:
# - forward_router_address: 10.200.16.2
# After state:
# ------------
#
# admin# show routing-options
# static {
# route 192.168.47.0/24 next-hop 10.200.16.2;
# route 192.168.16.0/24 next-hop 172.16.1.2;
# }
# Using gathered to gather static route facts from the device
# Before state
# ------------
# admin# show routing-options
# static {
# route 192.168.16.0/24 next-hop 172.16.1.2;
# route 192.168.47.0/24 next-hop 10.200.16.2;
# }
- name: Gather static routes facts from the device using junos_static_routes module
junipernetworks.junos.junos_static_routes:
state: gathered
# Task output:
# ------------
# gathered:
# - address_families:
# - afi: ipv4
# routes:
# - dest: 192.168.16.0/24
# next_hop:
# - forward_router_address: 172.16.1.2
# - dest: 192.168.47.0/24
# next_hop:
# - forward_router_address: 10.200.16.2
# Using rendered
- name: Render platform specific commands (without connecting to the device)
junipernetworks.junos.junos_static_routes:
config:
- address_families:
- afi: ipv4
routes:
- dest: 192.168.16.0/24
next_hop:
- forward_router_address: 172.16.1.2
state: rendered
# Task output:
# ------------
# rendered:
# - '<nc:routing-options
# xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:static><nc:route><nc:name>192.168.16.0/24</nc:name>
# <nc:next-hop>172.16.1.2</nc:next-hop></nc:route></nc:static></nc:routing-options>'
# 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>
# <routing-options>
# <static>
# <route>
# <name>192.168.16.0/24</name>
# <next-hop>172.16.1.2</next-hop>
# <next-hop>172.16.1.3</next-hop>
# </route>
# <route>
# <name>192.168.47.0/24</name>
# <next-hop>10.200.16.2</next-hop>
# </route>
# </static>
# </routing-options>
# </configuration>
# </rpc-reply>
- name: Parsed running config (without connecting to the device)
junipernetworks.junos.junos_static_routes:
running_config: "{{ lookup('file', 'parsed.cfg') }}"
state: parsed
# Task output:
# ------------
# parsed:
# - address_families:
# - afi: ipv4
# routes:
# - dest: 192.168.16.0/24
# next_hop:
# - forward_router_address: '[''172.16.1.2'', ''172.16.1.3'']'
# - dest: 192.168.47.0/24
# next_hop:
# - forward_router_address: 10.200.16.2
返回值
常见返回值已记录在 此处,以下是此模块独有的字段。
键 |
描述 |
---|---|
生成的配置模型调用。 返回:发生更改时 示例: |
|
模型调用之前的配置。 返回:始终返回 示例: |
|
推送到远程设备的命令集。 返回:始终返回 示例: |
|
从远程设备收集的关于网络资源的事实,作为结构化数据。 返回:当 *state* 为 示例: |
|
根据模块 argspec 将 *running_config* 选项中提供的设备原生配置解析为结构化数据。 返回:当 *state* 为 示例: |
|
以设备原生格式呈现的任务中提供的配置(离线)。 返回:当 *state* 为 示例: |