Skip to main content

Ansible Documentation Template Extractor

Project description

Ansible Documentation Template Extractor

ansible-doc-template-extractor is a documentation extractor for Ansible that reads the documentation from spec files in YAML format and produces documentation output using Jinja2 template files.

The supported formats of the spec files are:

  • For Ansible roles, the Ansible-defined format in the <role>/meta/argument_specs.yml files (see here).
  • For Ansible playbooks, a format defined by this project (see below).
  • You can also use any other spec file format for roles, playbooks or any other Ansible items, as long as it is in YAML and you provide a custom template for it.

The ansible-doc-template-extractor program includes a number of built-in template files:

  • role.rst.j2: Produces RST format from the Ansible-defined spec files for roles.
  • role.md.j2: Produces Markdown format from the Ansible-defined spec files for roles.
  • playbook.rst.j2: Produces RST format from the project-defined spec files for playbooks.
  • playbook.md.j2: Produces Markdown format from the project-defined spec files for playbooks.

These templates are selected automatically based on the detected spec file type and output format.

You can write your own custom templates for other output formats and/or other spec file formats (see below).

Disclaimer: The ansible-doc-template-extractor tool should be seen as a temporary bridge until there is official documentation extraction support for Ansible roles and playbooks. There have been discussions in Ansible forums to add support for Ansible roles to the ansible-doc and ansible-navigator tools. Once that happens, the ansible-doc-template-extractor tool is probably no longer needed for Ansible roles. In the event that an official spec format for Ansible playbooks gets defined one day and that this format gets supported by the ansible-doc and ansible-navigator tools, the ansible-doc-template-extractor tool is probably no longer needed at all.

Installation

If you want to install the package into a virtual Python environment:

$ pip install ansible-doc-template-extractor

Otherwise, you can also install it without depending on a virtual Python environment:

Example use

Suppose you have the following subtree:

├── my_collection
|   ├── roles
|       ├── my_role
|           └── meta
|               └── argument_specs.yml
├── docs

Then you can run the extractor as follows:

$ ansible-doc-template-extractor -v -o docs my_collection/roles/my_role/meta/argument_specs.yml

Loading template file: .../templates/role.rst.j2
Ansible spec type: role
Ansible name: my_role
Loading spec file: my_collection/roles/my_role/meta/argument_specs.yml
Created output file: docs/my_role.md

This will create an RST file with the documentation of the role:

├── docs
│   └── my_role.rst

Display the help message to learn about other options:

$ ansible-doc-template-extractor --help

Format of spec file for Ansible playbooks

Note: This spec file format is preliminary at this point and can still change.

The spec file format defined by this project for Ansible playbooks:

playbook:
  name: <Playbook name>
  title: <Playbook title>
  description:
    <string or list of strings with playbook descriptions>
  prerequisites:
    <string or list of strings with playbook prerequisites>
  version_added: <If the playbook was added to Ansible, the Ansible version>
  examples:
    - description: <string or list of strings with example description>
      command: <example ansible-playbook command>
  input_schema:
    <A JSON schema that describes a single input variable of the playbook>
  output_schema:
    <A JSON schema that describes a single output variable for success>
  authors:
    - <list of strings with playbook author names>

An example spec file for playbooks using this format is in the examples/playbooks directory.

Writing custom templates

You can write your own custom templates for any other output format and/or for any other spec file format.

The following rules apply when writing templates:

  • The templating language is Jinja2.

  • The following Jinja2 extensions are enabled for use by the template:

  • The following Jinja2 variables are set for use by the template:

    • name (str): Name of the Ansible role, playbook, or other item.

    • spec_file_name (str): Path name of the spec file.

    • spec_file_dict (dict): Content of the spec file.

You can use the templates in the templates directory as examples for your own custom templates.

Reporting issues

If you encounter a problem, please report it as an issue on GitHub.

License

This package is licensed under the Apache 2.0 License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ansible_doc_template_extractor-0.11.0.tar.gz (46.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ansible_doc_template_extractor-0.11.0-py3-none-any.whl (22.6 kB view details)

Uploaded Python 3

File details

Details for the file ansible_doc_template_extractor-0.11.0.tar.gz.

File metadata

File hashes

Hashes for ansible_doc_template_extractor-0.11.0.tar.gz
Algorithm Hash digest
SHA256 399a3b0f7f4d6c451c194cbb88311f297fd6306de31bea57e23d8f035acb9043
MD5 e2365415d5fc43dadc52800f99afd191
BLAKE2b-256 e441ed46bb01756cbe8ffc2b7a4cacdc4643037176d386910be67e34e9caf212

See more details on using hashes here.

Provenance

The following attestation bundles were made for ansible_doc_template_extractor-0.11.0.tar.gz:

Publisher: publish.yml on andy-maier/ansible-doc-template-extractor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ansible_doc_template_extractor-0.11.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ansible_doc_template_extractor-0.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e54e44eb1b790624e82ed1bf1847b1f94acff99e7af1c5ba115cacaf40bd55be
MD5 b1a99131b6a09ea12825023faafef390
BLAKE2b-256 1e4af689bc878065a6c47c0bf42a228441650c19f9865c1a5f3899f9086c41ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for ansible_doc_template_extractor-0.11.0-py3-none-any.whl:

Publisher: publish.yml on andy-maier/ansible-doc-template-extractor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page