community.general.lldp_facts module – Get details reported by LLDP

Note

This module is part of the community.general collection (version 13.1.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.general. You need further requirements to be able to use this module, see Requirements for details.

To use it in a playbook, specify: community.general.lldp_facts.

Synopsis

  • Reads LLDP data from lldpd using the CLI tool lldpctl.

Aliases: lldp

Requirements

The below requirements are needed on the host that executes this module.

  • lldpctl, usually provided by the lldpd package.

  • The module was renamed from lldp to lldp_facts in community.general 13.0.0. The old name is available as an alias. Eventually a deprecation message will be shown when the old name is used.

Parameters

Parameter

Comments

multivalues

boolean

If lldpctl outputs an attribute multiple time represent all values as a list.

Choices:

  • false ← (default)

  • true

Attributes

Attribute

Support

Description

check_mode

Support: full

This action does not modify state.

Can run in check_mode and return changed status prediction without modifying target.

diff_mode

Support: N/A

This action does not modify state.

Returns details on what has changed (or possibly needs changing in check_mode), when in diff mode.

facts

Support: full

Action returns an ansible_facts dictionary that updates existing host facts.

Notes

Note

  • Requires lldpd running and LLDP enabled on switches.

Examples

# 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"}

Authors

  • Andy Hill (@andyhky)