You've already forked ansible-collection-armbian
mirror of
https://github.com/armbian/ansible-collection-armbian.git
synced 2026-01-06 10:33:37 -08:00
import Sam Doran work
This commit is contained in:
82
README.md
82
README.md
@@ -1,3 +1,81 @@
|
||||
# Ansible Collection - armbian.armbian
|
||||
[](https://galaxy.ansible.com/armbian/armbian)
|
||||
|
||||
Documentation for the collection.
|
||||
|
||||
This collection contains a module for gathering facts on [Armbian](https://www.armbian.com). More Armbian related things may be added in the future.
|
||||
|
||||
**Ansible 2.9 and later is required.**
|
||||
|
||||
The module parses `/etc/armbian-release` and stores the result in `ansible_facts.armbian`. Here is an example:
|
||||
|
||||
```
|
||||
"ansible_facts": {
|
||||
"armbian": {
|
||||
"arch": "arm",
|
||||
"board": "orangepiplus2e",
|
||||
"board_family": "sun8i",
|
||||
"board_name": "Orange Pi+ 2E",
|
||||
"board_type": "conf",
|
||||
"branch": "current",
|
||||
"build_repository_commit": "e6fa811d-dirty",
|
||||
"build_repository_url": "https://github.com/armbian/build",
|
||||
"distribution_codename": "buster",
|
||||
"distribution_status": "supported",
|
||||
"image_type": "stable",
|
||||
"initrd_arch": "arm",
|
||||
"kernel_image_type": "Image",
|
||||
"linux_family": "sunxi",
|
||||
"version": "20.08.1"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If `/etc/armbian-release` is not available `ansible_facts.armbian` will be an empty dictionary. It is safe to run this on non-Armbian hosts without causing your playbook to fail. See `ansible-doc armbian.armbian.armbian_facts` for more details.
|
||||
|
||||
### Installation ###
|
||||
|
||||
`ansible-galaxy collection install armbian.armbian`
|
||||
|
||||
### Usage ###
|
||||
|
||||
This module can either be called explicitly by a task or added to the list of [`FACTS_MODULES`](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#facts-modules) that run automatically during the fact gathering stage.
|
||||
|
||||
#### Adding to the default Facts Modules ####
|
||||
|
||||
Add the module to the configuration:
|
||||
|
||||
```ini
|
||||
[default]
|
||||
facts_modules = armbian.armbian.armbian_facts
|
||||
```
|
||||
|
||||
This means that any time fact gathering is run, `armbian_facts` will be run in addition to the default fact gathering. This can be done in a playbook:
|
||||
|
||||
```yaml
|
||||
- hosts: armbian
|
||||
gather_facts: yes
|
||||
```
|
||||
|
||||
Or ad hoc:
|
||||
|
||||
```
|
||||
ansible all -m armbian.armbian.armbian_facts
|
||||
ansible all -m gather_facts
|
||||
```
|
||||
|
||||
#### Explicit Task ####
|
||||
|
||||
You can call the module at any time using a task. Since this is a facts module, there is no need to register the output. The returned facts will automatically be set for the host. If fact caching is enabled, the gathered facts will be cached.
|
||||
|
||||
```
|
||||
- hosts: armbian
|
||||
gather_facts: yes
|
||||
|
||||
tasks:
|
||||
- name: Gather Armbian facts
|
||||
armbian.armbian.armbian_facts
|
||||
```
|
||||
|
||||
|
||||
### Modules in this Collection ###
|
||||
|
||||
- `armbian.armbian.armbian_facts` - Gather facts about Armbian.
|
||||
|
||||
63
galaxy.yml
63
galaxy.yml
@@ -1,62 +1,27 @@
|
||||
### REQUIRED
|
||||
# The namespace of the collection. This can be a company/brand/organization or product namespace under which all
|
||||
# content lives. May only contain alphanumeric lowercase characters and underscores. Namespaces cannot start with
|
||||
# underscores or numbers and cannot contain consecutive underscores
|
||||
namespace: armbian
|
||||
|
||||
# The name of the collection. Has the same character restrictions as 'namespace'
|
||||
name: armbian
|
||||
|
||||
# The version of the collection. Must be compatible with semantic versioning
|
||||
version: 1.0.0
|
||||
|
||||
# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
|
||||
version: 1.0.3
|
||||
readme: README.md
|
||||
|
||||
# A list of the collection's content authors. Can be just the name or in the format 'Full Name <email> (url)
|
||||
# @nicks:irc/im.site#channel'
|
||||
authors:
|
||||
- your name <example@domain.com>
|
||||
- Sam Doran <sdoran@redhat.com>
|
||||
- Lane Jennion <lane@lane-fu.com>
|
||||
|
||||
description: Modules for Armbian.
|
||||
|
||||
### OPTIONAL but strongly recommended
|
||||
# A short summary description of the collection
|
||||
description: your collection description
|
||||
|
||||
# Either a single license or a list of licenses for content inside of a collection. Ansible Galaxy currently only
|
||||
# accepts L(SPDX,https://spdx.org/licenses/) licenses. This key is mutually exclusive with 'license_file'
|
||||
license:
|
||||
- GPL-2.0-or-later
|
||||
- GPL-2.0-or-later
|
||||
|
||||
# The path to the license file for the collection. This path is relative to the root of the collection. This key is
|
||||
# mutually exclusive with 'license'
|
||||
license_file: ''
|
||||
tags:
|
||||
- development
|
||||
- system
|
||||
- debian
|
||||
- armbian
|
||||
|
||||
# A list of tags you want to associate with the collection for indexing/searching. A tag name has the same character
|
||||
# requirements as 'namespace' and 'name'
|
||||
tags: []
|
||||
|
||||
# Collections that this collection requires to be installed for it to be usable. The key of the dict is the
|
||||
# collection label 'namespace.name'. The value is a version range
|
||||
# L(specifiers,https://python-semanticversion.readthedocs.io/en/latest/#requirement-specification). Multiple version
|
||||
# range specifiers can be set and are separated by ','
|
||||
dependencies: {}
|
||||
|
||||
# The URL of the originating SCM repository
|
||||
repository: http://example.com/repository
|
||||
repository: http://github.com/armbian/ansible-collection-armbian
|
||||
documentation: http://github.com/armbian/ansible-collection-armbian/README.md
|
||||
homepage: http://github.com/armbian/ansible-collection-armbian
|
||||
issues: http://github.com/armbian/ansible-collection-armbian/issues
|
||||
|
||||
# The URL to any online docs
|
||||
documentation: http://docs.example.com
|
||||
|
||||
# The URL to the homepage of the collection/project
|
||||
homepage: http://example.com
|
||||
|
||||
# The URL to the collection issue tracker
|
||||
issues: http://example.com/issue/tracker
|
||||
|
||||
# A list of file glob-like patterns used to filter any files or directories that should not be included in the build
|
||||
# artifact. A pattern is matched from the relative path of the file or directory of the collection directory. This
|
||||
# uses 'fnmatch' to match the files or directories. Some directories and files like 'galaxy.yml', '*.pyc', '*.retry',
|
||||
# and '.git' are always filtered
|
||||
build_ignore: []
|
||||
|
||||
|
||||
31
plugins/README.md
Normal file
31
plugins/README.md
Normal file
@@ -0,0 +1,31 @@
|
||||
# Collections Plugins Directory
|
||||
|
||||
This directory can be used to ship various plugins inside an Ansible collection. Each plugin is placed in a folder that
|
||||
is named after the type of plugin it is in. It can also include the `module_utils` and `modules` directory that
|
||||
would contain module utils and modules respectively.
|
||||
|
||||
Here is an example directory of the majority of plugins currently supported by Ansible:
|
||||
|
||||
```
|
||||
└── plugins
|
||||
├── action
|
||||
├── become
|
||||
├── cache
|
||||
├── callback
|
||||
├── cliconf
|
||||
├── connection
|
||||
├── filter
|
||||
├── httpapi
|
||||
├── inventory
|
||||
├── lookup
|
||||
├── module_utils
|
||||
├── modules
|
||||
├── netconf
|
||||
├── shell
|
||||
├── strategy
|
||||
├── terminal
|
||||
├── test
|
||||
└── vars
|
||||
```
|
||||
|
||||
A full list of plugin types can be found at [Working With Plugins](https://docs.ansible.com/ansible/2.10/plugins/plugins.html).
|
||||
164
plugins/modules/armbian_facts.py
Normal file
164
plugins/modules/armbian_facts.py
Normal file
@@ -0,0 +1,164 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2020 Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
DOCUMENTATION = """
|
||||
---
|
||||
module: Armbian Facts
|
||||
author:
|
||||
- Sam Doran (@samdoran)
|
||||
version_added: '1.0.0'
|
||||
short_description: Collect facts about Armbian
|
||||
notes: []
|
||||
description:
|
||||
- Gather detailed facts about Armbian from C(/etc/armbian-release). If facts are unable to be gathered,
|
||||
an empty dictionary is returned. This can be run safelay against non-Armbian hosts.
|
||||
- This module can be added to the default list of C(FACTS_MODULES).
|
||||
|
||||
options: {}
|
||||
"""
|
||||
|
||||
EXAMPLES = """
|
||||
- armbian_facts:
|
||||
"""
|
||||
|
||||
RETURN = """
|
||||
armbian:
|
||||
description: Main key containing the Armbian facts. Empty if parsing failed.
|
||||
returned: always
|
||||
type: complex
|
||||
contains:
|
||||
arch:
|
||||
description: Architecture
|
||||
returned: success
|
||||
type: str
|
||||
sample: "arm"
|
||||
board:
|
||||
description: Board
|
||||
returned: success
|
||||
type: str
|
||||
sample: "helios4"
|
||||
board_name:
|
||||
description: Board name
|
||||
returned: success
|
||||
type: str
|
||||
sample: "Helios4"
|
||||
board_type:
|
||||
description: Board type
|
||||
returned: success
|
||||
type: str
|
||||
sample: "conf"
|
||||
board_family:
|
||||
description: Board family
|
||||
returned: success
|
||||
type: str
|
||||
sample: "mvebu"
|
||||
branch:
|
||||
description: Branch
|
||||
returned: success
|
||||
type: str
|
||||
sample: "next"
|
||||
build_repository_commit:
|
||||
description: Build repository
|
||||
returned: success
|
||||
type: str
|
||||
sample: "0d21d90f"
|
||||
build_repsitory_url:
|
||||
description: Build repository
|
||||
returned: success
|
||||
type: str
|
||||
sample: "https://github.com/armbian/build"
|
||||
image_type:
|
||||
description: Image type
|
||||
returned: success
|
||||
type: str
|
||||
sample: "user-built"
|
||||
initrd_arch:
|
||||
description: initrd architecture
|
||||
returned: success
|
||||
type: str
|
||||
sample: "arm"
|
||||
kernel_image_type:
|
||||
description: Kernel image type
|
||||
returned: success
|
||||
type: str
|
||||
sample: "zImage"
|
||||
linux_family:
|
||||
description: Linux family
|
||||
returned: success
|
||||
type: str
|
||||
sample: "mvebu"
|
||||
version:
|
||||
description: Armbian version
|
||||
returned: success
|
||||
type: str
|
||||
sample: "5.91"
|
||||
"""
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.facts.utils import get_file_lines
|
||||
|
||||
# Eample of /etc/armbian-release:
|
||||
#
|
||||
# BOARD=helios4
|
||||
# BOARD_NAME="Helios4"
|
||||
# BOARDFAMILY=mvebu
|
||||
# BUILD_REPOSITORY_URL=https://github.com/armbian/build
|
||||
# BUILD_REPOSITORY_COMMIT=0d21d90f
|
||||
# VERSION=5.91
|
||||
# LINUXFAMILY=mvebu
|
||||
# BRANCH=next
|
||||
# ARCH=arm
|
||||
# IMAGE_TYPE=user-built
|
||||
# BOARD_TYPE=conf
|
||||
# INITRD_ARCH=arm
|
||||
# KERNEL_IMAGE_TYPE=zImage
|
||||
|
||||
|
||||
KEY_TRANSFORMATION = {
|
||||
'LINUXFAMILY': 'linux_family',
|
||||
'BOARDFAMILY': 'board_family',
|
||||
}
|
||||
|
||||
|
||||
def parse_armbian_release():
|
||||
release_file = '/etc/armbian-release'
|
||||
|
||||
lines = get_file_lines(release_file)
|
||||
|
||||
parsed = {}
|
||||
for line in lines:
|
||||
if line.startswith('#'):
|
||||
continue
|
||||
|
||||
try:
|
||||
key, value = line.split('=', 1)
|
||||
except ValueError:
|
||||
continue
|
||||
|
||||
key = KEY_TRANSFORMATION.get(key, key)
|
||||
parsed[key.lower()] = value.strip('\'"')
|
||||
|
||||
return parsed
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec={
|
||||
'fact_path': {'type': 'path'},
|
||||
},
|
||||
supports_check_mode=True,
|
||||
)
|
||||
|
||||
parsed = parse_armbian_release()
|
||||
results = {'ansible_facts': {'armbian': parsed}}
|
||||
module.exit_json(**results)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user