Project

General

Profile

πŸ‘©β€πŸ’» 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

  1. Create the role folder

    • Add a new directory under roles/ with your role name:
      roles/my_new_role/
      
  2. 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.
  3. 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: []
      
  4. 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, and handlers.
    • Generates a README.md inside your role folder.
    • Updates the central roles/README.md index with a link to your role.

βœ… 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:
    - [`my_new_role`](my_new_role/README.md): Short description of what this role does.
    

πŸ“‘ 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 under roles/.
  • 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.