Fix shebang
This commit is contained in:
parent
9d9ac03f5d
commit
5035437aa2
@ -5515,7 +5515,7 @@ fi
|
|||||||
* Modules
|
* Modules
|
||||||
This section contains custom modules for the yaVDR Playbooks. They are used to collect facts about the system and configure applications and daemons.
|
This section contains custom modules for the yaVDR Playbooks. They are used to collect facts about the system and configure applications and daemons.
|
||||||
** hardware_facts.py
|
** hardware_facts.py
|
||||||
#+BEGIN_SRC python :tangle library/hardware_facts.py :shebang #!/usr/bin/env/python
|
#+BEGIN_SRC python :tangle library/hardware_facts.py :shebang "#!/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 = '''
|
||||||
---
|
---
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/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 = '''
|
||||||
---
|
---
|
||||||
|
69
library/pci_facts.py
Executable file
69
library/pci_facts.py
Executable file
@ -0,0 +1,69 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# This module parses the output of lspci for detailed information about available (sub) devices.
|
||||||
|
DOCUMENTATION = '''
|
||||||
|
---
|
||||||
|
module: pci_facts
|
||||||
|
short_description: parses lspci output for detailed (sub) devices data
|
||||||
|
description:
|
||||||
|
- This module parses the output of lspci for detailed information about available (sub) devices.
|
||||||
|
- returns a list with a dict for each device
|
||||||
|
|
||||||
|
notes:
|
||||||
|
- requires lspci (package pciutils)
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
EXAMPLES = '''
|
||||||
|
- name: get detailled pci device infos
|
||||||
|
pci_facts:
|
||||||
|
|
||||||
|
- debug:
|
||||||
|
var: pci_devices
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import shlex
|
||||||
|
import subprocess
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
|
from ansible.module_utils.basic import *
|
||||||
|
|
||||||
|
def convert2hex(arg):
|
||||||
|
arg = arg.strip('"')
|
||||||
|
if arg:
|
||||||
|
return int(arg, 16)
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def parse_lspci_data():
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('-r', '--revision', help='revision', type=convert2hex)
|
||||||
|
parser.add_argument('-p', '--progif', help='proginf', type=convert2hex)
|
||||||
|
parser.add_argument('slot')
|
||||||
|
parser.add_argument('device_class', type=convert2hex)
|
||||||
|
parser.add_argument('vendor_id', type=convert2hex)
|
||||||
|
parser.add_argument('device_id', type=convert2hex)
|
||||||
|
parser.add_argument('sub_vendor_id', type=convert2hex)
|
||||||
|
parser.add_argument('sub_device_id', type=convert2hex)
|
||||||
|
parser.add_argument('other', nargs='*', default=[])
|
||||||
|
|
||||||
|
devices = []
|
||||||
|
for line in subprocess.check_output(['lspci', '-nm'], universal_newlines=True).splitlines():
|
||||||
|
args = parser.parse_args(args=shlex.split(line))
|
||||||
|
devices.append(vars(args))
|
||||||
|
return devices
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
arg_specs = {}
|
||||||
|
module = AnsibleModule(argument_spec=arg_specs, supports_check_mode=True,)
|
||||||
|
try:
|
||||||
|
pci_devices = parse_lspci_data()
|
||||||
|
except:
|
||||||
|
module.fail_json(msg="Something fatal happened")
|
||||||
|
data = {'pci_devices': pci_devices}
|
||||||
|
module.exit_json(changed=False, ansible_facts=data, msg=data)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
Loading…
Reference in New Issue
Block a user