Ansible Playbook Grapher: Difference between revisions

From Freephile Wiki
Created page with "If you use Ansible for automation, then you should be interested in a tool called [https://github.com/haidaraM/ansible-playbook-grapher Ansible Playbook Grapher] which allows you to visualize the workflow of your playbooks. I ran into [https://github.com/freephile/meza/issues/63 a little trouble getting it to work initially], but eventually was able to output graphs for Meza. thumb"
 
No edit summary
Line 3: Line 3:
I ran into [https://github.com/freephile/meza/issues/63 a little trouble getting it to work initially], but eventually was able to output graphs for Meza.
I ran into [https://github.com/freephile/meza/issues/63 a little trouble getting it to work initially], but eventually was able to output graphs for Meza.
[[File:Ansible-playbook-grapher illustration of meza site playbook.svg|thumb]]
[[File:Ansible-playbook-grapher illustration of meza site playbook.svg|thumb]]
== Usage ==
The way to use '''ansible-playbook-grapher''' is to setup a [[Python_deployments#Basic_PIP_and_Virtual_Environments|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 <code>ansible-playbook-grapher --include-role-tasks ../src/playbooks/site.yml</code>
By adding in the <code>--open-protocol-handler vscode</code> option, the nodes in the diagram will launch [[VSCode]] when clicked.
The command <code>ansible-playbook-grapher --include-role-tasks --open-protocol-handler vscode ../src/playbooks/site.yml</code> generates 'site.svg' in the current directory. You then view site.svg in your web browser.
<syntaxhighlight lang=bash>
# 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
</syntaxhighlight>

Revision as of 19:59, 12 October 2025

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.


Usage edit

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