Publish Ansible Collection Documentation

Publish Ansible collections documentation as an HTML docsite and make it easy to open from the terminal and browser.

Problem

Ansible collections contain module and filter documentation, but that documentation is not always easy to reach in the form users need.

This becomes more important when a project develops its own modules (Python or PowerShell) and filters. In that case the documentation may be available through ansible-doc, but not through the public Ansible website. The same problem appears in air-gapped or partly disconnected environments, where online documentation is harder to reach or should not be relied on.

Without a project-specific publication path, users often fall back to slower ways of finding documentation:

  • opening source files to inspect embedded plugin documentation;
  • typing exact plugin names into ansible-doc again and again;
  • switching between command-line lookup and a separate web portal.

That makes documentation less convenient to validate during development and less convenient to browse during operations.

Context

Some environments already solve part of this problem through Automation Hub in Ansible Automation Platform. In that case collection content and its documentation can be published through the platform.

Other environments do not have that option. For example:

  • collections are private or closed source and are not published on Ansible Galaxy;
  • the environment is air-gapped and should not depend on public documentation;
  • the project has no private hub yet, but still needs browsable documentation;
  • engineers are developing modules and filters and want to validate their documentation before they commit, push, or publish to a hub;
  • engineers need the same documentation set from both a terminal and a browser.

In those situations a project needs its own lightweight way to publish and open collection documentation.

Solution

Use one documentation pattern with two access paths:

  1. publish module and filter documentation as a static HTML docsite;
  2. make the same documentation easy to open from the command line.

For the published docsite, create one build script that:

  • builds the documentation locally, so engineers can test it before commit and push;
  • is reused unchanged in the CI/CD pipeline, so local validation and published output follow the same path;
  • publishes the generated HTML to GitLab Pages or another internal site.

antsibull-docs fits this pattern well because it builds documentation from the collections already installed in the current environment.

For command-line access, provide shell aliases with fuzzy search so engineers can open module and filter documentation quickly from a terminal. Those aliases can point either to the public Ansible documentation or to a project-specific published docsite. For the C2 Platform implementation, see Ansible documentation command-line aliases .

Collection projects

Collection projects should also validate their embedded module and filter documentation in CI. That validation is a complement to published HTML documentation, not a replacement for it.

A practical pattern is:

  • validate documentation locally during development with ansible-doc;
  • keep a pipeline check in the collection project so missing or broken documentation is still caught when local validation was skipped;
  • define the validation job once and include or reuse it in other collection projects instead of copying the same pipeline logic everywhere.

Air-gapped environments

This pattern also works in air-gapped environments.

The build itself works from the collections already installed in the environment. It does not need online collection discovery. The main extra step is to publish the generated HTML on an internal endpoint that users in that environment can reach, for example GitLab Pages or another internal web site.

Examples and Implementation

The C2 Platform inventory project  c2platform/c2/ansible-inventory provides a concrete example of this pattern. Its published docsite is available at c2platform.gitlab.io/c2/ansible-inventory  .

The example implementation has four parts:

  • requirements.txt pins antsibull-docs in the Ansible development environment;
  • execution-environment.yml adds antsibull-docs to the Ansible execution environment used by the CI/CD pipeline;
  • scripts/build-collection-docs.sh builds the local docsite;
  • .gitlab-ci.yml publishes that result through GitLab Pages.

Development and execution environment dependencies

The C2 implementation keeps antsibull-docs available in both places where the workflow needs it:

The execution-environment definition includes antsibull-docs in its Python dependencies:

 execution-environment.yml

 7dependencies:
 8  ansible_core:
 9    package_pip: ansible-core==2.18.12
10  ansible_runner:
11    package_pip: ansible-runner
12  galaxy: requirements.yml
13  python:
14    - ansible-lint==26.1.1
15    - yamllint==1.38.0
16    - pywinrm==0.5.0
17    - pykerberos==1.2.4
18    - ansible-cmdb==1.31
19    - ansible-navigator==26.4.0
20    - antsibull-docs==2.24.0
21    - j2lint==1.2.0
22  system: bindep.txt

Local build script

The local script shows the concrete antsibull-docs workflow used by the inventory project:

  • initialize the Sphinx project with sphinx-init --use-current;
  • install the generated Sphinx requirements;
  • generate reStructuredText for the currently available collections;
  • build the HTML output.

 scripts/build-collection-docs.sh

 1#!/usr/bin/env bash
 2# Build a local docsite for all installed Ansible collections using
 3# antsibull-docs.
 4#
 5# Usage: scripts/build-collection-docs.sh
 6#
 7# The docsite is generated under ./built-docs/build/html/. Set DEST_DIR to use a
 8# different output directory, for example: DEST_DIR=public
 9#   scripts/build-collection-docs.sh
10
11set -euo pipefail
12
13ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
14cd "$ROOT_DIR"
15
16DEST_DIR="${DEST_DIR:-built-docs}"
17
18echo "Cleaning previous build in ${DEST_DIR}..."
19rm -rf "$DEST_DIR"
20
21echo "Initializing Antsibull Sphinx project..."
22mkdir -p "$DEST_DIR"
23chmod 755 "$DEST_DIR"
24antsibull-docs sphinx-init \
25    --use-current \
26    --dest-dir "$DEST_DIR"
27
28echo "Installing Sphinx requirements..."
29python3 -m pip install -r "$DEST_DIR/requirements.txt"
30
31echo "Generating collection documentation..."
32mkdir -p "$DEST_DIR/rst"
33chmod og-w "$DEST_DIR/rst"
34antsibull-docs \
35    --config-file "$DEST_DIR/antsibull-docs.cfg" \
36    current \
37    --cleanup everything \
38    --dest-dir "$DEST_DIR/rst"
39
40echo "Building HTML documentation..."
41sphinx-build -M html "$DEST_DIR/rst" "$DEST_DIR/build" -c "$DEST_DIR"
42
43echo ""
44echo "Documentation built successfully."
45echo "Open ${DEST_DIR}/build/html/index.html in a browser to view it."

Run it from the project root:

./scripts/build-collection-docs.sh

Then open the generated site locally:

firefox built-docs/build/html/index.html

GitLab Pages publication

The inventory project publishes the same documentation through its pages job.1 The important part of the pipeline is that it reuses the same build script, writes the output to public/, and then moves the generated HTML to the Pages artifact root:

 .gitlab-ci.yml

62pages:
63  stage: docs
64  needs:
65    - job: yamllint
66      optional: true
67    - job: ansible-lint
68      optional: true
69    - job: Galaxy install
70      optional: false
71  script:
72    - DEST_DIR=public ./scripts/build-collection-docs.sh
73    - mv public/build/html/* public/
74    - rm -rf public/html
75  artifacts:
76    paths:
77      - public

This keeps local validation and CI publication aligned: the same build script is used in both places, with DEST_DIR=public in CI.

Terminal access on the development desktop

After the docsite is published, the development desktop can expose it through Ansible documentation aliases. That gives engineers two practical entry points to the same documentation set:

  • a browser for browsing the full site;
  • shell aliases with fuzzy search for fast terminal lookup.

The alias pattern and desktop-role configuration are described in Ansible Documentation Command-Line Aliases .

Additional Information


  1. In GitLab CI/CD, the top-level job name pages is treated specially by GitLab as the job that publishes a GitLab Pages site. In this pattern the job name is therefore not an arbitrary label that can be freely renamed without changing the publication behavior. ↩︎


Last modified November 26, 2026: guideline antsibull C2-1836 C2-742 (535ac6d)