junipernetworks.junos.junos_interfaces 模块 – Junos 接口资源模块
注意
此模块是 junipernetworks.junos 集合 (版本 9.1.0) 的一部分。
如果您使用的是 ansible
软件包,则可能已安装此集合。它不包含在 ansible-core
中。要检查它是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用:ansible-galaxy collection install junipernetworks.junos
。您需要其他要求才能使用此模块,请参阅 要求 获取详细信息。
要在剧本中使用它,请指定:junipernetworks.junos.junos_interfaces
。
junipernetworks.junos 1.0.0 中的新增功能
概要
此模块管理 Juniper Junos OS 网络设备上的接口。
要求
执行此模块的主机需要以下要求。
ncclient (>=v0.6.4)
参数
参数 |
注释 |
---|---|
提供的配置 |
|
接口描述。 |
|
接口链路状态。仅适用于以太网接口,可以是半双工、全双工或自动状态(自动协商双工)。 选项
|
|
接口的管理状态。 将值设置为 选项
|
|
给定接口名称的保持时间。 |
|
链路断开保持时间(毫秒)。 |
|
链路连接保持时间(毫秒)。 |
|
特定接口的 MTU。 仅适用于以太网接口。 |
|
接口的全名,例如 ge-0/0/0。 |
|
接口链路速度。仅适用于以太网接口。 |
|
指定逻辑接口单元。 |
|
指定逻辑接口描述。 |
|
指定接口单元号。 |
|
此选项仅与 state *parsed* 一起使用。 此选项的值应是从 Junos 设备通过执行命令 **show interfaces** 收到的输出。 state *parsed* 从 |
|
模块完成后的配置状态 选项
|
注释
注意
此模块要求在被管理的远程设备上启用 netconf 系统服务。
在 vSRX JUNOS 版本 18.4R1 上进行了测试。
此模块适用于连接
netconf
。请参阅 https://docs.ansible.org.cn/ansible/latest/network/user_guide/platform_junos.html模块示例使用回调插件 (stdout_callback = yaml) 以 yaml 格式生成任务输出。
示例
# Using merged
# Before state:
# -------------
#
# user@junos01# show interfaces
# ge-0/0/1 {
# description "test interface";
# speed 1g;
# }
# fe-0/0/2 {
# vlan-tagging;
# unit 10 {
# vlan-id 10;
# }
# unit 11 {
# vlan-id 11;
# }
# }
# ge-0/0/3 {
# description "Configured by Ansible-3";
# }
# fxp0 {
# unit 0 {
# family inet {
# dhcp;
# }
# }
# }
# lo0 {
# unit 0 {
# family inet {
# address 192.0.2.1/32;
# }
# }
# }
- name: Merge provided configuration with device configuration (default operation
is merge)
junipernetworks.junos.junos_interfaces:
config:
- name: ge-0/0/1
description: Configured by Ansible-1
enabled: true
units:
- name: 0
description: "This is logical intf unit0"
mtu: 1800
- name: ge-0/0/2
description: Configured by Ansible-2
enabled: false
state: merged
# Task Output
# -----------
#
# before:
# - description: test interface
# enabled: true
# name: ge-0/0/1
# speed: 1g
# - enabled: true
# name: fe-0/0/2
# - description: Configured by Ansible-3
# enabled: true
# name: ge-0/0/3
# - enabled: true
# name: fxp0
# - enabled: true
# name: lo0
# commands:
# - <nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:interface><nc:name>ge-0/0/1</nc:name>
# <nc:description>Configured by Ansible-1</nc:description><nc:mtu>1800</nc:mtu><nc:unit><nc:name>0</nc:name>
# <nc:description>This is logical intf unit0</nc:description></nc:unit></nc:interface><nc:interface><nc:name>ge-0/0/2</nc:name>
# <nc:description>Configured by Ansible-2</nc:description><nc:disable/></nc:interface></nc:interfaces>
# after:
# - description: Configured by Ansible-1
# enabled: true
# mtu: 1800
# name: ge-0/0/1
# speed: 1g
# units:
# - description: This is logical intf unit0
# name: 0
# - enabled: true
# name: fe-0/0/2
# - description: Configured by Ansible-2
# enabled: false
# name: ge-0/0/2
# - description: Configured by Ansible-3
# enabled: true
# name: ge-0/0/3
# - enabled: true
# name: fxp0
# - enabled: true
# name: lo0
# After state:
# ------------
#
# user@junos01# show interfaces
# ge-0/0/1 {
# description "Configured by Ansible-1";
# speed 1g;
# mtu 1800;
# unit 0 {
# description "This is logical intf unit0";
# }
# }
# fe-0/0/2 {
# vlan-tagging;
# unit 10 {
# vlan-id 10;
# }
# unit 11 {
# vlan-id 11;
# }
# }
# ge-0/0/2 {
# description "Configured by Ansible-2";
# disable;
# }
# ge-0/0/3 {
# description "Configured by Ansible-3";
# }
# fxp0 {
# unit 0 {
# family inet {
# dhcp;
# }
# }
# }
# lo0 {
# unit 0 {
# family inet {
# address 192.0.2.1/32;
# }
# }
# }
# Using deleted
# Before state:
# -------------
#
# ge-0/0/1 {
# description "Configured by Ansible-1";
# speed 1g;
# mtu 1800;
# unit 0 {
# description "This is logical intf unit0";
# }
# }
# fe-0/0/2 {
# vlan-tagging;
# unit 10 {
# vlan-id 10;
# }
# unit 11 {
# vlan-id 11;
# }
# }
# ge-0/0/2 {
# description "Configured by Ansible-2";
# disable;
# }
# ge-0/0/3 {
# description "Configured by Ansible-3";
# }
# fxp0 {
# unit 0 {
# family inet {
# dhcp;
# }
# }
# }
# lo0 {
# unit 0 {
# family inet {
# address 192.0.2.1/32;
# }
# }
# }
- name: "Delete given options for the interface (Note: This won't delete the interface itself if any other values are configured for interface)"
junipernetworks.junos.junos_interfaces:
config:
- name: ge-0/0/1
description: Configured by Ansible-1
speed: 1g
mtu: 1800
- name: ge-0/0/2
description: Configured by Ansible -2
state: deleted
# Task Output
# -----------
#
# before:
# - description: Configured by Ansible-1
# enabled: true
# mtu: 1800
# name: ge-0/0/1
# speed: 1g
# units:
# - description: This is logical intf unit0
# name: 0
# - enabled: true
# name: fe-0/0/2
# - description: Configured by Ansible-2
# enabled: false
# name: ge-0/0/2
# - description: Configured by Ansible-3
# enabled: true
# name: ge-0/0/3
# - enabled: true
# name: fxp0
# - enabled: true
# name: lo0
# commands:
# - <nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:interface>
# <nc:name>ge-0/0/1</nc:name><nc:description delete="delete"/>
# <nc:speed delete="delete"/><nc:mtu delete="delete"/><nc:link-mode delete="delete"/>
# <nc:disable delete="delete"/><nc:hold-time><nc:up delete="delete"/><nc:down delete="delete"/></nc:hold-time><nc:unit>
# <nc:name>0</nc:name><nc:description delete="delete"/></nc:unit></nc:interface><nc:interface><nc:name>ge-0/0/2</nc:name>
# <nc:description delete="delete"/><nc:speed delete="delete"/><nc:mtu delete="delete"/><nc:link-mode delete="delete"/>
# <nc:disable delete="delete"/><nc:hold-time><nc:up delete="delete"/><nc:down delete="delete"/></nc:hold-time></nc:interface>
# </nc:interfaces>
# after:
# - enabled: true
# name: ge-0/0/1
# - enabled: true
# name: fe-0/0/2
# - description: Configured by Ansible-3
# enabled: true
# name: ge-0/0/3
# - enabled: true
# name: fxp0
# - enabled: true
# name: lo0
# After state:
# ------------
#
# user@junos01# show interfaces
# ge-0/0/1 {
# unit 0;
# }
# fe-0/0/2 {
# vlan-tagging;
# unit 10 {
# vlan-id 10;
# }
# unit 11 {
# vlan-id 11;
# }
# }
# ge-0/0/3 {
# description "Configured by Ansible-3";
# }
# fxp0 {
# unit 0 {
# family inet {
# dhcp;
# }
# }
# }
# lo0 {
# unit 0 {
# family inet {
# address 192.0.2.1/32;
# }
# }
# }
# Using overridden
# Before state:
# -------------
#
# user@junos01# show interfaces
# ge-0/0/1 {
# unit 0;
# }
# fe-0/0/2 {
# vlan-tagging;
# unit 10 {
# vlan-id 10;
# }
# unit 11 {
# vlan-id 11;
# }
# }
# ge-0/0/3 {
# description "Configured by Ansible-3";
# }
# fxp0 {
# unit 0 {
# family inet {
# dhcp;
# }
# }
# }
# lo0 {
# unit 0 {
# family inet {
# address 192.0.2.1/32;
# }
# }
# }
- name: Override device configuration of all interfaces with provided configuration
junipernetworks.junos.junos_interfaces:
config:
- enabled: true
name: ge-0/0/1
- name: fe-0/0/2
description: Configured by Ansible-2
enabled: false
mtu: 2800
- description: Updated by Ansible-3
enabled: true
name: ge-0/0/3
- enabled: true
name: fxp0
- enabled: true
name: lo0
state: overridden
# Task Output
# -----------
#
# before:
# - enabled: true
# name: ge-0/0/1
# - enabled: true
# name: fe-0/0/2
# - description: Configured by Ansible-3
# enabled: true
# name: ge-0/0/3
# - enabled: true
# name: fxp0
# - enabled: true
# name: lo0
# commands:
# - <nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
# <nc:interface><nc:name>ge-0/0/1</nc:name><nc:description delete="delete"/>
# <nc:speed delete="delete"/><nc:mtu delete="delete"/><nc:link-mode delete="delete"/>
# <nc:disable delete="delete"/><nc:hold-time><nc:up delete="delete"/><nc:down delete="delete"/>
# </nc:hold-time></nc:interface><nc:interface><nc:name>fe-0/0/2</nc:name><nc:description delete="delete"/>
# <nc:speed delete="delete"/><nc:mtu delete="delete"/><nc:link-mode delete="delete"/><nc:disable delete="delete"/>
# <nc:hold-time><nc:up delete="delete"/><nc:down delete="delete"/></nc:hold-time></nc:interface><nc:interface>
# <nc:name>ge-0/0/3</nc:name><nc:description delete="delete"/><nc:speed delete="delete"/><nc:mtu delete="delete"/>
# <nc:link-mode delete="delete"/><nc:disable delete="delete"/><nc:hold-time>
# <nc:up delete="delete"/><nc:down delete="delete"/></nc:hold-time></nc:interface>
# <nc:interface><nc:name>fxp0</nc:name><nc:description delete="delete"/><nc:speed delete="delete"/>
# <nc:link-mode delete="delete"/><nc:disable delete="delete"/>
# <nc:hold-time><nc:up delete="delete"/><nc:down delete="delete"/>
# </nc:hold-time></nc:interface><nc:interface><nc:name>lo0</nc:name>
# <nc:description delete="delete"/><nc:disable delete="delete"/>
# <nc:hold-time><nc:up delete="delete"/><nc:down delete="delete"/>
# </nc:hold-time></nc:interface><nc:interface><nc:name>ge-0/0/1</nc:name>
# </nc:interface><nc:interface><nc:name>fe-0/0/2</nc:name>
# <nc:description>Configured by Ansible-2</nc:description>
# <nc:mtu>2800</nc:mtu><nc:disable/></nc:interface><nc:interface>
# <nc:name>ge-0/0/3</nc:name><nc:description>Updated by Ansible-3</nc:description>
# </nc:interface><nc:interface><nc:name>fxp0</nc:name></nc:interface><nc:interface>
# <nc:name>lo0</nc:name></nc:interface></nc:interfaces>
# after:
# - enabled: true
# name: ge-0/0/1
# - description: Configured by Ansible-2
# enabled: false
# mtu: 2800
# name: fe-0/0/2
# - description: Updated by Ansible-3
# enabled: true
# name: ge-0/0/3
# - enabled: true
# name: fxp0
# - enabled: true
# name: lo0
# After state:
# ------------
#
# user@junos01# show interfaces
# ge-0/0/1 {
# unit 0;
# }
# fe-0/0/2 {
# description "Configured by Ansible-2";
# disable;
# vlan-tagging;
# mtu 2800;
# unit 10 {
# vlan-id 10;
# }
# unit 11 {
# vlan-id 11;
# }
# }
# ge-0/0/3 {
# description "Updated by Ansible-3";
# }
# fxp0 {
# unit 0 {
# family inet {
# dhcp;
# }
# }
# }
# lo0 {
# unit 0 {
# family inet {
# address 192.0.2.1/32;
# }
# }
# }
# Using replaced
# Before state:
# -------------
#
# user@junos01# show interfaces
# ge-0/0/1 {
# unit 0;
# }
# fe-0/0/2 {
# description "Configured by Ansible-2";
# disable;
# vlan-tagging;
# mtu 2800;
# unit 10 {
# vlan-id 10;
# }
# unit 11 {
# vlan-id 11;
# }
# }
# ge-0/0/3 {
# description "Updated by Ansible-3";
# }
# fxp0 {
# unit 0 {
# family inet {
# dhcp;
# }
# }
# }
# lo0 {
# unit 0 {
# family inet {
# address 192.0.2.1/32;
# }
# }
# }
- name: Replace device configuration of listed interfaces with provided configuration
junipernetworks.junos.junos_interfaces:
config:
- name: ge-0/0/2
description: Configured by Ansible-2
enabled: false
mtu: 2800
- name: ge-0/0/3
description: Configured by Ansible-3
state: replaced
# Task Output
# -----------
#
# before:
# - enabled: true
# name: ge-0/0/1
# - description: Configured by Ansible-2
# enabled: false
# mtu: 2800
# name: fe-0/0/2
# - description: Updated by Ansible-3
# enabled: true
# name: ge-0/0/3
# - enabled: true
# name: fxp0
# - enabled: true
# name: lo0
# commands:
# - <nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:interface>
# <nc:name>ge-0/0/2</nc:name><nc:description delete="delete"/><nc:speed delete="delete"/>
# <nc:mtu delete="delete"/><nc:link-mode delete="delete"/><nc:disable delete="delete"/>
# <nc:hold-time><nc:up delete="delete"/><nc:down delete="delete"/></nc:hold-time></nc:interface>
# <nc:interface><nc:name>ge-0/0/3</nc:name><nc:description delete="delete"/><nc:speed delete="delete"/>
# <nc:mtu delete="delete"/><nc:link-mode delete="delete"/><nc:disable delete="delete"/><nc:hold-time>
# <nc:up delete="delete"/><nc:down delete="delete"/></nc:hold-time></nc:interface><nc:interface><nc:name>ge-0/0/2</nc:name>
# <nc:description>Configured by Ansible-2</nc:description><nc:mtu>2800</nc:mtu><nc:disable/></nc:interface><nc:interface>
# <nc:name>ge-0/0/3</nc:name><nc:description>Configured by Ansible-3</nc:description></nc:interface></nc:interfaces>
# after:
# - enabled: true
# name: ge-0/0/1
# - description: Configured by Ansible-2
# enabled: false
# mtu: 2800
# name: fe-0/0/2
# - description: Configured by Ansible-2
# enabled: false
# mtu: 2800
# name: ge-0/0/2
# - description: Configured by Ansible-3
# enabled: true
# name: ge-0/0/3
# - enabled: true
# name: fxp0
# - enabled: true
# name: lo0
# After state:
# ------------
#
# user@junos01# show interfaces
# ge-0/0/1 {
# unit 0;
# }
# fe-0/0/2 {
# description "Configured by Ansible-2";
# disable;
# vlan-tagging;
# mtu 2800;
# unit 10 {
# vlan-id 10;
# }
# unit 11 {
# vlan-id 11;
# }
# }
# ge-0/0/2 {
# description "Configured by Ansible-2";
# disable;
# mtu 2800;
# }
# ge-0/0/3 {
# description "Configured by Ansible-3";
# }
# fxp0 {
# unit 0 {
# family inet {
# dhcp;
# }
# }
# }
# lo0 {
# unit 0 {
# family inet {
# address 192.0.2.1/32;
# }
# }
# }
# Using gathered
# Before state:
# ------------
#
# vagrant@vsrx# show interfaces
# ge-0/0/1 {
# unit 0;
# }
# fe-0/0/2 {
# description "Configured by Ansible-2";
# disable;
# vlan-tagging;
# mtu 2800;
# unit 10 {
# vlan-id 10;
# }
# unit 11 {
# vlan-id 11;
# }
# }
# ge-0/0/2 {
# description "Configured by Ansible-2";
# disable;
# mtu 2800;
# }
# ge-0/0/3 {
# description "Configured by Ansible-3";
# }
# fxp0 {
# unit 0 {
# family inet {
# dhcp;
# }
# }
# }
# lo0 {
# unit 0 {
# family inet {
# address 192.0.2.1/32;
# }
# }
# }
- name: Gather junos interfaces as in given arguments
junipernetworks.junos.junos_interfaces:
state: gathered
# Task Output
# -----------
#
# gathered:
# - enabled: true
# name: ge-0/0/1
# - description: Configured by Ansible-2
# enabled: false
# mtu: 2800
# name: fe-0/0/2
# - description: Configured by Ansible-2
# enabled: false
# mtu: 2800
# name: ge-0/0/2
# - description: Configured by Ansible-3
# enabled: true
# name: ge-0/0/3
# - enabled: true
# name: fxp0
# - enabled: true
# name: lo0
# 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">
# <interfaces>
# <interface>
# <name>ge-0/0/1</name>
# <description>Configured by Ansible</description>
# <disable/>
# <speed>100m</speed>
# <mtu>1024</mtu>
# <hold-time>
# <up>2000</up>
# <down>2200</down>
# </hold-time>
# <link-mode>full-duplex</link-mode>
# <unit>
# <name>0</name>
# <family>
# <ethernet-switching>
# <interface-mode>access</interface-mode>
# <vlan>
# <members>vlan100</members>
# </vlan>
# </ethernet-switching>
# </family>
# </unit>
# </interface>
# </interfaces>
# </configuration>
# </rpc-reply>
# - name: Convert interfaces config to structured data without connecting to the appliance
# junipernetworks.junos.junos_interfaces:
# running_config: "{{ lookup('file', './parsed.cfg') }}"
# state: parsed
# Task Output
# -----------
#
# parsed:
# - description: Configured by Ansible
# duplex: full-duplex
# enabled: false
# hold_time:
# down: 2200
# up: 2000
# mtu: 1024
# name: ge-0/0/1
# speed: 100m
# Using rendered
- name: Render platform specific xml from task input using rendered state
junipernetworks.junos.junos_interfaces:
config:
- name: ge-0/0/2
description: Configured by Ansible
mtu: 2048
speed: 20m
hold_time:
up: 3200
down: 3200
state: rendered
# Task Output
# -----------
#
# rendered: <nc:interfaces
# xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
# <nc:interface>
# <nc:name>ge-0/0/2</nc:name>
# <nc:description>Configured by Ansible</nc:description>
# <nc:speed>20m</nc:speed>
# <nc:mtu>2048</nc:mtu>
# <nc:hold-time>
# <nc:up>3200</nc:up>
# <nc:down>3200</nc:down>
# </nc:hold-time>
# </nc:interface>
# </nc:interfaces>"
返回值
常见返回值在此处记录 此处,以下是此模块独有的字段
键 |
描述 |
---|---|
模块完成后的配置作为结构化数据。 返回:发生更改时 示例: |
|
模块调用之前的配置作为结构化数据。 返回:始终返回 示例: |
|
从远程设备收集到的有关网络资源的事实,作为结构化数据。 返回:当 state 为 示例: |
|
根据模块argspec,将running_config选项中提供的设备原生配置解析为结构化数据。 返回:当state为 示例: |
|
在任务中提供的配置以设备原生格式(离线)呈现。 返回:当state为 示例: |
|
推送到远程设备的XML RPC负载集合。 返回:始终返回 示例: |