ansibler
v0.0.1
Published
Performs various tasks required for generating sleek documentation for Ansible playbooks and roles
Downloads
5
Maintainers
Readme
Performs various tasks required for generating sleek documentation for Ansible playbooks and roles
➤ Table of Contents
➤ Requirements
➤ Overview
Ansibler is a set of tools used to manage Ansible playbooks and roles. It provides the following functionality:
- Populating the Role Dependency Chart for the Main Playbook: Scans through the
roles/
folder and extracts the description of each role from themeta/main.yml
file to a JSON file (that can be used to display a dependency chart similar to the one found in the Playr repository). This task also injects the project build status and icons representing which operating systems a role supports into the JSON. - Populating the Role Dependency Chart for Individual Roles: You can also create a dependency chart at the role-level as well. Instead of scanning through the
roles/
folder, it will look at therequirements.yml
folder and generate the JSON that can be used to generate a role-dependency chart for roles that have dependencies. - Automatically Updating
platforms:
ingalaxy_info:
: When used in combination with Ansible Molecule JSON, it can automatically populate theplatforms:
section in thegalaxy_info:
of themeta/main.yml
file found in each role.
➤ Getting Started
You can run ansibler
by installing it globally (i.e. npm install -g @megabytelabs/ansibler
) or running it with npx
. You can then run ansibler --help
to see the available parameters. You should see output that looks something like this:
❯ ansibler --help
Usage: ansibler [options]
-h, --help Displays help
-d, --data String Relative path to the data file.
-o, --output String Relative path to the output file - default: ./ansible-molecule.json
-c, --command String Additional commands to run before analyzing
-i, --inject String Inject output to a JSON file
➤ Example Usage
Ansibler has several different features that can be individually run or run all at the same time.
Populating the Role Dependency Chart for the Main Playbook
To generate the role dependency chart (that you can see in the README of our Playr repository), you should:
- Make sure all the roles are located in the
roles/
folder of your project and that each role has a valid description. - Run
ansibler --roles "./roles" --output "./role-chart.json" --populate-descriptions
The command above will scan through the roles/
folder and extract all of the descriptions into a JSON file. It might be important to know that a special format is used that is meant to be compatible with @appnest/readme which is the documentation generator we use.
Example Output
After running the above command (in step 2 above), you will be left with a file titled role-chart.json
in the current working directory that might look something like this:
{
"role_dependencies": [
["Role Dependency", "Description", "Supported OSes"],
[
"<a href='https://gitlab.com/megabyte-space/ansible-roles/androidstudio'>professormanhattan.androidstudio</a>",
"Installs Android Studio on nearly any OS",
"Supported OS feature not part of this task"
],
[
"<a href='https://gitlab.com/megabyte-space/ansible-roles/appium'>professormanhattan.appium</a>",
"Installs Appium on almost any platform",
"Supported OS feature not part of this task"
],
[
"<a href='https://gitlab.com/megabyte-space/ansible-roles/autokey'>professormanhattan.autokey</a>",
"Installs AutoKey on Linux or AutoHotkey on Windows",
"Supported OS feature not part of this task"
]
]
}
Populating the Role Dependency Chart for Individual Roles
You can also generate a role dependency chart for individual roles. Instead of scanning the roles/
folder to find roles, it looks at the requirements.yml
. For each role in the requirements.yml
file, it will include a line in the dependency chart. The chart includes all of the same details as the main playbook dependency chart.
Automatically Updating platforms:
in galaxy_info:
Every role that is published to Ansible Galaxy needs to include a file in meta/main.yml
that Ansible Galaxy can use to display your role to the right users. One way the Ansible Galaxy meta/main.yml
file does this is by providing a section in the file called platforms:
where information can be populated to tell Ansible Galaxy which operating systems your role will work on. For hundreds of roles, this can be a tedious process.
Many of the roles available on Ansible Galaxy haphazardly list a long list of platforms which the role obviously was not tested on. That does not cut it for us. To address this issue, we developed an automated system for properly generating the platforms:
compatibility chart in meta/main.yml
. You can get your platforms:
variable automatically populated the right way by using our two-step system:
- First, follow the instructions provided by our Ansible Molecule JSON project to set your role(s) up with automated testing
- With the JSON data that Ansible Molecule JSON generates, you can automatically populate the
meta/main.yml
platforms:
section by runningansibler TODO
Example Output
After running the command (in step 2 above), you should be able to see a proper platforms:
section in any of the roles you generated the compatibility data for. The platforms:
section of the meta/main.yml
file in each role should look something like this:
The Ansible community is really in need of something like this. The platforms:
section should provide useful data instead of just saying that the role supports all versions of every operating system which is the case way too often.
➤ Contributing
Contributions, issues, and feature requests are welcome! Feel free to check the issues page. If you would like to contribute, please take a look at the contributing guide.
Brian Zalewski
➤ License
Copyright © 2021 Megabyte LLC. This project is MIT licensed.