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

注意

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

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

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

要在 Playbook 中使用它,请指定:cisco.ios.ios_lldp_interfaces

cisco.ios 1.0.0 中的新功能

概要

  • 此模块管理 Cisco IOS 设备上接口的链路层发现协议 (LLDP) 属性。

参数

参数

注释

config

列表 / 元素=字典

LLDP 选项的字典

med_tlv_select

字典

要发送的 LLDP MED TLV 的选择

注意,如果配置了 med-tlv-select,则不会保持幂等性,因为 Cisco 设备不会记录配置的 med-tlv-select 选项。因此,Ansible 无法从设备端验证是否已配置相应的 med-tlv-select 选项。如果您尝试在每次运行中应用 med-tlv-select 选项,Ansible 将显示 changed 为 True。

inventory_management

布尔值

LLDP MED 库存管理 TLV

选择

  • false

  • true

name

字符串 / 必需

接口的全名,不包括任何逻辑单元号,例如 GigabitEthernet0/1。

receive

布尔值

在接口上启用 LLDP 接收。

选择

  • false

  • true

tlv_select

字典

要发送的 LLDP 类型-长度-值,即 TLV 的选择

注意,如果配置了 tlv-select,则不会保持幂等性,因为 Cisco 设备不会记录配置的 tlv-select 选项。因此,Ansible 无法从设备端验证是否已配置相应的 tlv-select 选项。如果您尝试在每次运行中应用 tlv-select 选项,Ansible 将显示 changed 为 True。

power_management

布尔值

通过 MDI TLV 的 IEEE 802.3 DTE 电源

选择

  • false

  • true

transmit

布尔值

在接口上启用 LLDP 传输。

选择

  • false

  • true

running_config

字符串

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

此选项的值应该是通过执行命令 **sh lldp interface** 从 IOS 设备收到的输出。

状态 *parsed* 从 running_config 选项读取配置,并将其转换为 Ansible 结构化数据,格式符合资源模块的 argspec,然后该值将返回到结果中的 *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"

  • "gathered"

  • "parsed"

注释

注意

示例

# Using merged
#
# Before state:
# -------------
#
# vios#sh lldp interface
# GigabitEthernet0/0:
#    Tx: enabled
#    Rx: disabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME
#
# GigabitEthernet0/1:
#    Tx: disabled
#    Rx: disabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME
#
# GigabitEthernet0/2:
#    Tx: disabled
#    Rx: disabled
#    Tx state: IDLE
#    Rx state: INIT
#
# GigabitEthernet0/3:
#    Tx: enabled
#    Rx: enabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME
#

- name: Merge provided configuration with device configuration
  cisco.ios.ios_lldp_interfaces:
    config:
      - name: GigabitEthernet0/1
        receive: true
        transmit: true
      - name: GigabitEthernet0/2
        receive: true
      - name: GigabitEthernet0/3
        transmit: true
    state: merged

# After state:
# ------------
#
# vios#sh lldp interface
# GigabitEthernet0/0:
#    Tx: enabled
#    Rx: disabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME
#
# GigabitEthernet0/1:
#    Tx: enabled
#    Rx: enabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME
#
# GigabitEthernet0/2:
#    Tx: disabled
#    Rx: enabled
#    Tx state: IDLE
#    Rx state: INIT
#
# GigabitEthernet0/3:
#    Tx: enabled
#    Rx: disabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME
#

# Using overridden
#
# Before state:
# -------------
#
# vios#sh lldp interface
# GigabitEthernet0/0:
#    Tx: enabled
#    Rx: enabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME
#
# GigabitEthernet0/1:
#    Tx: enabled
#    Rx: enabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME
#
# GigabitEthernet0/2:
#    Tx: disabled
#    Rx: disabled
#    Tx state: IDLE
#    Rx state: INIT
#
# GigabitEthernet0/3:
#    Tx: enabled
#    Rx: enabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME

- name: Override device configuration of all lldp_interfaces with provided configuration
  cisco.ios.ios_lldp_interfaces:
    config:
      - name: GigabitEthernet0/2
        receive: true
        transmit: true
    state: overridden

# After state:
# ------------
#
# vios#sh lldp interface
# GigabitEthernet0/0:
#    Tx: disabled
#    Rx: disabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME
#
# GigabitEthernet0/1:
#    Tx: disabled
#    Rx: disabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME
#
# GigabitEthernet0/2:
#    Tx: enabled
#    Rx: enabled
#    Tx state: IDLE
#    Rx state: INIT
#
# GigabitEthernet0/3:
#    Tx: disabled
#    Rx: disabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME

# Using replaced
#
# Before state:
# -------------
#
# vios#sh lldp interface
# GigabitEthernet0/0:
#    Tx: enabled
#    Rx: enabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME
#
# GigabitEthernet0/1:
#    Tx: enabled
#    Rx: enabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME
#
# GigabitEthernet0/2:
#    Tx: disabled
#    Rx: disabled
#    Tx state: IDLE
#    Rx state: INIT
#
# GigabitEthernet0/3:
#    Tx: enabled
#    Rx: enabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME
#

- name: Replaces device configuration of listed lldp_interfaces with provided configuration
  cisco.ios.ios_lldp_interfaces:
    config:
      - name: GigabitEthernet0/2
        receive: true
        transmit: true
      - name: GigabitEthernet0/3
        receive: true
    state: replaced

# After state:
# ------------
#
# vios#sh lldp interface
# GigabitEthernet0/0:
#    Tx: enabled
#    Rx: enabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME
#
# GigabitEthernet0/1:
#    Tx: enabled
#    Rx: enabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME
#
# GigabitEthernet0/2:
#    Tx: enabled
#    Rx: enabled
#    Tx state: IDLE
#    Rx state: INIT
#
# GigabitEthernet0/3:
#    Tx: disabled
#    Rx: enabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME
#

# Using Deleted
#
# Before state:
# -------------
#
# vios#sh lldp interface
# GigabitEthernet0/0:
#    Tx: enabled
#    Rx: enabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME
#
# GigabitEthernet0/1:
#    Tx: enabled
#    Rx: enabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME
#
# GigabitEthernet0/2:
#    Tx: disabled
#    Rx: disabled
#    Tx state: IDLE
#    Rx state: INIT
#
# GigabitEthernet0/3:
#    Tx: enabled
#    Rx: enabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME

- name: "Delete LLDP attributes of given interfaces (Note: This won't delete the interface itself)"
  cisco.ios.ios_lldp_interfaces:
    config:
      - name: GigabitEthernet0/1
    state: deleted

# After state:
# -------------
#
# vios#sh lldp interface
# GigabitEthernet0/0:
#    Tx: enabled
#    Rx: enabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME
#
# GigabitEthernet0/1:
#    Tx: disabled
#    Rx: disabled
#    Tx state: IDLE
#    Rx state: INIT
#
# GigabitEthernet0/2:
#    Tx: disabled
#    Rx: disabled
#    Tx state: IDLE
#    Rx state: INIT
#
# GigabitEthernet0/3:
#    Tx: enabled
#    Rx: enabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME
#

# Using Deleted without any config passed
# "(NOTE: This will delete all of configured LLDP module attributes)"
#
# Before state:
# -------------
#
# vios#sh lldp interface
# GigabitEthernet0/0:
#    Tx: enabled
#    Rx: enabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME
#
# GigabitEthernet0/1:
#    Tx: enabled
#    Rx: enabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME
#
# GigabitEthernet0/2:
#    Tx: disabled
#    Rx: disabled
#    Tx state: IDLE
#    Rx state: INIT
#
# GigabitEthernet0/3:
#    Tx: enabled
#    Rx: enabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME

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

# After state:
# -------------
#
# vios#sh lldp interface
# GigabitEthernet0/0:
#    Tx: disabled
#    Rx: disabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME
#
# GigabitEthernet0/1:
#    Tx: disabled
#    Rx: disabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME
#
# GigabitEthernet0/2:
#    Tx: disabled
#    Rx: disabled
#    Tx state: IDLE
#    Rx state: INIT
#
# GigabitEthernet0/3:
#    Tx: disabled
#    Rx: disabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME

# Using Gathered

# Before state:
# -------------
#
# vios#sh lldp interface
# GigabitEthernet0/0:
#    Tx: enabled
#    Rx: enabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME
#
# GigabitEthernet0/1:
#    Tx: enabled
#    Rx: enabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME
#
# GigabitEthernet0/2:
#    Tx: enabled
#    Rx: enabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME

- name: Gather listed LLDP interfaces with provided configurations
  cisco.ios.ios_lldp_interfaces:
    config:
    state: gathered

# Module Execution Result:
# ------------------------
#
# "gathered": [
#         {
#             "name": "GigabitEthernet0/0",
#             "receive": true,
#             "transmit": true
#         },
#         {
#             "name": "GigabitEthernet0/1",
#             "receive": true,
#             "transmit": true
#         },
#         {
#             "name": "GigabitEthernet0/2",
#             "receive": true,
#             "transmit": true
#         }
#     ]

# After state:
# ------------
#
# vios#sh lldp interface
# GigabitEthernet0/0:
#    Tx: enabled
#    Rx: enabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME
#
# GigabitEthernet0/1:
#    Tx: enabled
#    Rx: enabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME

# GigabitEthernet0/2:
#    Tx: enabled
#    Rx: enabled
#    Tx state: IDLE
#    Rx state: WAIT FOR FRAME

# Using Rendered

- name: Render the commands for provided  configuration
  cisco.ios.ios_lldp_interfaces:
    config:
      - name: GigabitEthernet0/0
        receive: true
        transmit: true
      - name: GigabitEthernet0/1
        receive: true
        transmit: true
      - name: GigabitEthernet0/2
        receive: true
    state: rendered

# Module Execution Result:
# ------------------------
#
# "rendered": [
#         "interface GigabitEthernet0/0",
#         "lldp receive",
#         "lldp transmit",
#         "interface GigabitEthernet0/1",
#         "lldp receive",
#         "lldp transmit",
#         "interface GigabitEthernet0/2",
#         "lldp receive"
#     ]

# Using Parsed

# File: parsed.cfg
# ----------------
#
# GigabitEthernet0/0:
#   Tx: enabled
#   Rx: disabled
#   Tx state: IDLE
#   Rx state: WAIT FOR FRAME
#
# GigabitEthernet0/1:
#   Tx: enabled
#   Rx: enabled
#   Tx state: IDLE
#   Rx state: WAIT FOR FRAME
#
# GigabitEthernet0/2:
#   Tx: disabled
#   Rx: enabled
#   Tx state: IDLE
#   Rx state: INIT

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

# Module Execution Result:
# ------------------------
#
# "parsed": [
#         {
#             "name": "GigabitEthernet0/0",
#             "receive": false,
#             "transmit": true
#         },
#         {
#             "name": "GigabitEthernet0/1",
#             "receive": true,
#             "transmit": true
#         },
#         {
#             "name": "GigabitEthernet0/2",
#             "receive": true,
#             "transmit": false
#         }
#     ]

返回值

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

描述

after

列表 / 元素=字符串

模块完成后,以结构化数据形式呈现的配置。

返回: 当发生更改时

示例: ["返回的 配置 始终 上方 参数的 格式 相同。\n"]

之前

列表 / 元素=字符串

模块调用前,以结构化数据形式呈现的配置。

返回: 始终

示例: ["返回的 配置 始终 上方 参数的 格式 相同。\n"]

命令

列表 / 元素=字符串

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

返回: 始终

示例: ["interface GigabitEthernet 0/1", "lldp transmit", "lldp receive"]

作者

  • Sumit Jaiswal (@justjais)