• Stars
    star
    411
  • Rank 105,247 (Top 3 %)
  • Language
    Python
  • License
    GNU General Publi...
  • Created over 10 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Summary

ansible-inventory-grapher creates a dot file suitable for use by graphviz

Requires:

  • ansible
  • graphviz

PyPI version Build Status

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

Resulting image for prod-web-server-78a

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.

More Repositories

1

ansible-review

Python
225
star
2

kubernetes-validate

Python
45
star
3

ansible-ec2-example

29
star
4

ansible-testing

Python
20
star
5

ansible-role-kube-resource

Manage Kubernetes resources through Ansible
HTML
19
star
6

devops-singapore-2016

Ruby
17
star
7

python-logging-proxy

Logging proxy
Python
17
star
8

ansiblefest2018

Python
13
star
9

aws-inkscape-symbols

Python
10
star
10

photodeck.lrdevplugin

PhotoDeck publishing plugin for Lightroom
Lua
6
star
11

explain.depesz.com

Fork of https://gitlab.com/depesz/explain.depesz.com
Perl
6
star
12

willthames.github.io

CSS
4
star
13

dotfiles

CSS
4
star
14

ansible-role-aws-lambda

Python
4
star
15

chef-on-rails

Rails-based dashboard for chef
Ruby
3
star
16

application-controller

Rust
3
star
17

role-versioning-example

3
star
18

playbook-versioning-example

3
star
19

ansible-hooks

Shell
3
star
20

devops-bris-ansible

Ruby
3
star
21

devopsweeklyindex

scripts for indexing devops weekly archive
Python
3
star
22

whatisdevops

HTML
2
star
23

listcircles

app to explore html5 and twitter api integration
Ruby
2
star
24

kubernetes-the-ansible-way

Python
2
star
25

ansible-brisbane-june-2017

HTML
2
star
26

wordle-guesses

Python
2
star
27

docker-debug-ts

TypeScript
2
star
28

firefox-ssl-research

2
star
29

docker-debug

Python
1
star
30

fakates

Python
1
star
31

mysql_setup

1
star
32

terraform-kubernetes-module-namespaces

HCL
1
star
33

jmx-perms

Java
1
star
34

postgresql-role

1
star
35

terraform-kubernetes-module-fluent-bit

HCL
1
star
36

terraform-willtham.es

HCL
1
star
37

devopsdays2014

JavaScript
1
star
38

client_9.4_setup

1
star
39

ansible-demo-docker-debug

1
star
40

terraform-civo-kubernetes

HCL
1
star
41

db_testing

Python
1
star
42

ansible-demo-common

1
star
43

pg_setup

1
star
44

copy_with_null_items

1
star
45

terraform-kubernetes-module-cilium

HCL
1
star
46

pgpool

Shell
1
star
47

ansible-jenkins-ci

Python
1
star
48

training

Python
1
star
49

ansible-brisbane-07-2016

CSS
1
star
50

badmeta

1
star
51

terraform-kubernetes-module-docker-debug

HCL
1
star
52

git-another-dep

1
star
53

willtham.es

CSS
1
star
54

terraform-kubernetes-module-ingress-nginx

HCL
1
star
55

geekforum-2014-01

JavaScript
1
star
56

env_dashboard

Python
1
star
57

clojure-books

fiddling around with clojure
Clojure
1
star
58

terraform-kubernetes-module-grafana

HCL
1
star
59

strava_activities

Python
1
star
60

dynamic_include_test

1
star
61

common_setup

Perl
1
star
62

aws-hipaa

1
star
63

filesrepo

Python
1
star
64

terraform-kubernetes-module-prometheus

HCL
1
star
65

opentelemetry-exporter-honeycomb

TypeScript
1
star
66

ansible-bris-nov-2017

HTML
1
star
67

ansible-bris-oct-2016

HTML
1
star
68

terraform-module-bug-test

1
star
69

terraform-kubernetes-module-civo-external-dns

HCL
1
star
70

weather

Python
1
star
71

adventofcode

Rust
1
star
72

application-operator-example

Python
1
star
73

opentracing-processor

Go
1
star
74

otre

Opentracing Rules Engine
Go
1
star
75

terraform-kubernetes-module-otel-collector

HCL
1
star
76

opentelemetry-tests

JavaScript
1
star
77

terraform-kubernetes-module-civo-cert-manager

HCL
1
star
78

devops-bris-ignite

HTML
1
star
79

urllib_kerberos

Python
1
star
80

ansible-role-vpc

1
star
81

d3

d3
JavaScript
1
star
82

ansible-demo-kuard

1
star
83

terraform-civo

HCL
1
star