arista.eos.eos_interfaces 模块 – 接口资源模块

注意

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

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

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

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

arista.eos 1.0.0 中的新增功能

概要

  • 此模块管理 Arista EOS 接口的接口属性。

参数

参数

注释

config

列表 / 元素=字典

提供的配置

description

字符串

接口描述

duplex

字符串

接口链路状态。仅适用于以太网接口。

auto 之外的值还必须设置 speed

speed 设置为高于 1000 时将被忽略。

enabled

布尔值

接口的管理状态。

将该值设置为 true 以管理方式启用接口,或设置为 false 以禁用它。

选项

  • false

  • true ← (默认)

mode

字符串

管理接口的第 2 层或第 3 层状态。仅适用于以太网和端口通道接口。

选项

  • "layer2"

  • "layer3"

mtu

整数

特定接口的 MTU。必须是介于 576 和 9216 之间的偶数。仅适用于以太网接口。

name

字符串 / 必需

接口的全名,例如 GigabitEthernet1。

speed

字符串

接口链路速度。仅适用于以太网接口。

running_config

字符串

此选项仅与状态 parsed 一起使用。

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

状态 parsedrunning_config 选项中读取配置,并根据资源模块的参数规范将其转换为 Ansible 结构化数据,然后该值将返回到结果中的 parsed 键中。

state

字符串

模块完成后配置的状态。

选项

  • "merged" ← (默认)

  • "replaced"

  • "overridden"

  • "deleted"

  • "parsed"

  • "rendered"

  • "gathered"

备注

注意

示例

# Using merged

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

- name: Merge provided configuration with device configuration
  arista.eos.eos_interfaces:
    config:
      - name: Ethernet1
        enabled: true
        mode: layer3
      - name: Ethernet2
        description: Configured by Ansible
        enabled: false
    state: merged

# Task Output
# -----------
#
# before:
# - enabled: true
#   name: Ethernet1
# - enabled: true
#   name: Ethernet2
# - enabled: true
#   name: Management1
# commands:
# - interface Ethernet1
# - no switchport
# - interface Ethernet2
# - shutdown
# - description Configured by Ansible
# after:
# - enabled: true
#   mode: layer3
#   name: Ethernet1
# - description: Configured by Ansible
#   enabled: false
#   name: Ethernet2
# - enabled: true
#   name: Management1

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

# Using replaced

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

- name: Replaces device configuration of listed interfaces with provided configuration
  arista.eos.eos_interfaces:
    config:
      - name: Ethernet1
        enabled: true
      - name: Ethernet2
        description: Configured by Ansible
        enabled: false
    state: replaced

# Task Output
# -----------
#
# before:
# - enabled: true
#   mode: layer3
#   name: Ethernet1
# - description: Configured by Ansible
#   enabled: false
#   name: Ethernet2
# - enabled: true
#   name: Management1
# commands:
# - interface Ethernet1
# - switchport
# after:
# - enabled: true
#   name: Ethernet1
# - description: Configured by Ansible
#   enabled: false
#   name: Ethernet2
# - enabled: true
#   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 overridden

# 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: Overrides all device configuration with provided configuration
  arista.eos.eos_interfaces:
    config:
      - name: Ethernet1
        enabled: true
      - name: Ethernet2
        description: Configured by Ansible
        enabled: false
    state: overridden

# Task Output
# -----------
#
# before:
# - enabled: true
#   name: Ethernet1
# - description: Configured by Ansible
#   enabled: false
#   name: Ethernet2
# - enabled: true
#   name: Management1
# commands:
# - interface Management1
# - no shutdown
# after:
# - enabled: true
#   name: Ethernet1
# - description: Configured by Ansible
#   enabled: false
#   name: Ethernet2
# - enabled: true
#   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 deleted

# 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: Delete or return interface parameters to default settings
  arista.eos.eos_interfaces:
    config:
      - name: Ethernet1
    state: deleted

# Task Output
# -----------
#
# before:
# - enabled: true
#   name: Ethernet1
# - description: Configured by Ansible
#   enabled: false
#   name: Ethernet2
# - enabled: true
#   name: Management1
# commands:
# - interface Ethernet1
# - no shutdown
# after:
# - enabled: true
#   name: Ethernet1
# - description: Configured by Ansible
#   enabled: false
#   name: Ethernet2
# - enabled: true
#   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: Render the provided configuration into platform specific configuration lines
  arista.eos.eos_interfaces:
    config:
      - name: Ethernet1
        enabled: true
        mode: layer3
      - name: Ethernet2
        description: Configured by Ansible
        enabled: false
    state: rendered

# Module Execution Result:
# ------------------------
#
# rendered:
# - interface Ethernet1
# - no shutdown
# - no switchport
# - interface Ethernet2
# - shutdown
# - description Configured by Ansible

# Using Parsed

# File: parsed.cfg
# ----------------
#
# interface Ethernet1
#    description "Interface 1"
# !
# interface Ethernet2
#    description "Configured by Ansible"
#    shutdown
# !

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

# Module Execution Result:
# ------------------------
#
# parsed:
#  - name: Ethernet1
#    enabled: True
#    mode: layer2
#  - name: Ethernet2
#    description: 'Configured by Ansible'
#    enabled: False
#    mode: layer2

# Using Gathered

# 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: Gather interfaces facts from the device
  arista.eos.interfaces:
    state: gathered

# Module Execution Result:
# ------------------------
#
# gathered:
# - enabled: true
#   name: Ethernet1
# - description: Configured by Ansible
#   enabled: false
#   name: Ethernet2
# - enabled: true
#   name: Management1

返回值

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

描述

after

字典

模块执行后的结果配置。

返回: 当已更改时

示例: "此 输出 将始终 模块参数规范的格式相同。\n"

before

字典

模块执行之前的配置。

返回:statemergedreplacedoverriddendeletedpurged

示例: "此 输出 将始终 模块参数规范的格式相同。\n"

commands

列表 / 元素=字符串

推送到远程设备的一组命令。

返回:statemergedreplacedoverriddendeletedpurged

示例: ["interface Ethernet1", "no shutdown", "no switchport"]

gathered

列表 / 元素=字符串

以结构化数据形式从远程设备收集的网络资源的事实。

返回:stategathered

示例: ["此 输出 将始终 模块参数规范的格式相同。\n"]

parsed

列表 / 元素=字符串

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

返回:stateparsed

示例: ["此 输出 将始终 模块参数规范的格式相同。\n"]

rendered

列表 / 元素=字符串

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

返回:staterendered

示例: ["interface Ethernet1", "no shutdown", "no switchport"]

作者

  • Nathaniel Case (@Qalthos)