community.general.usb_facts module – Allows listing information about USB devices

Note

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

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.usb_facts.

New in community.general 8.5.0

Synopsis

  • Allows retrieving information about available USB devices through lsusb.

Requirements

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

  • lsusb binary on PATH (usually installed through the package usbutils and preinstalled on many systems)

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.

Will return 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 will update existing host facts.

Examples

- name: Get information about USB devices
  community.general.usb_facts:

- name: Print information about USB devices
  ansible.builtin.debug:
    msg: "On bus {{ item.bus }} device {{ item.device }} with id {{ item.id }} is {{ item.name }}"
  loop: "{{ ansible_facts.usb_devices }}"

Returned Facts

Facts returned by this module are added/updated in the hostvars host facts and can be referenced by name just like any other host fact. They do not need to be registered in order to use them.

Key

Description

usb_devices

list / elements=dictionary

A list of USB devices available.

Returned: always

bus

string

The bus the usb device is connected to.

Returned: always

Sample: "001"

device

string

The device number occupied on the bus.

Returned: always

Sample: "002"

id

string

ID of the USB device.

Returned: always

Sample: "1d6b:0002"

name

string

Human readable name of the device.

Returned: always

Sample: "Linux Foundation 2.0 root hub"

Authors

  • Max Maxopoly (@maxopoly)