No description
Find a file
dependabot[bot] 73286c4d99
chore(deps): bump pytest from 7.4.4 to 8.0.0 (#171)
Bumps [pytest](https://github.com/pytest-dev/pytest) from 7.4.4 to
8.0.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/pytest-dev/pytest/releases">pytest's
releases</a>.</em></p>
<blockquote>
<h2>pytest 8.0.0 (2024-01-27)</h2>
<p>See <a
href="https://github.com/pytest-dev/pytest/releases/tag/8.0.0rc1">8.0.0rc1</a>
and <a
href="https://github.com/pytest-dev/pytest/releases/tag/8.0.0rc2">8.0.0rc2</a>
for the full changes since pytest 7.4!</p>
<h2>Bug Fixes</h2>
<ul>
<li><a
href="https://redirect.github.com/pytest-dev/pytest/issues/11842">#11842</a>:
Properly escape the <code>reason</code> of a <code>skip
&lt;pytest.mark.skip ref&gt;</code>{.interpreted-text
role=&quot;ref&quot;} mark when writing JUnit XML files.</li>
<li><a
href="https://redirect.github.com/pytest-dev/pytest/issues/11861">#11861</a>:
Avoid microsecond exceeds <code>1_000_000</code> when using
<code>log-date-format</code> with <code>%f</code> specifier, which might
cause the test suite to crash.</li>
</ul>
<h2>8.0.0rc2</h2>
<h1>pytest 8.0.0rc2 (2024-01-17)</h1>
<h2>Improvements</h2>
<ul>
<li><a
href="https://redirect.github.com/pytest-dev/pytest/issues/11233">#11233</a>:
Improvements to <code>-r</code> for xfailures and xpasses:
<ul>
<li>Report tracebacks for xfailures when <code>-rx</code> is set.</li>
<li>Report captured output for xpasses when <code>-rX</code> is
set.</li>
<li>For xpasses, add <code>-</code> in summary between test name and
reason, to match how xfail is displayed.</li>
</ul>
</li>
<li><a
href="https://redirect.github.com/pytest-dev/pytest/issues/11825">#11825</a>:
The <code>pytest_plugin_registered</code>{.interpreted-text
role=&quot;hook&quot;} hook has a new <code>plugin_name</code> parameter
containing the name by which <code>plugin</code> is registered.</li>
</ul>
<h2>Bug Fixes</h2>
<ul>
<li>
<p><a
href="https://redirect.github.com/pytest-dev/pytest/issues/11706">#11706</a>:
Fix reporting of teardown errors in higher-scoped fixtures when using
[--maxfail]{.title-ref} or [--stepwise]{.title-ref}.</p>
</li>
<li>
<p><a
href="https://redirect.github.com/pytest-dev/pytest/issues/11758">#11758</a>:
Fixed <code>IndexError: string index out of range</code> crash in
<code>if highlighted[-1] == &quot;\n&quot; and source[-1] !=
&quot;\n&quot;</code>.
This bug was introduced in pytest 8.0.0rc1.</p>
</li>
<li>
<p><a
href="https://redirect.github.com/pytest-dev/pytest/issues/9765">#9765</a>,
<a
href="https://redirect.github.com/pytest-dev/pytest/issues/11816">#11816</a>:
Fixed a frustrating bug that afflicted some users with the only error
being <code>assert mod not in mods</code>. The issue was caused by the
fact that <code>str(Path(mod))</code> and <code>mod.__file__</code>
don't necessarily produce the same string, and was being erroneously
used interchangably in some places in the code.</p>
<p>This fix also broke the internal API of
<code>PytestPluginManager.consider_conftest</code> by introducing a new
parameter -- we mention this in case it is being used by external code,
even if marked as <em>private</em>.</p>
</li>
</ul>
<h2>pytest 8.0.0rc1 (2023-12-30)</h2>
<p>See <a
href="https://docs.pytest.org/en/latest/changelog.html#pytest-8-0-0rc1-2023-12-30">https://docs.pytest.org/en/latest/changelog.html#pytest-8-0-0rc1-2023-12-30</a>
for the rendered changelog.</p>
<h2>Breaking Changes</h2>
<h3>Old Deprecations Are Now Errors</h3>
<ul>
<li>
<p><a
href="https://redirect.github.com/pytest-dev/pytest/issues/7363">#7363</a>:
<strong>PytestRemovedIn8Warning deprecation warnings are now errors by
default.</strong></p>
<p>Following our plan to remove deprecated features with as little
disruption as possible, all warnings of type
<code>PytestRemovedIn8Warning</code> now generate errors instead of
warning messages by default.</p>
<p><strong>The affected features will be effectively removed in pytest
8.1</strong>, so please consult the
<code>deprecations</code>{.interpreted-text role=&quot;ref&quot;}
section in the docs for directions on how to update existing code.</p>
<p>In the pytest <code>8.0.X</code> series, it is possible to change the
errors back into warnings as a stopgap measure by adding this to your
<code>pytest.ini</code> file:</p>
<pre lang="ini"><code>[pytest]
</code></pre>
</li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="478f8233bc"><code>478f823</code></a>
Prepare release version 8.0.0</li>
<li><a
href="608590097a"><code>6085900</code></a>
[8.0.x] fix: avoid rounding microsecond to <code>1_000_000</code> (<a
href="https://redirect.github.com/pytest-dev/pytest/issues/11863">#11863</a>)</li>
<li><a
href="3b41c65c81"><code>3b41c65</code></a>
[8.0.x] Escape skip reason in junitxml (<a
href="https://redirect.github.com/pytest-dev/pytest/issues/11845">#11845</a>)</li>
<li><a
href="747072ad26"><code>747072a</code></a>
[8.0.x] Update docstring of scripts/generate-gh-release-notes.py (<a
href="https://redirect.github.com/pytest-dev/pytest/issues/11768">#11768</a>)</li>
<li><a
href="011a475baf"><code>011a475</code></a>
Properly attach packages to the GH release notes (<a
href="https://redirect.github.com/pytest-dev/pytest/issues/11839">#11839</a>)
(<a
href="https://redirect.github.com/pytest-dev/pytest/issues/11840">#11840</a>)</li>
<li><a
href="97960bdd14"><code>97960bd</code></a>
Merge pull request <a
href="https://redirect.github.com/pytest-dev/pytest/issues/11835">#11835</a>
from pytest-dev/release-8.0.0rc2</li>
<li><a
href="6be0a3cbf7"><code>6be0a3c</code></a>
Prepare release version 8.0.0rc2</li>
<li><a
href="44ffe07165"><code>44ffe07</code></a>
Merge pull request <a
href="https://redirect.github.com/pytest-dev/pytest/issues/11837">#11837</a>
from pytest-dev/backport-11836-to-8.0.x</li>
<li><a
href="14ecb04973"><code>14ecb04</code></a>
[8.0.x] testing: temporarily disable test due to hypothesis issue</li>
<li><a
href="41c8dabee3"><code>41c8dab</code></a>
Merge pull request <a
href="https://redirect.github.com/pytest-dev/pytest/issues/11831">#11831</a>
from bluetech/backport-11825-to-8.0.x</li>
<li>Additional commits viewable in <a
href="https://github.com/pytest-dev/pytest/compare/7.4.4...8.0.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=pytest&package-manager=pip&previous-version=7.4.4&new-version=8.0.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-02-22 00:32:48 +01:00
.github chore(deps): bump actions/setup-python from 4 to 5 (#165) 2024-01-12 23:54:32 +01:00
ansibleplaybookgrapher chore(deps): update ansible-core requirement from <2.16,>=2.15 to >=2.15,<2.17 (#164) 2024-01-29 00:08:05 +01:00
img Initial support for mermaidjs (#144) 2023-05-13 14:41:07 +02:00
tests chore(deps): bump pytest from 7.4.4 to 8.0.0 (#171) 2024-02-22 00:32:48 +01:00
.gitignore Initial support for mermaidjs (#144) 2023-05-13 14:41:07 +02:00
CHANGELOG.md doc: release v2.1.1 (add full changelog link) 2023-12-27 23:29:01 +01:00
LICENSE Use the correct LICENSE GPLv3 (#100) 2022-01-17 00:12:32 +01:00
Makefile Support for ansible-core 2.15 (#151) 2023-10-01 11:30:32 +02:00
MANIFEST.in fix bug where the data files are not included in the package 2017-11-08 17:49:18 +01:00
README.md docs: Missing word in the readme 2024-01-31 23:13:57 +01:00
requirements.txt chore(deps): update ansible-core requirement from <2.16,>=2.15 to >=2.15,<2.17 (#164) 2024-01-29 00:08:05 +01:00
setup.cfg Add ability to run the tests with "python setup.py test" 2019-02-18 22:21:13 +01:00
setup.py chore(deps): update ansible-core requirement from <2.14,>=2.12 to >=2.12,<2.15 (#134) 2023-04-12 16:25:35 +02:00

Ansible Playbook Grapher

Testing PyPI version Coverage Status

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

Inspired by Ansible Inventory Grapher.

Features

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 whether if 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 others 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..
  • Filer tasks based on tags
  • Export the dot file used to generate the graph with Graphviz.

Prerequisites

  • Python 3.10 at least. Might work with some previous versions but the code is NOT tested against them. See support matrix.
  • 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.
    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

pip install ansible-playbook-grapher

Renderers

At the time of writing, two renderers are supported:

  1. graphviz (default): Generate the graph in SVG. It has more features and is more tested: open protocol, highlight linked nodes...
  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. Early support.

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

Usage

ansible-playbook-grapher tests/fixtures/example.yml

Example

ansible-playbook-grapher --include-role-tasks  tests/fixtures/with_roles.yml

Example

ansible-playbook-grapher tests/fixtures/with_block.yml

Example

ansible-playbook-grapher --include-role-tasks --renderer mermaid-flowchart tests/fixtures/multi-plays.yml
---
title: Ansible Playbook Grapher
---
%%{ init: { "flowchart": { "curve": "bumpX" } } }%%
flowchart LR
	%% Start of the playbook 'tests/fixtures/multi-plays.yml'
	playbook_34b89e53("tests/fixtures/multi-plays.yml")
		%% Start of the play 'Play: all (0)'
		play_8c4134b8["Play: all (0)"]
		style play_8c4134b8 fill:#656f5d,color:#ffffff
		playbook_34b89e53 --> |"1"| play_8c4134b8
		linkStyle 0 stroke:#656f5d,color:#656f5d
			pre_task_dd2c1b7d["[pre_task]  Pretask"]
			style pre_task_dd2c1b7d stroke:#656f5d,fill:#ffffff
			play_8c4134b8 --> |"1"| pre_task_dd2c1b7d
			linkStyle 1 stroke:#656f5d,color:#656f5d
			pre_task_bc33639f["[pre_task]  Pretask 2"]
			style pre_task_bc33639f stroke:#656f5d,fill:#ffffff
			play_8c4134b8 --> |"2"| pre_task_bc33639f
			linkStyle 2 stroke:#656f5d,color:#656f5d
			%% Start of the role 'fake_role'
			play_8c4134b8 --> |"3"| role_f4e6fb4d
			linkStyle 3 stroke:#656f5d,color:#656f5d
			role_f4e6fb4d("[role] fake_role")
			style role_f4e6fb4d fill:#656f5d,color:#ffffff,stroke:#656f5d
				task_94f7fc58[" fake_role : Debug 1"]
				style task_94f7fc58 stroke:#656f5d,fill:#ffffff
				role_f4e6fb4d --> |"1 [when: ansible_distribution == 'Debian']"| task_94f7fc58
				linkStyle 4 stroke:#656f5d,color:#656f5d
				task_bd56c6b5[" fake_role : Debug 2"]
				style task_bd56c6b5 stroke:#656f5d,fill:#ffffff
				role_f4e6fb4d --> |"2 [when: ansible_distribution == 'Debian']"| task_bd56c6b5
				linkStyle 5 stroke:#656f5d,color:#656f5d
				task_4f51a1cc[" fake_role : Debug 3 with double quote &#34;here&#34; in the name"]
				style task_4f51a1cc stroke:#656f5d,fill:#ffffff
				role_f4e6fb4d --> |"3 [when: ansible_distribution == 'Debian']"| task_4f51a1cc
				linkStyle 6 stroke:#656f5d,color:#656f5d
			%% End of the role 'fake_role'
			%% Start of the role 'display_some_facts'
			play_8c4134b8 --> |"4"| role_497b8470
			linkStyle 7 stroke:#656f5d,color:#656f5d
			role_497b8470("[role] display_some_facts")
			style role_497b8470 fill:#656f5d,color:#ffffff,stroke:#656f5d
				task_984b3c44[" display_some_facts : ansible_architecture"]
				style task_984b3c44 stroke:#656f5d,fill:#ffffff
				role_497b8470 --> |"1"| task_984b3c44
				linkStyle 8 stroke:#656f5d,color:#656f5d
				task_3cb4a46c[" display_some_facts : ansible_date_time"]
				style task_3cb4a46c stroke:#656f5d,fill:#ffffff
				role_497b8470 --> |"2"| task_3cb4a46c
				linkStyle 9 stroke:#656f5d,color:#656f5d
				task_715c2049[" display_some_facts : Specific included task for Debian"]
				style task_715c2049 stroke:#656f5d,fill:#ffffff
				role_497b8470 --> |"3"| task_715c2049
				linkStyle 10 stroke:#656f5d,color:#656f5d
			%% End of the role 'display_some_facts'
			task_d8b579ea["[task]  Add backport {{backport}}"]
			style task_d8b579ea stroke:#656f5d,fill:#ffffff
			play_8c4134b8 --> |"5"| task_d8b579ea
			linkStyle 11 stroke:#656f5d,color:#656f5d
			task_99117197["[task]  Install packages"]
			style task_99117197 stroke:#656f5d,fill:#ffffff
			play_8c4134b8 --> |"6"| task_99117197
			linkStyle 12 stroke:#656f5d,color:#656f5d
			post_task_f789bda0["[post_task]  Posttask"]
			style post_task_f789bda0 stroke:#656f5d,fill:#ffffff
			play_8c4134b8 --> |"7"| post_task_f789bda0
			linkStyle 13 stroke:#656f5d,color:#656f5d
			post_task_08755b4b["[post_task]  Posttask 2"]
			style post_task_08755b4b stroke:#656f5d,fill:#ffffff
			play_8c4134b8 --> |"8"| post_task_08755b4b
			linkStyle 14 stroke:#656f5d,color:#656f5d
		%% End of the play 'Play: all (0)'
		%% Start of the play 'Play: database (0)'
		play_40fea3c6["Play: database (0)"]
		style play_40fea3c6 fill:#2370a9,color:#ffffff
		playbook_34b89e53 --> |"2"| play_40fea3c6
		linkStyle 15 stroke:#2370a9,color:#2370a9
			%% Start of the role 'fake_role'
			play_40fea3c6 --> |"1"| role_38fdd7bb
			linkStyle 16 stroke:#2370a9,color:#2370a9
			role_38fdd7bb("[role] fake_role")
			style role_38fdd7bb fill:#2370a9,color:#ffffff,stroke:#2370a9
				task_54a811a1[" fake_role : Debug 1"]
				style task_54a811a1 stroke:#2370a9,fill:#ffffff
				role_38fdd7bb --> |"1 [when: ansible_distribution == 'Debian']"| task_54a811a1
				linkStyle 17 stroke:#2370a9,color:#2370a9
				task_0400749b[" fake_role : Debug 2"]
				style task_0400749b stroke:#2370a9,fill:#ffffff
				role_38fdd7bb --> |"2 [when: ansible_distribution == 'Debian']"| task_0400749b
				linkStyle 18 stroke:#2370a9,color:#2370a9
				task_e453cadd[" fake_role : Debug 3 with double quote &#34;here&#34; in the name"]
				style task_e453cadd stroke:#2370a9,fill:#ffffff
				role_38fdd7bb --> |"3 [when: ansible_distribution == 'Debian']"| task_e453cadd
				linkStyle 19 stroke:#2370a9,color:#2370a9
			%% End of the role 'fake_role'
			%% Start of the role 'display_some_facts'
			play_40fea3c6 --> |"2"| role_b05b7094
			linkStyle 20 stroke:#2370a9,color:#2370a9
			role_b05b7094("[role] display_some_facts")
			style role_b05b7094 fill:#2370a9,color:#ffffff,stroke:#2370a9
				task_153db06e[" display_some_facts : ansible_architecture"]
				style task_153db06e stroke:#2370a9,fill:#ffffff
				role_b05b7094 --> |"1"| task_153db06e
				linkStyle 21 stroke:#2370a9,color:#2370a9
				task_13df99ce[" display_some_facts : ansible_date_time"]
				style task_13df99ce stroke:#2370a9,fill:#ffffff
				role_b05b7094 --> |"2"| task_13df99ce
				linkStyle 22 stroke:#2370a9,color:#2370a9
				task_369b5720[" display_some_facts : Specific included task for Debian"]
				style task_369b5720 stroke:#2370a9,fill:#ffffff
				role_b05b7094 --> |"3"| task_369b5720
				linkStyle 23 stroke:#2370a9,color:#2370a9
			%% End of the role 'display_some_facts'
		%% End of the play 'Play: database (0)'
		%% Start of the play 'Play: webserver (0)'
		play_a68ff4e7["Play: webserver (0)"]
		style play_a68ff4e7 fill:#a905c7,color:#ffffff
		playbook_34b89e53 --> |"3"| play_a68ff4e7
		linkStyle 24 stroke:#a905c7,color:#a905c7
			%% Start of the role 'nested_include_role'
			play_a68ff4e7 --> |"1"| role_8bcf64e2
			linkStyle 25 stroke:#a905c7,color:#a905c7
			role_8bcf64e2("[role] nested_include_role")
			style role_8bcf64e2 fill:#a905c7,color:#ffffff,stroke:#a905c7
				task_bd87cdf3[" nested_include_role : Ensure postgresql is at the latest version"]
				style task_bd87cdf3 stroke:#a905c7,fill:#ffffff
				role_8bcf64e2 --> |"1"| task_bd87cdf3
				linkStyle 26 stroke:#a905c7,color:#a905c7
				task_d7674c4b[" nested_include_role : Ensure that postgresql is started"]
				style task_d7674c4b stroke:#a905c7,fill:#ffffff
				role_8bcf64e2 --> |"2"| task_d7674c4b
				linkStyle 27 stroke:#a905c7,color:#a905c7
				%% Start of the role 'display_some_facts'
				role_8bcf64e2 --> |"3 [when: x is not defined]"| role_806214e1
				linkStyle 28 stroke:#a905c7,color:#a905c7
				role_806214e1("[role] display_some_facts")
				style role_806214e1 fill:#a905c7,color:#ffffff,stroke:#a905c7
					task_b1fb63fd[" display_some_facts : ansible_architecture"]
					style task_b1fb63fd stroke:#a905c7,fill:#ffffff
					role_806214e1 --> |"1"| task_b1fb63fd
					linkStyle 29 stroke:#a905c7,color:#a905c7
					task_4a1319fd[" display_some_facts : ansible_date_time"]
					style task_4a1319fd stroke:#a905c7,fill:#ffffff
					role_806214e1 --> |"2"| task_4a1319fd
					linkStyle 30 stroke:#a905c7,color:#a905c7
					task_175005a1[" display_some_facts : Specific included task for Debian"]
					style task_175005a1 stroke:#a905c7,fill:#ffffff
					role_806214e1 --> |"3"| task_175005a1
					linkStyle 31 stroke:#a905c7,color:#a905c7
				%% End of the role 'display_some_facts'
				%% Start of the role 'fake_role'
				role_8bcf64e2 --> |"4"| role_557d6933
				linkStyle 32 stroke:#a905c7,color:#a905c7
				role_557d6933("[role] fake_role")
				style role_557d6933 fill:#a905c7,color:#ffffff,stroke:#a905c7
					task_1fa41f3c[" fake_role : Debug 1"]
					style task_1fa41f3c stroke:#a905c7,fill:#ffffff
					role_557d6933 --> |"1"| task_1fa41f3c
					linkStyle 33 stroke:#a905c7,color:#a905c7
					task_2841d72b[" fake_role : Debug 2"]
					style task_2841d72b stroke:#a905c7,fill:#ffffff
					role_557d6933 --> |"2"| task_2841d72b
					linkStyle 34 stroke:#a905c7,color:#a905c7
					task_e5fef12a[" fake_role : Debug 3 with double quote &#34;here&#34; in the name"]
					style task_e5fef12a stroke:#a905c7,fill:#ffffff
					role_557d6933 --> |"3"| task_e5fef12a
					linkStyle 35 stroke:#a905c7,color:#a905c7
				%% End of the role 'fake_role'
			%% End of the role 'nested_include_role'
			%% Start of the role 'display_some_facts'
			play_a68ff4e7 --> |"2"| role_2720d5bc
			linkStyle 36 stroke:#a905c7,color:#a905c7
			role_2720d5bc("[role] display_some_facts")
			style role_2720d5bc fill:#a905c7,color:#ffffff,stroke:#a905c7
				task_4d8d8def[" display_some_facts : ansible_architecture"]
				style task_4d8d8def stroke:#a905c7,fill:#ffffff
				role_2720d5bc --> |"1"| task_4d8d8def
				linkStyle 37 stroke:#a905c7,color:#a905c7
				task_58aea4f6[" display_some_facts : ansible_date_time"]
				style task_58aea4f6 stroke:#a905c7,fill:#ffffff
				role_2720d5bc --> |"2"| task_58aea4f6
				linkStyle 38 stroke:#a905c7,color:#a905c7
				task_800f91e9[" display_some_facts : Specific included task for Debian"]
				style task_800f91e9 stroke:#a905c7,fill:#ffffff
				role_2720d5bc --> |"3"| task_800f91e9
				linkStyle 39 stroke:#a905c7,color:#a905c7
			%% End of the role 'display_some_facts'
		%% End of the play 'Play: webserver (0)'
	%% End of the playbook 'tests/fixtures/multi-plays.yml'

Note on block: Since blocks are 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:

usage: ansible-playbook-grapher [-h] [-v] [-i INVENTORY]
                                [--include-role-tasks] [-s] [--view]
                                [-o OUTPUT_FILENAME]
                                [--open-protocol-handler {default,vscode,custom}]
                                [--open-protocol-custom-formats OPEN_PROTOCOL_CUSTOM_FORMATS]
                                [--group-roles-by-name]
                                [--renderer {graphviz,mermaid-flowchart}]
                                [--renderer-mermaid-directive RENDERER_MERMAID_DIRECTIVE]
                                [--renderer-mermaid-orientation {TD,RL,BT,RL,LR}]
                                [--version] [-t TAGS] [--skip-tags SKIP_TAGS]
                                [--vault-id VAULT_IDS]
                                [--ask-vault-password | --vault-password-file VAULT_PASSWORD_FILES]
                                [-e EXTRA_VARS]
                                playbooks [playbooks ...]

Make graphs from your Ansible Playbooks.

positional arguments:
  playbooks             Playbook(s) to graph

options:
  --ask-vault-password, --ask-vault-pass
                        ask for vault password
  --group-roles-by-name
                        When rendering the graph, only a single role will be
                        display for all roles having the same names. Default:
                        False
  --include-role-tasks  Include the tasks of the role in the graph.
  --open-protocol-custom-formats OPEN_PROTOCOL_CUSTOM_FORMATS
                        The custom formats to use as URLs for the nodes in the
                        graph. Required if --open-protocol-handler is set to
                        custom. You should provide a JSON formatted string
                        like: {"file": "", "folder": ""}. Example: If you want
                        to open folders (roles) inside the browser and files
                        (tasks) in vscode, set it to: '{"file":
                        "vscode://file/{path}:{line}:{column}", "folder":
                        "{path}"}'. path: the absolute path to the file
                        containing the the plays/tasks/roles. line/column: the
                        position of the plays/tasks/roles in the file. You can
                        optionally add the attribute "remove_from_path" to
                        remove some parts of the path if you want relative
                        paths.
  --open-protocol-handler {default,vscode,custom}
                        The protocol to use to open the nodes when double-
                        clicking on them in your SVG viewer. Your SVG viewer
                        must support double-click and Javascript. The
                        supported values are 'default', 'vscode' and 'custom'.
                        For 'default', the URL will be the path to the file or
                        folders. When using a browser, it will open or
                        download them. For 'vscode', the folders and files
                        will be open with VSCode. For 'custom', you need to
                        set a custom format with --open-protocol-custom-
                        formats.
  --renderer {graphviz,mermaid-flowchart}
                        The renderer to use to generate the graph. Default:
                        graphviz
  --renderer-mermaid-directive RENDERER_MERMAID_DIRECTIVE
                        The directive for the mermaid renderer. Can be used to
                        customize the output: fonts, theme, curve etc. More
                        info at https://mermaid.js.org/config/directives.html.
                        Default: '%%{ init: { "flowchart": { "curve": "bumpX" } } }%%'
  --renderer-mermaid-orientation {TD,RL,BT,RL,LR}
                        The orientation of the flow chart. Default: 'LR'
  --skip-tags SKIP_TAGS
                        only run plays and tasks whose tags do not match these
                        values
  --vault-id VAULT_IDS  the vault identity to use
  --vault-password-file VAULT_PASSWORD_FILES, --vault-pass-file VAULT_PASSWORD_FILES
                        vault password file
  --version             show program's version number and exit
  --view                Automatically open the resulting SVG file with your
                        systems default viewer application for the file type
  -e EXTRA_VARS, --extra-vars EXTRA_VARS
                        set additional variables as key=value or YAML/JSON, if
                        filename prepend with @
  -h, --help            show this help message and exit
  -i INVENTORY, --inventory INVENTORY
                        specify inventory host path or comma separated host
                        list.
  -o OUTPUT_FILENAME, --output-file-name OUTPUT_FILENAME
                        Output filename without the '.svg' extension. Default:
                        <playbook>.svg
  -s, --save-dot-file   Save the graphviz dot file used to generate the graph.
  -t TAGS, --tags TAGS  only run plays and tasks tagged with these values
  -v, --verbose         Causes Ansible to print more debug messages. Adding
                        multiple -v will increase the verbosity, the builtin
                        plugins currently evaluate up to -vvvvvv. A reasonable
                        level to start is -vvv, connection debugging might
                        require -vvvv.

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

  • 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 tasks 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.

Contribution

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

Dev environment

To setup a new development environment :

  • Install graphviz (see above)
  • (cd tests && pip install -r requirements_tests.txt)

Run the tests and open the generated files in your systems default viewer application:

export TEST_VIEW_GENERATED_FILE=1
make test # run all tests

The graphs are generated in the folder tests/generated-svgs. They are also generated as artefacts in Github Actions. Feel free to look at them when submitting PRs.

Lint and format

The project uses black to format the code. Run black . to format.

License

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

See LICENSE for the full text