Created
March 18, 2021 21:52
-
-
Save kbabioch/fbf329724509aae6e3674cf5b32bea8c to your computer and use it in GitHub Desktop.
Custom Ansible module to collection hardware-specific information about a Enigma2-based receiver (based on boxbranding from OE-Alliance).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# Copyright (c) 2021 Karol Babioch <[email protected]> | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
from __future__ import (absolute_import, division, print_function) | |
__metaclass__ = type | |
import sys | |
sys.path.append('/usr/lib/enigma2/python') | |
try: | |
from boxbranding import getImageArch, getOEVersion | |
BOX_ARCH = getImageArch() | |
BOX_OEVER = getOEVersion().replace('OE-Alliance ', '') | |
except: | |
pass | |
DOCUMENTATION = r''' | |
--- | |
module: oea-box-info | |
short_description: Returns information about the Enigma2-based (OE Alliance) receivers and its base image (e.g. architecture, version, etc.). | |
description: This module collects basic information about Enigma2-based boxes and the base image being used. The collected information includes details about the hardware architecture/platform and the base version being used. It works under the assumption that there is a `boxbranding` Python module in `/usr/lib/enigma2/python`, which should be the case for any OE-Alliance based image. | |
author: | |
- Karol Babioch ([email protected]) | |
''' | |
EXAMPLES = r''' | |
- name: collect information about receiver | |
oea-box-info: | |
''' | |
RETURN = r''' | |
ansible_facts: | |
description: Facts to be added to ansible_facts | |
returned: always | |
type: dict | |
contains: | |
box_arch: | |
description: Architecture of box | |
type: str | |
returned: always | |
sample: 'mips32el' | |
box_oever: | |
description: Base version of image | |
type: str | |
returned: always | |
sample: '4.4' | |
''' | |
from ansible.module_utils.basic import AnsibleModule | |
def run_module(): | |
module_args = dict() | |
result = dict(changed=False, ansible_facts=dict()) | |
if BOX_ARCH: | |
result['ansible_facts']['box_arch'] = BOX_ARCH | |
if BOX_OEVER: | |
result['ansible_facts']['box_oever'] = BOX_OEVER | |
module = AnsibleModule( | |
argument_spec=module_args, | |
supports_check_mode=True | |
) | |
module.exit_json(**result) | |
def main(): | |
run_module() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment