Skip to content

Instantly share code, notes, and snippets.

@kbabioch
Created March 18, 2021 21:52

Revisions

  1. kbabioch created this gist Mar 18, 2021.
    90 changes: 90 additions & 0 deletions oea-box-info.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,90 @@
    #! /usr/bin/env python

    # Copyright (c) 2021 Karol Babioch <karol@babioch.de>

    # 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 (karol@babioch.de)
    '''

    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()