π©βπ» Contributor Guide: Adding a New Ansible Role
π Purpose
This guide explains how to add a new Ansible role to the homelab repository and ensure its documentation is automatically generated by our GitHub Action workflow.
π Steps to Add a New Role
- Create the role folder
- Add a new directory under
roles/with your role name:roles/my_new_role/
- Add a new directory under
- Add required files
- At minimum, include:
meta/main.ymlβ defines role metadata (name, description, author, license, supported platforms, dependencies).tasks/main.ymlβ defines tasks for the role.defaults/main.ymlβ optional, for default variables.vars/main.ymlβ optional, for constant variables.handlers/main.ymlβ optional, for handlers.
- At minimum, include:
- Fill in metadata
- Example
meta/main.yml:galaxy_info: role_name: my_new_role author: Your Name description: Short description of what this role does. license: MIT min_ansible_version: "2.9" platforms: - name: Ubuntu versions: - focal - jammy dependencies: []
- Example
- Commit your changes
- Push your branch or open a pull request.
βοΈ What Happens Next
- The Generate Ansible Role Docs GitHub Action runs automatically on push/PR.
- It executes
scripts/generate_role_docs.py, which:- Reads your
meta/main.yml,defaults,vars,tasks, andhandlers. - Generates a
README.mdinside your role folder. - Updates the central
roles/README.mdindex with a link to your role.
- Reads your
β Contributor Expectations
- No manual README writing needed β the script handles it.
- Keep metadata accurate β description, platforms, and dependencies drive the docs.
- Use comments in variable files β they appear in the generated tables.
- Check the PR diff β youβll see your roleβs README and the index updated automatically.
π Example
After adding roles/my_new_role/ and pushing, youβll see:
roles/my_new_role/README.mdβ auto-generated documentation.roles/README.mdβ updated index entry:
π meta/main.yml Starter Template
galaxy_info:
role_name: my_new_role
author: Your Name
description: >
Short description of what this role does.
(Keep it concise but clear for auto-generated docs.)
license: MIT
min_ansible_version: "2.9"
platforms:
- name: Ubuntu
versions:
- focal
- jammy
- name: EL
versions:
- "7"
- "8"
# List other roles this one depends on.
# These will be documented automatically in the README.
dependencies: []
π Key Fields Explained
role_nameβ Must match the folder name underroles/.authorβ Contributorβs name or team.descriptionβ Appears in the generated README and central index.licenseβ License type (MIT, GPL, etc.).min_ansible_versionβ Minimum version required for the role.platformsβ OS families and versions supported.dependenciesβ Other roles that must run before this one.
π Contributor Tip
- Keep descriptions short but meaningful β they show up in the role index.
- Add dependencies if your role relies on another (e.g.,
common,firewall). - Update platforms whenever you test against new OS versions.