Summary
ansible-inventory-grapher creates a dot file suitable for use by graphviz
Requires:
- ansible
- graphviz
Getting started
pip install ansible-inventory-grapher
Usage
Usage: ansible-inventory-grapher [options] pattern1 [pattern2...]
Options:
--version show program's version number and exit
-h, --help show this help message and exit
-i INVENTORY specify inventory host file [/etc/ansible/hosts]
-d DIRECTORY Location to output resulting files [current directory]
-o FORMAT, --format=FORMAT
python format string to name output files (e.g.
{}.dot) [defaults to stdout]
-q, --no-variables Turn off variable display in default template
-t TEMPLATE path to jinja2 template used for creating output
-T print default template
-a ATTRIBUTES include top-level graphviz attributes from
http://www.graphviz.org/doc/info/attrs.html
[rankdir=TB;]
--ask-vault-pass prompt for vault password
--vault-password-file=VAULT_PASSWORD_FILE
Location of file with cleartext vault password
Using the example inventory in https://github.com/willthames/ansible-ec2-example, we can generate the dot files for two of the example web servers using:
bin/ansible-inventory-grapher -i ../ansible-ec2-example/inventory/hosts \
prod-web-server-78a prod-web-server-28a \
-d test --format "test-{hostname}.dot"
You can add the -a option to insert a string with graphviz attributes (http://www.graphviz.org/doc/info/attrs.html) to apply to the root level of the graph. Some fun examples:
# transpose the tree so it grows from left-right instead of top-bottom
-a "rankdir=LR;"
# circular layout, with group nodes shaded grey
-a "layout=circo; overlap=false; splines=polyline;\
node [ style=filled fillcolor=lightgrey ]"
# orthogonal, UML-like inheritance connectors
-a "rankdir=LR; splines=ortho; ranksep=2;\
node [ width=5 style=filled fillcolor=lightgrey ];\
edge [ dir=back arrowtail=empty ];"
You can replace the default template (which can be seen by passing the -T variable to ansible-inventory-grapher) with a template file that can be
passed with the -t option.
The resulting graphs can then be converted to pngs using:
for f in test/*.dot ; do dot -Tpng -o test/`basename $f .dot`.png $f; done
Or the whole thing can now be done in one pipeline (only works for one pattern) straight to image viewer (imagemagick's display in this example)
bin/ansible-inventory-grapher -i ../ansible-ec2-example/inventory/hosts \
prod-web-server-1a | dot -Tpng | display png:-
This works with valid Ansible patterns now although only hosts and groups have been tested.
Metadata
Release files for ansible-inventory-grapher 2.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ansible_inventory_grapher-2.6.0.tar.gz | 19.2 kB | Without provenance | Details for ansible_inventory_grapher-2.6.0.tar.gz |
Release files / ansible_inventory_grapher-2.6.0.tar.gz
| Download URL | ansible_inventory_grapher-2.6.0.tar.gz |
|---|---|
| Size | 19.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7a782e3f50e11f6dec8f3663e063ac906eff292a628be7bd3cc473faec5a3d19
|
|
BLAKE2b-256 checksum How to use checksums |
a04c996a1948325eef46ad6beacf0d259540ec9846dcdb69b9c43da3b9d38bc0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.4
|
Security for ansible-inventory-grapher 2.6.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.