Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
A

ansible-playbook-grapher

> DevOps
Open source

A command line tool to create a graph representing your Ansible playbook tasks and roles

754 stars0 likes0 views
WebsiteGitHub

About

A command line tool to create a graph representing your Ansible playbook tasks and roles

Ansible Playbook Grapher

ansible-playbook-grapher is a command line tool to create a graph representing your Ansible playbooks, plays, tasks and roles. The aim of this project is to have an overview of your playbooks that you can use as documentation.

Inspired by Ansible Inventory Grapher.

Features

  • Multiple rendering formats: graphviz, mermaid and JSON.
  • Automatically find all your installed roles and collection.
  • Native support for Ansible filters based on tags.
  • Variables interpolation (when possible).
  • Support for import_* and include_*.
  • Multiple flags to hide empty plays, group roles by name, etc...
  • Support for playbooks in collections.
  • Collapsible play, role and block nodes in the SVG output with (--collapsible-nodes).

The following features are available when opening the SVGs in a browser (recommended) or a viewer that supports JavaScript:

  • Highlighting of all the related nodes of a given node when clicking or hovering. Example: Click on a role to select all its tasks when --include-role-tasks is set.
  • A double click on a node opens the corresponding file or folder depending on whether it's a playbook, a play, a task or a role. By default, the browser will open folders and download files since it may not be able to render the YAML file.
    Optionally, you can set the open protocol to use VSCode with --open-protocol-handler vscode: it will open the folders when double-clicking on roles (not include_role) and the files for the other nodes. The cursor will be at the task exact position in the file.
    Lastly, you can provide your own protocol formats with --open-protocol-handler custom --open-protocol-custom-formats '{}'. See the help and an example. To not confuse with Ansible Handlers.
  • Export the dot file used to generate the graph with Graphviz.

Prerequisites

  • Python 3.10 at least. It might work with previous versions, but the code is NOT tested against them. See the support matrix and the matrix in the testing workflow.
  • A virtual environment from which to run the grapher. This is highly recommended because the grapher depends on some versions of ansible-core which are not necessarily installed in your environment and may cause issues if you use some older versions of Ansible ( since ansible package has been split).
  • Graphviz: The tool used to generate the graph in SVG. Optional if you don't plan to use the graphviz renderer.
    bash
    sudo apt-get install graphviz # or yum install or brew install

I try to respect Red Hat Ansible Engine Life Cycle for the supported Ansible version.

Installation

Using uv (recommended)

bash
uv tool install ansible-playbook-grapher

Using pip

bash
pip install ansible-playbook-grapher

You can also install the unpublished version from GitHub directly. Examples:

bash
# Using uv
uv tool install "ansible-playbook-grapher @ git+https://github.com/haidaraM/ansible-playbook-grapher"

# Using pip
pip install "ansible-playbook-grapher @ git+https://github.com/haidaraM/ansible-playbook-grapher"

Renderers

At the time of writing, two renderers are supported:

  1. graphviz (default): Generate the graph in SVG. Has more features than the other renderers.
  2. mermaid-flowchart: Generate the graph in Mermaid format. You can directly embed the graph in your Markdown and GitHub ( and other integrations) will render it.
  3. json: Generate a JSON representation of the graph. The corresponding JSON schema is here. The JSON output will give you more flexibility to create your own renderer outside the grapher.

Comparison of the renderers:

graphviz (.svg) mermaid-flowchart (.mmd) json (.json)
Click on nodes to open the files (open protocol handler) ✅ ❌ ✅: the file location is in the output
Highlight on hover ✅ ❌ ❌: NA
Change graph orientation ❌ ✅ ❌: NA
Group roles by name ✅ ✅ ✅: the roles with the same names will have the same IDs.
View the output file in your the OS default viewer ✅ ✅ on https://mermaid.live/ ✅
Tests of the output Automatic Manual (need a parser) Automatic

If you are interested to support more renderers, feel free to create an issue or raise a PR based on the existing renderers.

Usage

bash
ansible-playbook-grapher tests/fixtures/example.yml
bash
ansible-playbook-grapher --include-role-tasks  tests/fixtures/with_roles.yml
bash
ansible-playbook-grapher tests/fixtures/with_block.yml
bash
ansible-playbook-grapher --include-role-tasks --renderer mermaid-flowchart tests/fixtures/multi-plays.yml
…
bash
ansible-playbook-grapher --renderer json tests/fixtures/simple_playbook.yml

Json output

…

Note on block: Since a block is a logical group of tasks, the conditional when is not displayed on the edges pointing to them but on the tasks inside the block. This mimics Ansible behavior regarding the blocks.

CLI options

The available options:

…

Configuration: ansible.cfg

The content of ansible.cfg is loaded automatically when running the grapher according to Ansible's behavior. The corresponding environment variables are also loaded.

The values in the config file (and their corresponding environment variables) may affect the behavior of the grapher. For example TAGS_RUN and TAGS_SKIP or vault configuration.

More information here.

Limitations and notes

  • Since Ansible Playbook Grapher is a static analyzer that parses your playbook, it's limited to what can be determined statically: no task is run against your inventory. The parser tries to interpolate the variables, but some of them are only available when running your playbook ( ansible_os_family, ansible_system, etc.). The tasks inside any import_* or include_* with some variables in their arguments may not appear in the graph.
  • The rendered SVG graph may sometime display tasks in a wrong order. I cannot control this behavior of Graphviz yet. Always check the edge label to know the task order.
  • The label of the edges may overlap with each other. They are positioned so that they are as close as possible to the target nodes. If the same role is used in multiple plays or playbooks, the labels can overlap.
  • Looping on tasks and roles is not supported. The tasks using loop are displayed as a single task.

Contribution

Contributions are welcome. Feel free to contribute by creating an issue or submitting a PR :smiley:

Local development

To set up a new local development environment:

  • Install graphviz (see above)
  • Install uv
  • uv sync --dev
  • (cd tests/fixtures && ansible-galaxy install -r requirements.yml)

The project contains some collections in collections. If you modify them, you need to do a force install with ansible-galaxy install -r requirements.yml --force

Run the tests and open the generated files in your system's default viewer application:

bash
export TEST_VIEW_GENERATED_FILE=1
make test # run all tests

The graphs are generated in the folders tests/generated-svgs, tests/generated-mermaids and tests/generated-jsons. They are also generated as artifacts in GitHub Actions. Feel free to look at them when submitting PRs.

Lint and format

The project uses ruff to format and lint the code. Run make lint to format and lint.

License

GNU General Public License v3.0 or later (Same as Ansible)

See LICENSE for the full text

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Pythonansibleansible-playbookansible-rolegrapher

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
CategoryDevOps
PricingOpen source

> Related tools

D
Docker
容器化平台,标准化应用交付
G
GitHub Actions
GitHub 原生 CI/CD 工作流
N
Nginx
高性能 Web 服务器与反向代理