junipernetworks.junos.junos_l2_interfaces 模块 – L2 接口资源模块
注意
此模块是 junipernetworks.junos 集合 (版本 9.1.0) 的一部分。
如果您使用的是 ansible
包,则可能已经安装了此集合。它不包含在 ansible-core
中。要检查它是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用:ansible-galaxy collection install junipernetworks.junos
。您需要其他要求才能使用此模块,有关详细信息,请参阅 需求。
要在 playbook 中使用它,请指定:junipernetworks.junos.junos_l2_interfaces
。
junipernetworks.junos 1.0.0 中的新增功能
概要
此模块提供对 Juniper JUNOS 设备上第 2 层接口的声明式管理。
需求
执行此模块的主机需要以下要求。
ncclient (>=v0.6.4)
参数
参数 |
注释 |
---|---|
第 2 层接口选项的字典 |
|
将接口配置为第 2 层接入模式。 |
|
配置接入 VLAN ID。 |
|
如果您的设备具有增强型第 2 层软件 (ELS),则为 True。如果 l2 配置位于 选项
|
|
接口的全名,例如 ge-0/0/1。 |
|
将接口配置为第 2 层 trunk 模式。 |
|
要在 trunk 端口中配置的 VLAN 列表。它用作要添加到 trunk 或从 trunk 中移除的 VLAN 范围。 |
|
要在 trunk 端口中配置的原生 VLAN。它用作 trunk 原生 VLAN ID。 |
|
逻辑接口编号。 |
|
此选项仅与 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:
# -------------
#
# ansible@junos01# show interfaces
# ge-0/0/1 {
# unit 0 {
# family inet;
# family inet6;
# }
# }
# ge-0/0/2 {
# unit 0 {
# family inet;
# family inet6;
# }
# }
# ge-0/0/3 {
# unit 0 {
# family ethernet-switching {
# interface-mode access;
# }
# }
# }
# ge-0/0/4 {
# unit 0 {
# family ethernet-switching {
# interface-mode access;
# }
# }
# }
# fxp0 {
# enable;
# unit 0 {
# family inet {
# dhcp;
# }
# family inet6;
# }
# }
- name: Merge provided configuration with device configuration
junipernetworks.junos.junos_l2_interfaces:
config:
- name: ge-0/0/3
access:
vlan: v101
- name: ge-0/0/4
trunk:
allowed_vlans:
- vlan30
native_vlan: 50
state: merged
# Task Output
# -----------
#
# before:
# - enhanced_layer: true
# name: ge-0/0/3
# unit: 0
# - enhanced_layer: true
# name: ge-0/0/4
# unit: 0
# commands:
# - <nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
# <nc:interface>
# <nc:name>ge-0/0/3</nc:name>
# <nc:unit>
# <nc:name>0</nc:name>
# <nc:family>
# <nc:ethernet-switching>
# <nc:interface-mode>access</nc:interface-mode>
# <nc:vlan>
# <nc:members>v101</nc:members>
# </nc:vlan>
# </nc:ethernet-switching>
# </nc:family>
# </nc:unit>
# </nc:interface>
# <nc:interface>
# <nc:name>ge-0/0/4</nc:name>
# <nc:unit>
# <nc:name>0</nc:name>
# <nc:family>
# <nc:ethernet-switching>
# <nc:interface-mode>trunk</nc:interface-mode>
# <nc:vlan>
# <nc:members>vlan30</nc:members>
# </nc:vlan>
# </nc:ethernet-switching>
# </nc:family>
# </nc:unit>
# <nc:native-vlan-id>50</nc:native-vlan-id>
# </nc:interface>
# </nc:interfaces>
# after:
# - access:
# vlan: v101
# enhanced_layer: true
# name: ge-0/0/3
# unit: 0
# - enhanced_layer: true
# name: ge-0/0/4
# trunk:
# allowed_vlans:
# - vlan30
# native_vlan: '50'
# unit: 0
# After state:
# ------------
#
# user@junos01# show interfaces
# ge-0/0/1 {
# unit 0 {
# family inet;
# family inet6;
# }
# }
# ge-0/0/2 {
# unit 0 {
# family inet;
# family inet6;
# }
# }
# ge-0/0/3 {
# unit 0 {
# family ethernet-switching {
# interface-mode access;
# vlan {
# members v101;
# }
# }
# }
# }
# ge-0/0/4 {
# native-vlan-id 50;
# unit 0 {
# family ethernet-switching {
# interface-mode trunk;
# vlan {
# members vlan30;
# }
# }
# }
# }
# fxp0 {
# enable;
# unit 0 {
# family inet {
# dhcp;
# }
# family inet6;
# }
# }
# Using overridden
# Before state:
# -------------
# ansible@junos01# show interfaces
# ge-0/0/1 {
# unit 0 {
# family inet;
# family inet6;
# }
# }
# ge-0/0/2 {
# unit 0 {
# family inet;
# family inet6;
# }
# }
# ge-0/0/3 {
# unit 0 {
# family ethernet-switching {
# interface-mode access;
# vlan {
# members v101;
# }
# }
# }
# }
# ge-0/0/4 {
# native-vlan-id 50;
# unit 0 {
# family ethernet-switching {
# interface-mode trunk;
# vlan {
# members vlan30;
# }
# }
# }
# }
# fxp0 {
# enable;
# unit 0 {
# family inet {
# dhcp;
# }
# family inet6;
# }
# }
- name: Override provided configuration with device configuration
junipernetworks.junos.junos_l2_interfaces:
config:
- name: ge-0/0/4
trunk:
allowed_vlans:
- v101
native_vlan: 30
state: overridden
# Task Output
# -----------
#
# before:
# - access:
# vlan: v101
# enhanced_layer: true
# name: ge-0/0/3
# unit: 0
# - enhanced_layer: true
# name: ge-0/0/4
# trunk:
# allowed_vlans:
# - vlan30
# native_vlan: '50'
# unit: 0
# commands:
# - <nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
# <nc:interface>
# <nc:name>ge-0/0/4</nc:name>
# <nc:unit>
# <nc:name>0</nc:name>
# <nc:family>
# <nc:ethernet-switching>
# <nc:interface-mode delete="delete"/>
# <nc:vlan delete="delete"/>
# </nc:ethernet-switching>
# </nc:family>
# </nc:unit>
# <nc:native-vlan-id delete="delete"/>
# </nc:interface>
# <nc:interface>
# <nc:name>ge-0/0/4</nc:name>
# <nc:unit>
# <nc:name>0</nc:name>
# <nc:family>
# <nc:ethernet-switching>
# <nc:interface-mode>trunk</nc:interface-mode>
# <nc:vlan>
# <nc:members>v101</nc:members>
# </nc:vlan>
# </nc:ethernet-switching>
# </nc:family>
# </nc:unit>
# <nc:native-vlan-id>30</nc:native-vlan-id>
# </nc:interface>
# <nc:interface>
# <nc:name>ge-0/0/3</nc:name>
# <nc:unit>
# <nc:name>0</nc:name>
# <nc:family>
# <nc:ethernet-switching>
# <nc:interface-mode delete="delete"/>
# <nc:vlan delete="delete"/>
# </nc:ethernet-switching>
# </nc:family>
# </nc:unit>
# <nc:native-vlan-id delete="delete"/>
# </nc:interface>
# </nc:interfaces>
# after:
# - enhanced_layer: true
# name: ge-0/0/4
# trunk:
# allowed_vlans:
# - v101
# native_vlan: '30'
# unit: 0
# After state:
# ------------
# user@junos01# show interfaces
# ge-0/0/1 {
# unit 0 {
# family inet;
# family inet6;
# }
# }
# ge-0/0/2 {
# unit 0 {
# family inet;
# family inet6;
# }
# }
# ge-0/0/3 {
# unit 0 {
# family ethernet-switching;
# }
# }
# ge-0/0/4 {
# native-vlan-id 30;
# unit 0 {
# family ethernet-switching {
# interface-mode trunk;
# vlan {
# members v101;
# }
# }
# }
# }
# fxp0 {
# enable;
# unit 0 {
# family inet {
# dhcp;
# }
# family inet6;
# }
# }
# Using replaced
# Before state:
# -------------
#
# ansible@junos01# show interfaces
# ge-0/0/1 {
# unit 0 {
# family inet;
# family inet6;
# }
# }
# ge-0/0/2 {
# unit 0 {
# family inet;
# family inet6;
# }
# }
# ge-0/0/3 {
# unit 0 {
# family ethernet-switching;
# }
# }
# ge-0/0/4 {
# native-vlan-id 30;
# unit 0 {
# family ethernet-switching {
# interface-mode trunk;
# vlan {
# members v101;
# }
# }
# }
# }
# fxp0 {
# enable;
# unit 0 {
# family inet {
# dhcp;
# }
# family inet6;
# }
# }
- name: Replace provided configuration with device configuration
junipernetworks.junos.junos_l2_interfaces:
config:
- name: ge-0/0/3
access:
vlan: v101
- name: ge-0/0/4
trunk:
allowed_vlans:
- vlan30
native_vlan: 50
state: replaced
# Task Output
# -----------
#
# before:
# - enhanced_layer: true
# name: ge-0/0/4
# trunk:
# allowed_vlans:
# - v101
# native_vlan: '30'
# unit: 0
# commands:
# - <nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
# <nc:interface>
# <nc:name>ge-0/0/4</nc:name>
# <nc:unit>
# <nc:name>0</nc:name>
# <nc:family>
# <nc:ethernet-switching>
# <nc:interface-mode delete="delete"/>
# <nc:vlan delete="delete"/>
# </nc:ethernet-switching>
# </nc:family>
# </nc:unit>
# <nc:native-vlan-id delete="delete"/>
# </nc:interface>
# <nc:interface>
# <nc:name>ge-0/0/3</nc:name>
# <nc:unit>
# <nc:name>0</nc:name>
# <nc:family>
# <nc:ethernet-switching>
# <nc:interface-mode>access</nc:interface-mode>
# <nc:vlan>
# <nc:members>v101</nc:members>
# </nc:vlan>
# </nc:ethernet-switching>
# </nc:family>
# </nc:unit>
# </nc:interface>
# <nc:interface>
# <nc:name>ge-0/0/4</nc:name>
# <nc:unit>
# <nc:name>0</nc:name>
# <nc:family>
# <nc:ethernet-switching>
# <nc:interface-mode>trunk</nc:interface-mode>
# <nc:vlan>
# <nc:members>vlan30</nc:members>
# </nc:vlan>
# </nc:ethernet-switching>
# </nc:family>
# </nc:unit>
# <nc:native-vlan-id>50</nc:native-vlan-id>
# </nc:interface>
# </nc:interfaces>
# after:
# - access:
# vlan: v101
# enhanced_layer: true
# name: ge-0/0/3
# unit: 0
# - enhanced_layer: true
# name: ge-0/0/4
# trunk:
# allowed_vlans:
# - vlan30
# native_vlan: '50'
# unit: 0
# After state:
# ------------
#
# user@junos01# show interfaces
# ge-0/0/1 {
# unit 0 {
# family inet;
# family inet6;
# }
# }
# ge-0/0/2 {
# unit 0 {
# family inet;
# family inet6;
# }
# }
# ge-0/0/3 {
# unit 0 {
# family ethernet-switching {
# interface-mode access;
# vlan {
# members v101;
# }
# }
# }
# }
# ge-0/0/4 {
# native-vlan-id 50;
# unit 0 {
# family ethernet-switching {
# interface-mode trunk;
# vlan {
# members vlan30;
# }
# }
# }
# }
# fxp0 {
# enable;
# unit 0 {
# family inet {
# dhcp;
# }
# family inet6;
# }
# }
# Using deleted
# Before state:
# -------------
#
# ansible@junos01# show interfaces
# ge-0/0/1 {
# unit 0 {
# family inet;
# family inet6;
# }
# }
# ge-0/0/2 {
# unit 0 {
# family inet;
# family inet6;
# }
# }
# ge-0/0/3 {
# unit 0 {
# family ethernet-switching {
# interface-mode access;
# vlan {
# members v101;
# }
# }
# }
# }
# ge-0/0/4 {
# native-vlan-id 50;
# unit 0 {
# family ethernet-switching {
# interface-mode trunk;
# vlan {
# members vlan30;
# }
# }
# }
# }
# fxp0 {
# enable;
# unit 0 {
# family inet {
# dhcp;
# }
# family inet6;
# }
# }
- name: "Delete L2 attributes of given interfaces (Note: This won't delete the
interface itself)."
junipernetworks.junos.junos_l2_interfaces:
config:
- name: ge-0/0/1
- name: ge-0/0/2
state: deleted
# Task Output
# -----------
#
# before:
# - access:
# vlan: v101
# enhanced_layer: true
# name: ge-0/0/3
# unit: 0
# - enhanced_layer: true
# name: ge-0/0/4
# trunk:
# allowed_vlans:
# - vlan30
# native_vlan: '50'
# unit: 0
# commands:
# - <nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
# <nc:interface>
# <nc:name>ge-0/0/3</nc:name>
# <nc:unit>
# <nc:name>0</nc:name>
# <nc:family>
# <nc:ethernet-switching>
# <nc:interface-mode delete="delete"/>
# <nc:vlan delete="delete"/>
# </nc:ethernet-switching>
# </nc:family>
# </nc:unit>
# <nc:native-vlan-id delete="delete"/>
# </nc:interface>
# </nc:interfaces>
# after:
# - enhanced_layer: true
# name: ge-0/0/4
# trunk:
# allowed_vlans:
# - vlan30
# native_vlan: '50'
# unit: 0
# After state:
# ------------
#
# ansible@junos01# show interfaces
# ge-0/0/1 {
# unit 0 {
# family inet;
# family inet6;
# }
# }
# ge-0/0/2 {
# unit 0 {
# family inet;
# family inet6;
# }
# }
# ge-0/0/3 {
# unit 0 {
# family ethernet-switching;
# }
# }
# ge-0/0/4 {
# native-vlan-id 50;
# unit 0 {
# family ethernet-switching {
# interface-mode trunk;
# vlan {
# members vlan30;
# }
# }
# }
# }
# fxp0 {
# enable;
# unit 0 {
# family inet {
# dhcp;
# }
# family inet6;
# }
# }
# Using gathered
# Before state:
# -------------
#
# user@junos01# show interfaces
# ge-0/0/1 {
# description "Configured by Ansible";
# disable;
# speed 100m;
# mtu 1024;
# hold-time up 2000 down 2200;
# link-mode full-duplex;
# unit 0 {
# family ethernet-switching {
# interface-mode access;
# vlan {
# members vlan100;
# }
# }
# }
# }
# ge-0/0/2 {
# description "Configured by Ansible";
# native-vlan-id 400;
# speed 10m;
# mtu 2048;
# hold-time up 3000 down 3200;
# unit 0 {
# family ethernet-switching {
# interface-mode trunk;
# vlan {
# members [ vlan200 vlan300 ];
# }
# }
# }
# }
# em1 {
# description TEST;
# }
# fxp0 {
# description ANSIBLE;
# speed 1g;
# link-mode automatic;
# unit 0 {
# family inet {
# address 10.8.38.38/24;
# }
# }
# }
- name: Gather junos layer 2 interfaces facts
junipernetworks.junos.junos_l2_interfaces:
state: gathered
# Task Output
# -----------
#
# gathered:
# - access:
# vlan: vlan100
# enhanced_layer: true
# name: ge-0/0/1
# unit: 0
# - enhanced_layer: true
# name: ge-0/0/2
# trunk:
# allowed_vlans:
# - vlan200
# - vlan300
# native_vlan: '400'
# unit: 0
# 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 argspec without connecting to the appliance
junipernetworks.junos.junos_l2_interfaces:
running_config: "{{ lookup('file', './parsed.cfg') }}"
state: parsed
# Task Output
# -----------
#
# parsed:
# - access:
# vlan: vlan100
# enhanced_layer: true
# name: ge-0/0/1
# unit: 0
# - enhanced_layer: true
# name: ge-0/0/2
# trunk:
# allowed_vlans:
# - vlan200
# - vlan300
# native_vlan: '400'
# unit: 0
# Using rendered
- name: Render platform specific xml from task input using rendered state
junipernetworks.junos.junos_l2_interfaces:
config:
- name: ge-0/0/1
access:
vlan: vlan100
- name: ge-0/0/2
trunk:
allowed_vlans:
- vlan200
- vlan300
native_vlan: '400'
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/1</nc:name>
# <nc:unit>
# <nc:name>0</nc:name>
# <nc:family>
# <nc:ethernet-switching>
# <nc:interface-mode>access</nc:interface-mode>
# <nc:vlan>
# <nc:members>vlan100</nc:members>
# </nc:vlan>
# </nc:ethernet-switching>
# </nc:family>
# </nc:unit>
# </nc:interface>
# <nc:interface>
# <nc:name>ge-0/0/2</nc:name>
# <nc:unit>
# <nc:name>0</nc:name>
# <nc:family>
# <nc:ethernet-switching>
# <nc:interface-mode>trunk</nc:interface-mode>
# <nc:vlan>
# <nc:members>vlan200</nc:members>
# <nc:members>vlan300</nc:members>
# </nc:vlan>
# </nc:ethernet-switching>
# </nc:family>
# </nc:unit>
# <nc:native-vlan-id>400</nc:native-vlan-id>
# </nc:interface>
# </nc:interfaces>"
返回值
常见的返回值在此处有说明 此处,以下是此模块特有的字段
键 |
描述 |
---|---|
模块完成后的配置作为结构化数据。 返回:发生更改时 示例: |
|
模块调用之前的配置作为结构化数据。 返回:始终返回 示例: |
|
推送到远程设备的命令集。 返回:始终返回 示例: |
|
从远程设备收集到的关于网络资源的结构化数据。 返回:当state 为 示例: |
|
根据模块argspec,将running_config选项中提供的设备原生配置解析为结构化数据。 返回:当state 为 示例: |
|
以设备原生格式渲染任务中提供的配置(离线)。 返回:当state 为 示例: |