junipernetworks.junos.junos_l2_interfaces module – L2 interfaces resource module
Note
This module is part of the junipernetworks.junos collection (version 2.10.0).
You might already have this collection installed if you are using the ansible
package.
It is not included in ansible-core
.
To check whether it is installed, run ansible-galaxy collection list
.
To install it, use: ansible-galaxy collection install junipernetworks.junos
.
To use it in a playbook, specify: junipernetworks.junos.junos_l2_interfaces
.
New in version 1.0.0: of junipernetworks.junos
Synopsis
This module provides declarative management of a Layer-2 interface on Juniper JUNOS devices.
Note
This module has a corresponding action plugin.
Requirements
The below requirements are needed on the host that executes this module.
ncclient (>=v0.6.4)
Parameters
Parameter |
Comments |
---|---|
A dictionary of Layer-2 interface options |
|
Configure the interface as a Layer 2 access mode. |
|
Configure the access VLAN ID. |
|
True if your device has Enhanced Layer 2 Software (ELS). If the l2 configuration is under Choices:
|
|
Full name of interface, e.g. ge-0/0/1. |
|
Configure the interface as a Layer 2 trunk mode. |
|
List of VLANs to be configured in trunk port. It’s used as the VLAN range to ADD or REMOVE from the trunk. |
|
Native VLAN to be configured in trunk port. It is used as the trunk native VLAN ID. |
|
Logical interface number. Value of |
|
This option is used only with state parsed. The value of this option should be the output received from the Junos device by executing the command show interfaces. The state parsed reads the configuration from |
|
The state of the configuration after module completion Choices:
|
Notes
Note
This module requires the netconf system service be enabled on the remote device being managed.
Tested against vSRX JUNOS version 18.4R1.
This module works with connection
netconf
. See the Junos OS Platform Options.
Examples
# Using deleted
# Before state:
# -------------
#
# ansible@junos01# show interfaces
# ge-0/0/1 {
# description "L2 interface";
# speed 1g;
# unit 0 {
# family ethernet-switching {
# interface-mode access;
# vlan {
# members vlan30;
# }
# }
# }
#}
#ge-0/0/2 {
# description "non L2 interface";
# unit 0 {
# family inet {
# address 192.168.56.14/24;
# }
# }
- 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
# After state:
# ------------
#
# ansible@junos01# show interfaces
# ge-0/0/1 {
# description "L2 interface";
# speed 1g;
# }
#ge-0/0/2 {
# description "non L2 interface";
# unit 0 {
# family inet {
# address 192.168.56.14/24;
# }
# }
# Using merged
# Before state:
# -------------
# ansible@junos01# show interfaces
# ge-0/0/3 {
# description "test interface";
# speed 1g;
#}
# ge-0/0/4 {
# description interface-trunk;
# native-vlan-id 100;
# unit 0 {
# family ethernet-switching {
# interface-mode trunk;
# vlan {
# members [ vlan40 ];
# }
# }
# }
# }
- name: Merge provided configuration with device configuration (default operation
is merge)
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
# After state:
# ------------
# user@junos01# show interfaces
# ge-0/0/3 {
# description "test interface";
# speed 1g;
# unit 0 {
# family ethernet-switching {
# interface-mode access;
# vlan {
# members v101;
# }
# }
# }
# }
# ge-0/0/4 {
# description interface-trunk;
# native-vlan-id 50;
# unit 0 {
# family ethernet-switching {
# interface-mode trunk;
# vlan {
# members [ vlan40 vlan30 ];
# }
# }
# }
# }
# Using overridden
# Before state:
# -------------
# ansible@junos01# show interfaces
# ge-0/0/3 {
# description "test interface";
# speed 1g;
#}
# ge-0/0/4 {
# description interface-trunk;
# native-vlan-id 100;
# unit 0 {
# family ethernet-switching {
# interface-mode trunk;
# vlan {
# members [ vlan40 ];
# }
# }
# }
# }
# ge-0/0/5 {
# description "Configured by Ansible-11";
# unit 0 {
# family ethernet-switching {
# interface-mode access;
# vlan {
# members v101;
# }
# }
# }
# }
- name: Override 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: overridden
# After state:
# ------------
# user@junos01# show interfaces
# ge-0/0/3 {
# unit 0 {
# family ethernet-switching {
# interface-mode access;
# vlan {
# members v101;
# }
# }
# }
# }
# ge-0/0/4 {
# description interface-trunk;
# native-vlan-id 50;
# unit 0 {
# family ethernet-switching {
# interface-mode trunk;
# vlan {
# members [ vlan30 ];
# }
# }
# }
# }
# Using replaced
# Before state:
# -------------
# ansible@junos01# show interfaces
# ge-0/0/3 {
# description "test interface";
# speed 1g;
#}
# ge-0/0/4 {
# description interface-trunk;
# native-vlan-id 100;
# unit 0 {
# family ethernet-switching {
# interface-mode trunk;
# vlan {
# members [ vlan40 ];
# }
# }
# }
# }
- 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
# After state:
# ------------
# user@junos01# show interfaces
# ge-0/0/3 {
# unit 0 {
# family ethernet-switching {
# interface-mode access;
# vlan {
# members v101;
# }
# }
# }
# }
# ge-0/0/4 {
# description interface-trunk;
# native-vlan-id 50;
# unit 0 {
# family ethernet-switching {
# interface-mode trunk;
# vlan {
# members [ vlan30 ];
# }
# }
# }
# }
# 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 as in given arguments
junipernetworks.junos.junos_l2_interfaces:
state: gathered
# Task Output (redacted)
# -----------------------
#
# "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
# }
# ]
# After 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;
# }
# }
# }
# 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 (redacted)
# -----------------------
# "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 (redacted)
# -----------------------
# "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>"
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
---|---|
The configuration as structured data after module completion. Returned: when changed Sample: “The configuration returned will always be in the same format\n of the parameters above.\n” |
|
The configuration as structured data prior to module invocation. Returned: always Sample: “The configuration returned will always be in the same format\n of the parameters above.\n” |
|
The set of commands pushed to the remote device. Returned: always Sample: [“\u003cnc:interfaces xmlns:nc=\”urn:ietf:params:xml:ns:netconf:base:1.0\”\u003e \u003cnc:interface\u003e \u003cnc:name\u003ege-0/0/1\u003c/nc:name\u003e \u003cnc:unit\u003e \u003cnc:name\u003e0\u003c/nc:name\u003e \u003cnc:family\u003e \u003cnc:ethernet-switching\u003e \u003cnc:interface-mode\u003eaccess\u003c/nc:interface-mode\u003e \u003cnc:vlan\u003e \u003cnc:members\u003evlan100\u003c/nc:members\u003e \u003c/nc:vlan\u003e \u003c/nc:ethernet-switching\u003e \u003c/nc:family\u003e \u003c/nc:unit\u003e \u003c/nc:interface\u003e \u003cnc:interface\u003e \u003cnc:name\u003ege-0/0/2\u003c/nc:name\u003e \u003cnc:unit\u003e \u003cnc:name\u003e0\u003c/nc:name\u003e \u003cnc:family\u003e \u003cnc:ethernet-switching\u003e \u003cnc:interface-mode\u003etrunk\u003c/nc:interface-mode\u003e \u003cnc:vlan\u003e \u003cnc:members\u003evlan200\u003c/nc:members\u003e \u003cnc:members\u003evlan300\u003c/nc:members\u003e \u003c/nc:vlan\u003e \u003c/nc:ethernet-switching\u003e \u003c/nc:family\u003e \u003c/nc:unit\u003e \u003cnc:native-vlan-id\u003e400\u003c/nc:native-vlan-id\u003e \u003c/nc:interface\u003e \u003c/nc:interfaces\u003e”, “xml 2”, “xml 3”] |
Authors
Ganesh Nalawade (@ganeshrn)