Git Product home page Git Product logo

docsible's Introduction

Docsible

About

Docsible is a command-line interface (CLI) written in Python that automates the documentation of Ansible roles and collections. It generates a Markdown-formatted README file for role or collection by scanning the Ansible YAML files.

Table of Contents

Features

  • Generates a README in Markdown format
  • Scans and includes default variables and role-specific variables
  • Parses tasks, including special Ansible task types like 'block' and 'rescue'
  • Optionally includes playbook content in the README
  • CLI-based, easy to integrate into a CI/CD pipeline
  • Provides a templating feature to customize output
  • Supports multiple YAML files within tasks, defaults, vars directory
  • Includes meta-data like author and license from meta/main.[yml/yaml]
  • Generates a well-structured table for default and role-specific variables
  • Support for encrypted Ansible Vault variables

Installation

To install Docsible, you can run:

pip install docsible

Usage

To use Docsible, you can run the following command in your terminal:

Specific path

docsible --role /path/to/ansible/role --playbook /path/to/playbook.yml --graph

Document collection

docsible --collection ./collections_tests/lucian/ --no-backup --graph

Only role without playbook

docsible --role /path/to/ansible/role # without include a playbook into readme
$ docsible --help
Usage: docsible [OPTIONS]

Options:
  --role TEXT      Path to the Ansible role directory.
  --collection TEXT Path to the Ansible collection directory.
  --playbook TEXT  Path to the playbook file.
  --graph          Generate Mermaid graph for tasks.
  --no-backup      Do not backup the readme before remove.
  --no-docsible    Do not create .docsible file and do not print relative variable to generated README.md.
  --comments       Read comments from tasks files.
  --md-template    Path to the markdown template file.
  --append         Append to the existing README.md instead of replacing it.
  --version        Show the module version.
  --help           Show this message and exit.

Flags

  • --role: Specifies the directory path to the Ansible role.
  • --collection: Specifies the directory path to the Ansible collection.
  • --playbook: Specifies the path to the Ansible playbook (Optional). ( Works only with roles )
  • --graph: Generate mermaid for role and playbook.
  • --no-backup: Ignore existent README.md and remove before generate a new one. (Optional).
  • --comments: Read comments from tasks files. (Optional).
  • --md-template: Specifies the path to the markdown template file (Optional). ( Works only with roles )
  • --append: Append existing readme.md if needed

Data Sources

Docsible fetches information from the following files within the specified Ansible role:

  • defaults/*.yml/yaml: For default variables
  • vars/*.yml/yaml: For role-specific variables
  • meta/main.yml/yaml: For role metadata
  • tasks/*.yml/yaml: For tasks, including special task types and subfolders

Examples

Demo1 coffeemaker_midday role

Demo2 coffeemaker_morning role

Prerequisites

Docsible works with Python 3.x and requires the following libraries:

  • Click
  • Jinja2
  • PyYAML

TODO

  • Clean the code
  • Add more features
  • Custom templates for collection
  • Multiple playbooks handle into mermaid for collection and role

About comments

This tool work whith several type of comments.

On variables and defaults

The tool read comments placed before a variable, only if it begin with specific tag:

# title: This tag will be used for popiulate the column Title of the README.md. It is a short description of the variable

# required: This tag will be used for popiulate the column Required of the README.md

On tasks

The tool will read all the line before each - name: of the tasks that begin with #. All comment will be reported to the column Comments of the tasks tables.

Contributing

For details on how to contribute, please read the Contributing Guidelines.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Author

docsible's People

Contributors

exaluc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

docsible's Issues

[BUG] In line comments are part of var values

Describe the Bug

If you use inline comment on vars, like example, these become part of "value" in the generated README.md

Environment

  • Docsible Version: 0.5.0
  • Python Version: 3.10
  • Operating System: WSL Ubuntu

To Reproduce

Describe the steps to reproduce the behavior:

  1. create a test variable or default with inline comment like: test_var: value # this is an inline comment
  2. generate the README whit docsible

Expected Behavior

Value without the comment:

The result will be like:

Var Type Value Required Title
test_var str value None None

Actual Behavior

Value with the comment:

Var Type Value Required Title
test_var str value # this is an inline comment None None

[BUG] Include tasks is not handled: Syntax error in text mermaid

Describe the Bug

When task got include, mermaid dont handle it, it's generate include like: |Include| {'file': 'modify.yml'}

Environment

  • Docsible Version: docsible, version 0.6.0

  • Python Version: Python 3.9.2

  • Operating System: Linux

  • CLI or Script: docsible --role ./test --graph

To Reproduce

Describe the steps to reproduce the behavior:

  1. Run the following command docsible --role ./test --graph
  2. Navigate to readme.md
  3. Open readme.md, check the include into mermaid templates

Expected Behavior

Nice template with mermaid.

Actual Behavior

Syntax error in text mermaid version 10.7.0

Incorrect Variable Documentation in Generated README.md

Incorrect Variable Documentation

When using docsible to generate the README.md file, the variable in vars/main.yml is incorrectly documented. The variable cwa_use_proxy is not displayed correctly in the generated README.md file.

The problematic variable in vars/main.yml:

cwa_use_proxy: "{{ true | bool if cwa_http_proxy is defined and cwa_http_proxy | length > 0 else false | bool }}"

The generated README.md file shows:

image

Expected results should be as the variable.

Environment

  • Docsible Version: 0.6.1
  • Python Version: 3.8.2
  • Operating System: Ubuntu

To Reproduce

Describe the steps to reproduce the behavior:

  1. Create a variable in vars/main.yml:
cwa_use_proxy: "{{ true | bool if cwa_http_proxy is defined and cwa_http_proxy | length > 0 else false | bool }}"
  1. Run the following command:
docsible --role . --no-backup --graph --no-docsible

Expected Behavior

Expected results should be as the variable in declared.

Actual Behavior

image

Feature Request: Add Marker for Controlled Appending in README.md

Hi @exaluc, first of all love your work on docsible. I have been using this for generating documents for roles. Thank you for the quick response on the previous bug #12 <3. I would like to request a new feature. It will be a life saver for me.

Currently, docsible overrides the entire content of the README.md file when generating documentation. I would like to request a feature that allows docsible to append content after specific markers, enabling better control over the generated documentation and preserving other parts of the README.md file.

Proposed Solution

Introduce two markers that can be added to the README.md file:

  • <---- begin of docsible --->

docsible should append its generated content only between these markers, leaving the rest of the README.md file intact. If the markers are not present, docsible can default to its current behavior of overriding the entire file.

Environment

Docsible Version: 0.6.2
Python Version: Python 3.8.3
Operating System: Ubuntu

[BUG] array of variables

Describe the Bug

The single variables are OK, but if we have an array of variables it's not working properly

Environment

  • Docsible Version: 0.5.8
  • Python Version: 3.11
  • Operating System: Linux
  • CLI or Script: CLI command in CI/CD gitlab

To Reproduce

here my variables :

fm_hardening_sshd_login_grace_time: true
fm_hardening_openssh_default_policy: true

packages_ssh:

  • openssh
  • openssh-server
  • openssh-clients
  • rpmdevtools

Expected Behavior

Array of variables
packages_ssh | openssh ; openssh-server ; openssh-clients ; rpmdevtools

Actual Behavior

nothing...

extra question

Can we have an explanation on how customize or create template to generate a customized README.md file ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.