arista.eos.eos_l2_interfaces 模块 – L2 接口资源模块

注意

此模块是 arista.eos 集合 (版本 10.0.1) 的一部分。

如果您使用的是 ansible 包,则可能已经安装了此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install arista.eos

要在 playbook 中使用它,请指定:arista.eos.eos_l2_interfaces

arista.eos 1.0.0 中的新增功能

概要

  • 此模块提供对 Arista EOS 设备上的第 2 层接口的声明式管理。

参数

参数

注释

config

列表 / 元素=字典

第 2 层接口选项的字典

access

字典

Switchport mode access 命令,用于将接口配置为第 2 层接入端口。

vlan

整数

在接入端口中配置给定的 VLAN。它用作接入 VLAN ID。

mode

字符串

需要配置接口的模式。

接入模式未显示在接口事实中,因此对于 switchport mode access,不会保持幂等性,每次输出都将显示为 changed=True。

选项

  • "access"

  • "trunk"

name

字符串 / 必需

接口的全名,例如 Ethernet1。

trunk

字典

Switchport mode trunk 命令,用于将接口配置为第 2 层 trunk 端口。

native_vlan

整数

要在 trunk 端口中配置的本机 VLAN。它用作 trunk 本机 VLAN ID。

trunk_allowed_vlans

列表 / 元素=字符串

给定 trunk 端口中允许的 VLAN 列表。这些是将在 trunk 上配置的唯一 VLAN。

running_config

字符串

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

此选项的值应为通过执行命令 **show running-config | section ^interface** 从 EOS 设备接收的输出。

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

state

字符串

模块完成后的配置状态

选项

  • "merged" ← (默认)

  • "replaced"

  • "overridden"

  • "deleted"

  • "parsed"

  • "rendered"

  • "gathered"

备注

注意

示例

# Using merged

# Before state:
# -------------
#
# test#show running-config | section interface
# interface Ethernet1
# !
# interface Ethernet2
#    description Configured by Ansible
#    shutdown
# !
# interface Management1
#    ip address dhcp
#    dhcp client accept default-route

- name: Merge provided configuration with device configuration.
  arista.eos.eos_l2_interfaces:
    config:
      - name: Ethernet1
        mode: trunk
        trunk:
          native_vlan: 10
      - name: Ethernet2
        mode: access
        access:
          vlan: 30
    state: merged

# Task Output
# -----------
#
# before:
# - name: Ethernet1
# - name: Ethernet2
# - name: Management1
# commands:
# - interface Ethernet1
# - switchport mode trunk
# - switchport trunk native vlan 10
# - interface Ethernet2
# - switchport mode access
# - switchport access vlan 30
# after:
# - mode: trunk
#   name: Ethernet1
#   trunk:
#     native_vlan: 10
# - access:
#     vlan: 30
#   name: Ethernet2
# - name: Management1

# After state:
# ------------
#
# test#show running-config | section interface
# interface Ethernet1
#    switchport trunk native vlan 10
#    switchport mode trunk
# !
# interface Ethernet2
#    description Configured by Ansible
#    shutdown
#    switchport access vlan 30
# !
# interface Management1
#    ip address dhcp
#    dhcp client accept default-route

# Using replaced

# Before state:
# -------------
#
# test#show running-config | section interface
# interface Ethernet1
#    switchport trunk native vlan 10
#    switchport mode trunk
# !
# interface Ethernet2
#    description Configured by Ansible
#    shutdown
#    switchport access vlan 30
# !
# interface Management1
#    ip address dhcp
#    dhcp client accept default-route

- name: Replace device configuration of specified L2 interfaces with provided configuration.
  arista.eos.eos_l2_interfaces:
    config:
      - name: Ethernet1
        mode: trunk
        trunk:
          native_vlan: 20
          trunk_allowed_vlans: 5-10, 15
    state: replaced

# Task Output
# -----------
#
# before:
# - mode: trunk
#   name: Ethernet1
#   trunk:
#     native_vlan: 10
# - access:
#     vlan: 30
#   name: Ethernet2
# - name: Management1
# commands:
# - interface Ethernet1
# - switchport trunk native vlan 20
# - switchport trunk allowed vlan 10,15,5,6,7,8,9
# after:
# - mode: trunk
#   name: Ethernet1
#   trunk:
#     native_vlan: 20
#     trunk_allowed_vlans:
#     - 5-10
#     - '15'
# - access:
#     vlan: 30
#   name: Ethernet2
# - name: Management1

# After state:
# ------------
#
# test#show running-config | section interface
# interface Ethernet1
#    switchport trunk native vlan 20
#    switchport trunk allowed vlan 5-10,15
#    switchport mode trunk
# !
# interface Ethernet2
#    description Configured by Ansible
#    shutdown
#    switchport access vlan 30
# !
# interface Management1
#    ip address dhcp
#    dhcp client accept default-route

# Using overridden

# Before state:
# -------------
#
# test#show running-config | section interface
# interface Ethernet1
#    switchport trunk native vlan 20
#    switchport trunk allowed vlan 5-10,15
#    switchport mode trunk
# !
# interface Ethernet2
#    description Configured by Ansible
#    shutdown
#    switchport access vlan 30
# !
# interface Management1
#    ip address dhcp
#    dhcp client accept default-route

- name: Override device configuration of all L2 interfaces on device with provided
    configuration.
  arista.eos.eos_l2_interfaces:
    config:
      - name: Ethernet2
        mode: access
        access:
          vlan: 30
    state: overridden

# Task Output
# -----------
#
# before:
# - mode: trunk
#   name: Ethernet1
#   trunk:
#     native_vlan: 20
#     trunk_allowed_vlans:
#     - 5-10
#     - '15'
# - access:
#     vlan: 30
#   name: Ethernet2
# - name: Management1
# commands:
# - interface Ethernet1
# - no switchport mode
# - no switchport trunk allowed vlan
# - no switchport trunk native vlan
# - interface Ethernet2
# - switchport mode access
# after:
# - name: Ethernet1
# - access:
#     vlan: 30
#   name: Ethernet2
# - name: Management1

# After state:
# ------------
#
# test#show running-config | section interface
# interface Ethernet1
# !
# interface Ethernet2
#    description Configured by Ansible
#    shutdown
#    switchport access vlan 30
# !
# interface Management1
#    ip address dhcp
#    dhcp client accept default-route

# Using deleted

# Before state:
# -------------
#
# test#show running-config | section interface
# interface Ethernet1
# !
# interface Ethernet2
#    description Configured by Ansible
#    shutdown
#    switchport access vlan 30
# !
# interface Management1
#    ip address dhcp
#    dhcp client accept default-route

- name: Delete EOS L2 interfaces as in given arguments.
  arista.eos.eos_l2_interfaces:
    config:
      - name: Ethernet1
      - name: Ethernet2
    state: deleted

# Task Output
# -----------
#
# before:
# - name: Ethernet1
# - access:
#     vlan: 30
#   name: Ethernet2
# - name: Management1
# commands:
# - interface Ethernet2
# - no switchport access vlan
# after:
# - name: Ethernet1
# - name: Ethernet2
# - name: Management1

# After state:
# ------------
#
# test#show running-config | section interface
# interface Ethernet1
# !
# interface Ethernet2
#    description Configured by Ansible
#    shutdown
# !
# interface Management1
#    ip address dhcp
#    dhcp client accept default-route

# using rendered

- name: Use Rendered to convert the structured data to native config
  arista.eos.eos_l2_interfaces:
    config:
      - name: Ethernet1
        mode: trunk
        trunk:
          native_vlan: 10
      - name: Ethernet2
        mode: access
        access:
          vlan: 30
    state: rendered

# Module Execution Result:
# ------------------------
#
# rendered:
# - interface Ethernet1
# - switchport mode trunk
# - switchport trunk native vlan 10
# - interface Ethernet2
# - switchport mode access
# - switchport access vlan 30

# Using parsed

# File: parsed.cfg
# ----------------
#
# interface Ethernet1
#    switchport trunk native vlan 10
#    switchport mode trunk
# !
# interface Ethernet2
#    switchport access vlan 30
# !

- name: Parse the commands for provided configuration
  arista.eos.l2_interfaces:
    running_config: "{{ lookup('file', 'parsed.cfg') }}"
    state: parsed

# Module Execution Result:
# ------------------------
#
# parsed:
#  - name: Ethernet1
#    mode: trunk
#    trunk:
#      native_vlan: 10
#  - name: Ethernet2
#    mode: access
#    access:
#      vlan: 30

# Using gathered

# Before state:
# -------------
#
# veos#show running-config | section interface
# interface Ethernet1
#    switchport trunk native vlan 10
#    switchport mode trunk
# !
# interface Ethernet2
#    switchport access vlan 30
# !

- name: Gather interfaces facts from the device
  arista.eos.l2_interfaces:
    state: gathered

# Module Execution Result:
# ------------------------
#
# gathered:
# - name: Ethernet1
#   mode: trunk
#   trunk:
#     native_vlan: 10
# - name: Ethernet2
#   mode: access
#   access:
#     vlan: 30

返回值

常见的返回值已记录在 此处,以下是此模块特有的字段

描述

after

字典

模块执行后的结果配置。

返回:发生更改时

示例: "This output will always be in the same format as the module argspec.\n"

before

字典

模块执行前的配置。

返回:statemergedreplacedoverriddendeletedpurged

示例: "This output will always be in the same format as the module argspec.\n"

commands

列表 / 元素=字符串

推送到远程设备的命令集。

返回:statemergedreplacedoverriddendeletedpurged

示例: ["interface Ethernet1", "switchport mode trunk", "switchport access vlan 20"]

gathered

列表 / 元素=字符串

从远程设备收集到的关于网络资源的事实,以结构化数据的形式呈现。

返回:stategathered

示例: ["This output will always be in the same format as the module argspec.\n"]

parsed

列表 / 元素=字符串

根据模块参数规范(argspec),在running_config选项中提供的设备原生配置被解析成结构化数据。

返回:stateparsed

示例: ["This output will always be in the same format as the module argspec.\n"]

渲染

列表 / 元素=字符串

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

返回:staterendered

示例: ["interface Ethernet1", "switchport mode trunk", "switchport access vlan 20"]

作者

  • Nathaniel Case (@Qalthos)