Ansible Documentation Command-Line Aliases
Categories:
adoc, adocf, adocw, and adocfw to open Ansible module and
filter documentation quickly, while keeping terminal and browser lookup
aligned.Problem
Looking up module or filter documentation from the terminal usually means typing
an exact plugin name and remembering the right ansible-doc -t option.
That is slow when a project uses many Ansible collections, when engineers are still exploring unfamiliar plugins, or when the project also publishes its own HTML documentation site. In those cases engineers need a fast way to:
- discover available modules and filters;
- preview documentation before opening it fully;
- switch between terminal lookup and browser-based browsing;
- point browser access at public or project-specific documentation.
Without a shared pattern, every engineer ends up typing longer commands or keeping private shell snippets.
Context
ansible-doc is the standard Ansible community CLI for module and filter
lookup, but it is still a terminal-first tool. fzf complements it well by
turning ansible-doc -t <type> -l into an interactive picker with preview.
C2 Platform adopts that combination as a development-desktop convenience pattern. It is not a replacement for published HTML documentation. Published project documentation remains the right format for browsing and sharing, while these aliases provide a fast terminal entry point to the same documentation set. For the publication pattern, see Publish Ansible Collection Documentation .
Solution
- Provide one shell helper,
_adoc(), that accepts a plugin type (moduleorfilter) and a mode (autoorweb). - Use
ansible-doc -t <type> -las the source list andfzfas the picker, withansible-doc -t <type> {1}as preview. - Keep terminal lookup as the default behavior for
adocandadocf. - Provide forced browser aliases,
adocwandadocfw, for users who want the HTML page directly. - Let
C2_ADOC=wswitch the default aliases to browser mode. - Let
C2_ADOC_URLoverride the URL template so the browser aliases can point at docs.ansible.com, an internal mirror, or a project-specific docsite. - Manage the aliases centrally on development workstations so engineers use the same commands and URL pattern.
Benefits
- Faster discovery of modules and filters.
- Less need to remember exact plugin names.
- One shared lookup pattern across development workstations.
- Easy switching between terminal and browser workflows.
- Support for internal or project-specific documentation endpoints.
Examples and Implementation
Managed desktop-role implementation
The
Ansible Desktop Role ( c2platform.dev.desktop)
renders the helper and aliases into ~/.c2_bash_aliases.sh:
roles/desktop/templates/c2_bash_aliases.sh.j2
_adoc() {
local type="$1" mode="$2" sel url eff_mode c2_adoc_url
# Bepaal de effectieve modus (web of term)
if [ "$mode" = "auto" ] && [ "${C2_ADOC:-}" = "w" ]; then
eff_mode="web"
else
eff_mode="$mode"
fi
# fzf selectie met preview
sel=$(ansible-doc -t "$type" -l | fzf --preview="ansible-doc -t $type {1}" --preview-window=right:50% | cut -d" " -f1)
# Als er niks gekozen is (ESC), stop dan
[ -z "$sel" ] && return
# Voer actie uit op basis van de effectieve modus
if [ "$eff_mode" = "web" ]; then
c2_adoc_url="https://docs.ansible.com/ansible/latest/collections/{collection_path}_{type}.html"
if [ -n "${C2_ADOC_URL:-}" ]; then
c2_adoc_url="$C2_ADOC_URL"
fi
url="${c2_adoc_url//\{collection_path\}/$(echo "$sel" | tr "." "/")}"
url="${url//\{name\}/$sel}"
url="${url//\{type\}/$type}"
# Start the browser in a new session so the prompt returns immediately
# and no job-control output appears in the terminal. Do not add the
# command to shell history.
setsid xdg-open "$url" >/dev/null 2>&1
else
history -s "ansible-doc -t $type $sel"
ansible-doc -t "$type" "$sel"
fi
}
# Standaard aliassen (luisteren naar C2_ADOC variabele)
alias adoc='_adoc module auto'
alias adocf='_adoc filter auto'
# Geforceerde web aliassen (negeren ADOC variabele)
alias adocw='_adoc module web'
alias adocfw='_adoc filter web'
This implementation gives four user-facing aliases:
adoc— select a module and openansible-doc.adocf— select a filter and openansible-doc.adocw— select a module and open the documentation URL in a browser.adocfw— select a filter and open the documentation URL in a browser.
The adoc and adocf aliases run in auto mode. They respect C2_ADOC=w
and switch to browser mode automatically when that variable is set.
Switching the default to browser mode
export C2_ADOC=w
With that setting, adoc and adocf behave like their web variants, while
adocw and adocfw still remain the explicit forced-browser aliases.
Pointing browser lookup at another docsite
The default browser template is:
https://docs.ansible.com/ansible/latest/collections/{collection_path}_{type}.html
The helper supports these placeholders:
| Placeholder | Value |
|---|---|
{collection_path} | Selected name with dots replaced by slashes, for example ansible/builtin/file. |
{name} | Selected name unchanged, for example ansible.builtin.file. |
{type} | module or filter. |
To point the aliases at another documentation endpoint, set C2_ADOC_URL:
export C2_ADOC_URL="https://docs.example.com/ansible/{collection_path}_{type}.html"
This is useful when a project publishes its own collection documentation with
antsibull-docs, or when the environment uses an internal mirror.
Unmanaged shell setup
If a workstation does not receive the managed desktop role, copy the same helper
pattern into ~/.bash_aliases or another shell startup file instead of keeping
one-off personal variants. Keep the alias names and URL-template behavior the
same so the workflow remains portable across C2 Platform workstations.
Additional Information
- Publish Ansible Collection Documentation: Publish Ansible collections documentation as an HTML docsite and make it easy to open from the terminal and browser.
- Ansible Desktop Role: Provisions an Ubuntu 24.04 Ansible development desktop with VirtualBox, LXD, and Vagrant.
- ansible-doc documentation
- fzf on GitHub
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.