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)

参数

参数

注释

config

列表 / 元素=字典

第 2 层接口选项的字典

access

字典

将接口配置为第 2 层接入模式。

vlan

字符串

配置接入 VLAN ID。

enhanced_layer

布尔值

如果您的设备具有增强型第 2 层软件 (ELS),则为 True。如果 l2 配置位于 interface-mode 下,则值为 True;否则,如果 l2 配置位于 port-mode 下,则值为 False

选项

  • false

  • true

name

字符串 / 必需

接口的全名,例如 ge-0/0/1。

trunk

字典

将接口配置为第 2 层 trunk 模式。

allowed_vlans

列表 / 元素=字符串

要在 trunk 端口中配置的 VLAN 列表。它用作要添加到 trunk 或从 trunk 中移除的 VLAN 范围。

native_vlan

字符串

要在 trunk 端口中配置的原生 VLAN。它用作 trunk 原生 VLAN ID。

unit

整数

逻辑接口编号。unit 的值应为整数类型。

running_config

字符串

此选项仅与 state *parsed* 一起使用。

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

state *parsed* 从 running_config 选项读取配置并将其转换为 Ansible 结构化数据,该数据符合资源模块的 argspec,然后该值将返回到结果中的 *parsed* 密钥中。

state

字符串

模块完成后的配置状态

选项

  • "merged" ← (默认)

  • "replaced"

  • "overridden"

  • "deleted"

  • "gathered"

  • "parsed"

  • "rendered"

备注

注意

示例

# 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>"

返回值

常见的返回值在此处有说明 此处,以下是此模块特有的字段

描述

after

列表 / 元素=字符串

模块完成后的配置作为结构化数据。

返回:发生更改时

示例: ["The configuration returned will always be in the same format\n of the parameters above.\n"]

before

列表 / 元素=字符串

模块调用之前的配置作为结构化数据。

返回:始终返回

示例: ["The configuration returned will always be in the same format\n of the parameters above.\n"]

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: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>", "xml 2", "xml 3"]

收集

列表 / 元素=字符串

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

返回:stategathered

示例: ["此输出将始终与模块argspec格式相同。\n"]

解析

列表 / 元素=字符串

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

返回:stateparsed

示例: ["此输出将始终与模块argspec格式相同。\n"]

渲染

列表 / 元素=字符串

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

返回:staterendered

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

作者

  • Ganesh Nalawade (@ganeshrn)