cisco.ios.ios_lag_interfaces 模块 – 用于配置 LAG 接口的资源模块。

注意

此模块是 cisco.ios 集合(版本 9.0.3)的一部分。

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

要安装它,请使用:ansible-galaxy collection install cisco.ios

要在 playbook 中使用它,请指定:cisco.ios.ios_lag_interfaces

cisco.ios 1.0.0 中的新增功能

概要

  • 此模块管理 Cisco IOS 设备上链路聚合组的属性。

参数

参数

注释

config

列表 / 元素=字典

链路聚合组配置的列表。

members

列表 / 元素=字典

链路聚合组的接口选项。

整数

分配一个用于负载均衡的链路标识符。

有关有效值,请参阅供应商文档。

注意,该参数仅在 Cisco IOS XE 平台上支持。

member

字符串

链路聚合组的接口成员。

mode

字符串

用于链路聚合的接口的以太网通道模式。

“on” 模式必须用引号引起来,如 'on',否则 pyyaml 会在将其传递给 Ansible 之前转换为 True。

选项

  • "auto"

  • "on"

  • "desirable"

  • "active"

  • "passive"

name

字符串 / 必填

接口的以太网通道 ID。

有关有效的端口值,请参阅供应商文档。

running_config

字符串

此选项仅在 state 为 *parsed* 时使用。

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

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

state

字符串

配置应保留的状态

状态 *rendered*、*gathered* 和 *parsed* 不会对设备执行任何更改。

状态 *rendered* 会将 config 选项中的配置转换为特定于平台的 CLI 命令,这些命令将作为 *rendered* 键在结果中返回。对于状态 *rendered*,不需要与远程主机的活动连接。

状态 *gathered* 将从设备获取运行配置,并将其转换为结构化数据,格式与资源模块 argspec 相同,并且该值将作为 *gathered* 键在结果中返回。

状态 *parsed* 从 running_config 选项读取配置,并根据资源模块参数将其转换为 JSON 格式,然后该值将作为 *parsed* 键在结果中返回。running_config 选项的值应与在设备上执行命令 *show running-config | include ip route|ipv6 route* 的输出格式相同。对于状态 *parsed*,不需要与远程主机的活动连接。

选项

  • "merged" ←(默认)

  • "replaced"

  • "overridden"

  • "deleted"

  • "rendered"

  • "parsed"

  • "gathered"

注释

注意

示例

# Using merged
#
# Before state:
# -------------
#
# vios#show running-config | section ^interface
# interface Port-channel10
# interface GigabitEthernet0/1
#  shutdown
# interface GigabitEthernet0/2
#  shutdown
# interface GigabitEthernet0/3
#  shutdown
# interface GigabitEthernet0/4
#  shutdown

- name: Merge provided configuration with device configuration
  cisco.ios.ios_lag_interfaces:
    config:
      - name: Port-channel10
        members:
          - member: GigabitEthernet0/1
            mode: auto
          - member: GigabitEthernet0/2
            mode: auto
      - name: Port-channel20
        members:
          - member: GigabitEthernet0/3
            mode: "on"
      - name: Port-channel30
        members:
          - member: GigabitEthernet0/4
            mode: active
    state: merged

# Task Output:
# ---------------

# commands:
# - interface GigabitEthernet0/1
# - channel-group 10 mode auto
# - interface GigabitEthernet0/2
# - channel-group 10 mode auto
# - interface GigabitEthernet0/3
# - channel-group 20 mode on
# - interface GigabitEthernet0/4
# - channel-group 30 mode active

# After state:
# ------------
#
# vios#show running-config | section ^interface
# interface Port-channel10
# interface Port-channel20
# interface Port-channel30
# interface GigabitEthernet0/1
#  shutdown
#  channel-group 10 mode auto
# interface GigabitEthernet0/2
#  shutdown
#  channel-group 10 mode auto
# interface GigabitEthernet0/3
#  shutdown
#  channel-group 20 mode on
# interface GigabitEthernet0/4
#  shutdown
#  channel-group 30 mode active

# Using overridden
#
# Before state:
# -------------
#
# vios#show running-config | section ^interface
# interface Port-channel10
# interface Port-channel20
# interface Port-channel30
# interface GigabitEthernet0/1
#  shutdown
#  channel-group 10 mode auto
# interface GigabitEthernet0/2
#  shutdown
#  channel-group 10 mode auto
# interface GigabitEthernet0/3
#  shutdown
#  channel-group 20 mode on
# interface GigabitEthernet0/4
#  shutdown
#  channel-group 30 mode active

- name: Override device configuration of all interfaces with provided configuration
  cisco.ios.ios_lag_interfaces:
    config:
      - name: Port-channel20
        members:
          - member: GigabitEthernet0/2
            mode: auto
          - member: GigabitEthernet0/3
            mode: auto
    state: overridden

# Task Output:
# ---------------

# commands:
# - interface GigabitEthernet0/1
# - no channel-group 10 mode auto
# - interface GigabitEthernet0/2
# - no channel-group 10 mode auto
# - interface GigabitEthernet0/4
# - no channel-group 30 mode active
# - interface GigabitEthernet0/2
# - channel-group 20 mode auto
# - interface GigabitEthernet0/3
# - channel-group 20 mode auto

# After state:
# ------------
#
# vios#show running-config | section ^interface
# interface Port-channel10
# interface Port-channel20
# interface Port-channel30
# interface GigabitEthernet0/1
#  shutdown
# interface GigabitEthernet0/2
#  shutdown
#  channel-group 20 mode auto
# interface GigabitEthernet0/3
#  shutdown
#  channel-group 20 mode auto
# interface GigabitEthernet0/4
#  shutdown

# Using replaced
#
# Before state:
# -------------
#
# vios#show running-config | section ^interface
# interface Port-channel10
# interface Port-channel20
# interface Port-channel30
# interface GigabitEthernet0/1
#  shutdown
#  channel-group 10 mode auto
# interface GigabitEthernet0/2
#  shutdown
#  channel-group 10 mode auto
# interface GigabitEthernet0/3
#  shutdown
#  channel-group 20 mode on
# interface GigabitEthernet0/4
#  shutdown
#  channel-group 30 mode active

- name: Replaces device configuration of listed interfaces with provided configuration
  cisco.ios.ios_lag_interfaces:
    config:
      - name: Port-channel30
        members:
          - member: GigabitEthernet0/3
            mode: auto
    state: replaced

# Task Output:
# ---------------

# commands:
# - interface GigabitEthernet0/3
# - channel-group 30 mode auto
# - interface GigabitEthernet0/4
# - no channel-group 30 mode active

# After state:
# ------------
#
# vios#show running-config | section ^interface
# interface Port-channel10
# interface Port-channel20
# interface Port-channel30
# interface GigabitEthernet0/1
#  shutdown
#  channel-group 10 mode auto
# interface GigabitEthernet0/2
#  shutdown
#  channel-group 10 mode auto
# interface GigabitEthernet0/3
#  shutdown
#  channel-group 30 mode auto
# interface GigabitEthernet0/4
#  shutdown

# Using Deleted
#
# Before state:
# -------------
#
# vios#show running-config | section ^interface
# interface Port-channel10
# interface Port-channel20
# interface Port-channel30
# interface GigabitEthernet0/1
#  shutdown
#  channel-group 10 mode auto
# interface GigabitEthernet0/2
#  shutdown
#  channel-group 10 mode auto
# interface GigabitEthernet0/3
#  shutdown
#  channel-group 20 mode on
# interface GigabitEthernet0/4
#  shutdown
#  channel-group 30 mode active

- name: "Delete LAG attributes of given interfaces (Note: This won't delete the interface itself)"
  cisco.ios.ios_lag_interfaces:
    config:
      - name: Port-channel10
      - name: Port-channel20
    state: deleted

# Task Output:
# ---------------

# commands:
# - interface GigabitEthernet0/1
# - no channel-group 10 mode auto
# - interface GigabitEthernet0/2
# - no channel-group 10 mode auto
# - interface GigabitEthernet0/3
# - no channel-group 20 mode on

# After state:
# -------------
#
# vios#show running-config | section ^interface
# interface Port-channel10
# interface Port-channel20
# interface Port-channel30
# interface GigabitEthernet0/1
#  shutdown
# interface GigabitEthernet0/2
#  shutdown
# interface GigabitEthernet0/3
#  shutdown
# interface GigabitEthernet0/4
#  shutdown
#  channel-group 30 mode active

# Using Deleted without any config passed
# "(NOTE: This will delete all of configured LLDP module attributes)"

#
# Before state:
# -------------
#
# vios#show running-config | section ^interface
# interface Port-channel10
# interface Port-channel20
# interface Port-channel30
# interface GigabitEthernet0/1
#  shutdown
#  channel-group 10 mode auto
# interface GigabitEthernet0/2
#  shutdown
#  channel-group 10 mode auto
# interface GigabitEthernet0/3
#  shutdown
#  channel-group 20 mode on
# interface GigabitEthernet0/4
#  shutdown
#  channel-group 30 mode active

- name: "Delete all configured LAG attributes for interfaces (Note: This won't delete the interface itself)"
  cisco.ios.ios_lag_interfaces:
    state: deleted

# Task Output:
# ---------------

# commands:
# - interface GigabitEthernet0/1
# - no channel-group 10 mode auto
# - interface GigabitEthernet0/2
# - no channel-group 10 mode auto
# - interface GigabitEthernet0/3
# - no channel-group 20 mode on
# - interface GigabitEthernet0/4
# - no channel-group 30 mode active

# After state:
# -------------
#
# vios#show running-config | section ^interface
# interface Port-channel10
# interface Port-channel20
# interface Port-channel30
# interface GigabitEthernet0/1
#  shutdown
# interface GigabitEthernet0/2
#  shutdown
# interface GigabitEthernet0/3
#  shutdown
# interface GigabitEthernet0/4
#  shutdown

# Using Gathered

# Before state:
# -------------
#
# vios#show running-config | section ^interface
# interface Port-channel10
# interface Port-channel20
# interface Port-channel30
# interface GigabitEthernet0/1
#   shutdown
#   channel-group 10 mode auto
# interface GigabitEthernet0/2
#   shutdown
#   channel-group 10 mode auto
# interface GigabitEthernet0/3
#   shutdown
#   channel-group 20 mode on
# interface GigabitEthernet0/4
#   shutdown
#   channel-group 30 mode active

- name: Gather listed LAG interfaces with provided configurations
  cisco.ios.ios_lag_interfaces:
    config:
    state: gathered

# Module Execution Result:
# ------------------------
#
# "gathered": [
# {
#     "members": [
#         {
#             "member": "GigabitEthernet0/1",
#             "mode": "auto"
#         },
#         {
#             "member": "GigabitEthernet0/2",
#             "mode": "auto"
#         }
#     ],
#     "name": "Port-channel10"
# },
# {
#     "members": [
#         {
#             "member": "GigabitEthernet0/3",
#             "mode": "on"
#         }
#     ],
#     "name": "Port-channel20"
# },
# {
#     "members": [
#         {
#             "member": "GigabitEthernet0/4",
#             "mode": "active"
#         }
#     ],
#     "name": "Port-channel30"
# }
# ]

# After state:
# ------------
#
# vios#sh running-config | section ^interface
# interface Port-channel10
# interface Port-channel20
# interface Port-channel30
# interface GigabitEthernet0/1
#   shutdown
#   channel-group 10 mode auto
# interface GigabitEthernet0/2
#   shutdown
#   channel-group 10 mode auto
# interface GigabitEthernet0/3
#   shutdown
#   channel-group 20 mode on
# interface GigabitEthernet0/4
#   shutdown
#   channel-group 30 mode active

# Using Rendered

- name: Render the commands for provided  configuration
  cisco.ios.ios_lag_interfaces:
    config:
      - name: Port-channel11
        members:
          - member: GigabitEthernet0/1
            mode: active
      - name: Port-channel22
        members:
          - member: GigabitEthernet0/2
            mode: passive
    state: rendered

# Module Execution Result:
# ------------------------
#
# "rendered": [
#         "interface GigabitEthernet0/1",
#         "channel-group 11 mode active",
#         "interface GigabitEthernet0/2",
#         "channel-group 22 mode passive",
#     ]

# Using Parsed

#  File: parsed.cfg
# ----------------
#
# interface GigabitEthernet0/1
# channel-group 11 mode active
# interface GigabitEthernet0/2
# channel-group 22 mode passive

- name: Parse the commands for provided configuration
  cisco.ios.ios_lag_interfaces:
    running_config: "{{ lookup('file', 'parsed.cfg') }}"
    state: parsed

# Module Execution Result:
# ------------------------
#
# "parsed": [
#     {
#         "members": [
#             {
#                 "member": "GigabitEthernet0/1",
#                 "mode": "active"
#             }
#         ],
#         "name": "Port-channel11"
#     },
#     {
#         "members": [
#             {
#                 "member": "GigabitEthernet0/2",
#                 "mode": "passive"
#             }
#         ],
#         "name": "Port-channel22"
#     }
# ]

返回值

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

描述

after

字典

模块执行后的结果配置。

返回: 当更改时

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

before

字典

模块执行之前的配置。

返回:statemerged, replaced, overridden, deletedpurged

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

commands

列表 / 元素=字符串

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

返回:statemerged, replaced, overridden, deletedpurged

示例: ["interface GigabitEthernet0/1", "channel-group 10 mode auto", "channel-group 10 mode active link 20"]

gathered

列表 / 元素=字符串

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

返回:stategathered

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

已解析

列表 / 元素=字符串

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

返回值:stateparsed

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

已渲染

列表 / 元素=字符串

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

返回值:staterendered

示例: ["interface GigabitEthernet0/2", "channel-group 20 mode auto", "channel-group 20 mode active link 60"]

作者

  • Sagar Paul (@KB-perByte)

  • Sumit Jaiswal (@justjais)