
    Vh                     b    d dl mZmZmZ eZdZdZdZd dl	Z	d dl
mZ d Zd Zed	k(  r e        yy)
    )absolute_importdivisionprint_functiona  
module: usb_facts
short_description: Allows listing information about USB devices
version_added: 8.5.0
description:
  - Allows retrieving information about available USB devices through C(lsusb).
author:
  - Max Maxopoly (@maxopoly)
extends_documentation_fragment:
  - community.general.attributes
  - community.general.attributes.facts
  - community.general.attributes.facts_module
requirements:
  - lsusb binary on PATH (usually installed through the package usbutils and preinstalled on many systems)
a  
- 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 }}"
aj  
ansible_facts:
  description: Dictionary containing details of connected USB devices.
  returned: always
  type: dict
  contains:
    usb_devices:
      description: A list of USB devices available.
      returned: always
      type: list
      elements: dict
      contains:
        bus:
          description: The bus the usb device is connected to.
          returned: always
          type: str
          sample: "001"
        device:
          description: The device number occupied on the bus.
          returned: always
          type: str
          sample: "002"
        id:
          description: ID of the USB device.
          returned: always
          type: str
          sample: "1d6b:0002"
        name:
          description: Human readable name of the device.
          returned: always
          type: str
          sample: Linux Foundation 2.0 root hub
N)AnsibleModulec                    | j                  |d      \  }}}t        j                  d      }g }|j                         D ]  }t        j                  ||      }|s| j                  d|z  ||       |j                  d      |j                  d      |j                  d      |j                  d	      d
}	|j                  |	        d|i}
| j                  dt        |      z  |||
       y )NT)check_rcz?^Bus (\d{3}) Device (\d{3}): ID ([0-9a-f]{4}:[0-9a-f]{4}) (.*)$z'failed to parse unknown lsusb output %s)msgstdoutstderr            )busdeviceidnameusb_deviceszparsed %s USB devices)r	   r
   r   ansible_facts)
run_commandrecompile
splitlinesmatch	fail_jsongroupappend	exit_jsonlen)module
lsusb_pathrcr
   r   regexr   liner   current_devicereturn_values              o/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/usb_facts.pyparse_lsusbr(   M   s    ++J+FBJJYZEK!!# 
+%!Jd!S\bkqr;;q>kk!n++a.KKN	
 	>*
+ 	{L 0C4DEf]cs  A    c                      t        i d      } t        dd      | _        | j                  dd      }t	        | |       y )NT)supports_check_modeC)LANGUAGELC_ALLlsusb)required)r   dictrun_command_environ_updateget_bin_pathr(   )r    r!   s     r'   mainr4   b   sB    
 F )-c#(FF%$$Wt$<J
#r)   __main__)
__future__r   r   r   type__metaclass__DOCUMENTATIONEXAMPLESRETURNr   ansible.module_utils.basicr   r(   r4   __name__ r)   r'   <module>r?      sP    A @  
D 
 4A*
$ zF r)   