Skip to main content

ansible-doctor

Build Status License

This project is based on the idea (and at some parts on the code) of ansible-autodoc by Andres Bott so credits goes to him for his work.

ansible-doctor is a simple annotation like documentation generator based on Jinja2 templates. While ansible-doctor comes with a default template called readme, it is also possible to write your own templates. This gives you the ability to customize the output and render the data to every format you like (e.g. html or xml).

ansible-doctor is designed to work within your CI pipeline to complete your testing and deployment workflow. Releases are available as Python Packages on GitHub or PyPI and as Docker Image on DockerHub.

Table of Content


Setup

Using pip

# From PyPI as unprivilegd user
$ pip install ansible-doctor --user

# .. or as root
$ sudo pip install ansible-doctor

# From Wheel file
$ pip install https://github.com/xoxys/ansible-doctor/releases/download/v0.1.1/ansible_doctor-0.1.1-py2.py3-none-any.whl

Using docker

docker run \
    -e ANSIBLE_DOCTOR_ROLE_DIR=example/demo-role/ \
    -e ANSIBLE_DOCTOR_OUTPUT_DIR=example/ \
    -e ANSIBLE_DOCTOR_FORCE_OVERWRITE=true \
    -e ANSIBLE_DOCTOR_CUSTOM_HEADER=example/demo-role/HEADER.md \
    -e ANSIBLE_DOCTOR_LOG_LEVEL=info \
    -e PY_COLORS=1 \
    -v $(pwd):/doctor \
    -w /doctor \
    xoxys/ansible-doctor

Keep in mind, that you have to pass selinux labels (:Z or :z) to your mount option if you are working on a selinux enabled system.

Configuration

ansible-doctor comes with default settings which should be sufficient for most users to start, but you can adjust most settings to your needs.

Changes can be made on different locations which will be processed in the following order (last wins):

  • default config (build-in)
  • global config file (path depends on your operating system)
  • folder-based config file (.ansibledoctor.yml|.ansibledoctor.yaml|.ansibledoctor in current working dir)
  • environment variables
  • cli options

Default settings

---
# default is your current working dir
role_dir:
# don't write anything to filesystem
dry_run: False

logging:
    # possible options debug | info | warning | error | critical
    level: "warning"
    # you can enable json logging if a parsable output is required
    json: False

# path to write rendered template file
# default is your current working dir
output_dir:
# default is in-build templates dir
template_dir:
template: readme

# don't ask to overwrite if output file exists
force_overwrite: False
# load custom header from given file and append template output
# to it before write.
custom_header: ""

exclude_files: []
# Examples
# exclude_files:
#   - molecule/
#   - files/**/*.py

CLI options

$ ansible-doctor --help
usage: ansible-doctor [-h] [-c CONFIG_FILE] [-o OUTPUT_DIR] [-f] [-d] [-v]
                      [-q] [--version]
                      role_dir

Generate documentation from annotated Ansible roles using templates

positional arguments:
  role_dir              role directory (default: current working dir)

optional arguments:
  -h, --help            show this help message and exit
  -c CONFIG_FILE, --config CONFIG_FILE
                        location of configuration file
  -o OUTPUT_DIR, --output OUTPUT_DIR
                        output base dir
  -f, --force           force overwrite output file
  -d, --dry-run         dry run without writing
  -v                    increase log level
  -q                    decrease log level
  --version             show program's version number and exit

Environment variables

ANSIBLE_DOCTOR_CONFIG_FILE=
ANSIBLE_DOCTOR_ROLE_DIR=
ANSIBLE_DOCTOR_DRY_RUN=false
ANSIBLE_DOCTOR_LOG_LEVEL=warning
ANSIBLE_DOCTOR_LOG_JSON=false
ANSIBLE_DOCTOR_OUTPUT_DIR=
ANSIBLE_DOCTOR_TEMPLATE_DIR=
ANSIBLE_DOCTOR_TEMPLATE=readme
ANSIBLE_DOCTOR_FORCE_OVERWRITE=false
ANSIBLE_DOCTOR_CUSTOM_HEADER=
ANSIBLE_DOCTOR_EXCLUDE_FILES=
# ANSIBLE_DOCTOR_EXCLUDE_FILES=molecule/,files/**/*.py

Usage

ansible-doctor FOLDER

If you don't pass a folder to ansible-doctor your current working directory will be used. The first step is to identify if the given folder is an ansible role. This check is very simple, if the folder contains a subfolder called tasks is MUST be an ansible role! :)

After the successful check, ansible-doctor will try to read some static files into a dictionary:

  • defaults/main.yml
  • meta/main.yml

This will be the base result set which is used as data source for every output template. Without any work, you will get at least a documentation about available variables and some meta information. Theses basic information can be expanded with a set of available annotations. In general, an annotation is a comment with an identifier. This identifier is followed by colon separated options and ends with a value.

# @identifier option1:option2: <value>

# @var docker_registry_password:example: "%8gv_5GA?"
# @var docker_registry_password:description: Very secure password to login to the docker registry
# @var docker_registry_password:description: >
# You can also write it as multiline description
# Very secure password to login to the docker registry.
# @end
docker_registry_password: "secret"

These list of pre-defined identifiers is currently available:

  • @meta
  • @todo
  • @var
  • @tag

License

This project is licensed under the GNU v3.0 - see the LICENSE file for details.

Maintainers and Contributors

Robert Kaussow

Download files

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

Source Distribution

ansible-doctor-0.1.2.tar.gz (27.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_doctor-0.1.2-py2.py3-none-any.whl (31.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file ansible-doctor-0.1.2.tar.gz.

File metadata

  • Download URL: ansible-doctor-0.1.2.tar.gz
  • Upload date:
  • Size: 27.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

File hashes

Hashes for ansible-doctor-0.1.2.tar.gz
Algorithm Hash digest
SHA256 4a17f6ef5df92ab757d85e3d6d336c5545a8a199c6e1477a8479eb9e2737500d
MD5 57cb6a4085f5bdc67c173e684f7afdb0
BLAKE2b-256 5d736dec7612cd95ceb5b287a1fb87fdb7c9be98531605d5b84672d9d887302f

See more details on using hashes here.

File details

Details for the file ansible_doctor-0.1.2-py2.py3-none-any.whl.

File metadata

  • Download URL: ansible_doctor-0.1.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 31.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

File hashes

Hashes for ansible_doctor-0.1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 bdbbd725a83e29b78cabad445b8a380483d15cd2087e008be3a57650d9e14af1
MD5 a76f58d0e1e6f35fe7b63f9bd1f732b9
BLAKE2b-256 e28870a1da0fd344173d9f77993911607b7d0066b8212d81fcc201a71be0e36c

See more details on using hashes here.

Release history Release notifications | RSS feed

Supported by

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