fix indentation errors

This commit is contained in:
Alexander Grothe 2017-06-20 16:38:38 +02:00
parent b374fe4ead
commit 8a1aa945de
4 changed files with 1778 additions and 1780 deletions

1779
Manual.org

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# This Module collects the vendor- and device ids for USB- and PCI(e)-devices and currently loaded kernel modules. # This Module collects the vendor- and device ids for USB- and PCI(e)-devices and currently loaded kernel modules.
DOCUMENTATION = ''' DOCUMENTATION = '''
--- ---
module: hardware_facts module: hardware_facts
short_description: collects facts for kernel modules, usb and pci devices short_description: collects facts for kernel modules, usb and pci devices
@ -15,112 +15,112 @@
description: description:
- return a list of vendor- and device ids for usb devices in '04x:04x' notation - return a list of vendor- and device ids for usb devices in '04x:04x' notation
pci: pci:
required: False required: False
default: True default: True
description: description:
- return a list of vendor- and device ids for pci devices in '04x:04x' notation - return a list of vendor- and device ids for pci devices in '04x:04x' notation
modules: modules:
required: False required: False
default: True default: True
description: description:
- return a list of currently loaded kernel modules - return a list of currently loaded kernel modules
gpus: gpus:
required: False required: False
default: True default: True
description: description:
- return a list of devices of the pci gpu class (0x030000) - return a list of devices of the pci gpu class (0x030000)
notes: notes:
- requres python-pyusb and python-kmodpy - requres python-pyusb and python-kmodpy
requirements: [ ] requirements: [ ]
author: "Alexander Grothe <seahawk1986@gmx.de>" author: "Alexander Grothe <seahawk1986@gmx.de>"
''' '''
EXAMPLES = ''' EXAMPLES = '''
- name: get information about usb and pci hardware and loaded kernel modules - name: get information about usb and pci hardware and loaded kernel modules
hardware_facts: hardware_facts:
usb: True usb: True
pci: True pci: True
modules: True modules: True
- debug: - debug:
var: usb var: usb
- debug - debug
var: pci var: pci
- debug - debug
var: modules var: modules
- debug - debug
var: gpus var: gpus
''' '''
import glob import glob
import json import json
import os import os
import sys import sys
import usb.core import usb.core
from collections import namedtuple from collections import namedtuple
import kmodpy import kmodpy
from ansible.module_utils.basic import * from ansible.module_utils.basic import *
PCIDevice = namedtuple("PCIDevice", 'idVendor idProduct idClass pciPath') PCIDevice = namedtuple("PCIDevice", 'idVendor idProduct idClass pciPath')
def get_pci_devices(): def get_pci_devices():
for device in glob.glob('/sys/devices/pci*/*:*:*/'): for device in glob.glob('/sys/devices/pci*/*:*:*/'):
with open(os.path.join(device, 'device')) as d: with open(os.path.join(device, 'device')) as d:
product_id = int(d.read().strip(), 16) product_id = int(d.read().strip(), 16)
with open(os.path.join(device, 'vendor')) as d: with open(os.path.join(device, 'vendor')) as d:
vendor_id = int(d.read().strip(), 16) vendor_id = int(d.read().strip(), 16)
with open(os.path.join(device, 'class')) as d: with open(os.path.join(device, 'class')) as d:
class_id = int(d.read().strip(), 16) class_id = int(d.read().strip(), 16)
yield PCIDevice(idVendor=vendor_id, idProduct=product_id, idClass=class_id, pciPath=device) yield PCIDevice(idVendor=vendor_id, idProduct=product_id, idClass=class_id, pciPath=device)
def format_device_list(iterator): def format_device_list(iterator):
return ["{:04x}:{:04x}".format(d.idVendor, d.idProduct) for d in iterator] return ["{:04x}:{:04x}".format(d.idVendor, d.idProduct) for d in iterator]
def format_gpu_device_list(iterator): def format_gpu_device_list(iterator):
def get_entries(iterator): def get_entries(iterator):
for d in iterator: for d in iterator:
if d.idClass == 0x030000: if d.idClass == 0x030000:
yield ("{:04x}:{:04x}".format(d.idVendor, d.idProduct)) yield ("{:04x}:{:04x}".format(d.idVendor, d.idProduct))
return [entry for entry in get_entries(iterator)] return [entry for entry in get_entries(iterator)]
arg_specs = { arg_specs = {
'usb': dict(default=True, type='bool', required=False), 'usb': dict(default=True, type='bool', required=False),
'pci': dict(default=True, type='bool', required=False), 'pci': dict(default=True, type='bool', required=False),
'modules': dict(default=True, type='bool', required=False), 'modules': dict(default=True, type='bool', required=False),
'gpus': dict(default=True, type='bool', required=False), 'gpus': dict(default=True, type='bool', required=False),
} }
def main(): def main():
module = AnsibleModule(argument_spec=arg_specs, supports_check_mode=True,) module = AnsibleModule(argument_spec=arg_specs, supports_check_mode=True,)
collect_usb = module.params['usb'] collect_usb = module.params['usb']
collect_pci = module.params['pci'] collect_pci = module.params['pci']
collect_modules = module.params['modules'] collect_modules = module.params['modules']
collect_gpus = module.params['gpus'] collect_gpus = module.params['gpus']
if collect_usb: if collect_usb:
usb_devices = format_device_list(usb.core.find(find_all=True)) usb_devices = format_device_list(usb.core.find(find_all=True))
else: else:
usb_device = [] usb_device = []
if collect_pci: if collect_pci:
pci_devices = format_device_list(get_pci_devices()) pci_devices = format_device_list(get_pci_devices())
else: else:
pci_devices = [] pci_devices = []
if collect_modules: if collect_modules:
k = kmodpy.Kmod() k = kmodpy.Kmod()
modules = [m[0] for m in k.loaded()] modules = [m[0] for m in k.loaded()]
else: else:
modules = [] modules = []
if collect_gpus: if collect_gpus:
gpus = format_gpu_device_list(get_pci_devices()) gpus = format_gpu_device_list(get_pci_devices())
else: else:
gpus = [] gpus = []
data = {'usb': usb_devices, 'pci': pci_devices, 'modules': modules, 'gpus': gpus} data = {'usb': usb_devices, 'pci': pci_devices, 'modules': modules, 'gpus': gpus}
module.exit_json(changed=False, ansible_facts=data, msg=data) module.exit_json(changed=False, ansible_facts=data, msg=data)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -1,16 +1,15 @@
--- ---
# file roles/autoinstall-ubuntu-drivers/tasks/main.yml # file roles/autoinstall-ubuntu-drivers/tasks/main.yml
- name: apt | install ubuntu-drivers-common
apt:
name: ubuntu-drivers-common
state: present
- name: apt | install ubuntu-drivers-common - name: ensure /etc/yavdr exists
apt: file:
name: ubuntu-drivers-common path: /etc/yavdr
state: present state: directory
mode: 0755
- name: ensure /etc/yavdr exists - name: let ubuntu-drivers automatically install additional drivers
file: command: ubuntu-drivers --package-list /etc/yavdr/autoinstalled autoinstall
path: /etc/yavdr
state: directory
mode: 0755
- name: let ubuntu-drivers automatically install additional drivers
command: ubuntu-drivers --package-list /etc/yavdr/autoinstalled autoinstall

File diff suppressed because it is too large Load Diff