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_ 一起使用。

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

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

字典

模块执行后的结果配置。

返回:发生更改时

示例: "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 GigabitEthernet0/1", "channel-group 10 mode auto", "channel-group 10 mode active link 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"]

rendered

列表 / 元素=字符串

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

返回值:状态rendered

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

作者

  • Sagar Paul (@KB-perByte)

  • Sumit Jaiswal (@justjais)