Ansible Playbook Grapher

If you use Ansible for automation, then you should be interested in a tool called Ansible Playbook Grapher which allows you to visualize the workflow of your playbooks.

I ran into a little trouble getting it to work initially, but eventually was able to output graphs for Meza.

Although you can output Mermaid graphs (see example) in lieu of the default SVG, the SVG format is richer, more functional and can handle large complex graphs more easily.

Usage edit

Although it is not mentioned in the help, you can use the ANSIBLE_CONFIG environment variable to specify the config (so apg finds your roles etc.), and thereby easily generate a series of svgs right from the 'playbooks' directory.
ANSIBLE_CONFIG=/home/greg/src/meza/config/ansible.cfg ansible-playbook-grapher --open-protocol-handler vscode --collapsible-nodes --title 'Meza site playbook' -vvv site.yml


The way to use ansible-playbook-grapher is to setup a Python Virtual Environment, so that you can install apg. Once it is installed, you can use it on a checkout of Meza by changing into the 'config' directory and invoking the script with optional arguments ansible-playbook-grapher --include-role-tasks ../src/playbooks/site.yml

By adding in the --open-protocol-handler vscode option, the nodes in the diagram will launch VSCode when clicked.

The command ansible-playbook-grapher --include-role-tasks --open-protocol-handler vscode ../src/playbooks/site.yml generates 'site.svg' in the current directory. You then view site.svg in your web browser.


# create a basic graph
ansible-playbook-grapher --open-protocol-handler vscode --title 'Meza site playbook' -vvv ../src/playbooks/site.yml

# Make the nodes collapsible
ansible-playbook-grapher --open-protocol-handler vscode --collapsible-nodes --title 'Meza site playbook' -vvv ../src/playbooks/site.yml


# Also graph the tasks (creates a much bigger graph)
ansible-playbook-grapher --include-role-tasks --open-protocol-handler vscode --collapsible-nodes --title 'Meza site playbook' -vvv ../src/playbooks/site.yml

The site playbook with tasks is too large to thumbnail without raising limits, so this is a link to the file.

See Also edit

Check out all the graphs created for the Meza playbooks https://github.com/freephile/meza/blob/dev/src/playbooks/README.md