community.general.lldp 模块 – 获取 lldp 报告的详细信息

注意

此模块是 community.general 集合 (版本 10.1.0) 的一部分。

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

要安装它,请使用:ansible-galaxy collection install community.general。您需要其他要求才能使用此模块,请参阅 需求了解详细信息。

要在 playbook 中使用它,请指定:community.general.lldp

概要

  • 读取 lldpctl 中的数据

需求

在执行此模块的主机上需要以下需求。

  • lldpctl

属性

属性

支持

描述

check_mode

支持:不支持

可以在 check_mode 下运行并返回更改状态预测,而无需修改目标。

diff_mode

支持:不支持

处于 diff 模式时,将返回有关已更改内容(或可能需要在 check_mode 中更改的内容)的详细信息。

备注

注意

  • 需要在交换机上运行 lldpd 并启用 lldp

示例

# Retrieve switch/port information
 - name: Gather information from lldp
   community.general.lldp:

 - name: Print each switch/port
   ansible.builtin.debug:
    msg: "{{ lldp[item]['chassis']['name'] }} / {{ lldp[item]['port']['ifname'] }}"
   with_items: "{{ lldp.keys() }}"

# TASK: [Print each switch/port] ***********************************************************
# ok: [10.13.0.22] => (item=eth2) => {"item": "eth2", "msg": "switch1.example.com / Gi0/24"}
# ok: [10.13.0.22] => (item=eth1) => {"item": "eth1", "msg": "switch2.example.com / Gi0/3"}
# ok: [10.13.0.22] => (item=eth0) => {"item": "eth0", "msg": "switch3.example.com / Gi0/3"}

作者

  • Andy Hill (@andyhky)