• Stars
    star
    411
  • Rank 104,739 (Top 3 %)
  • Language
    Python
  • License
    GNU General Publi...
  • Created over 10 years ago
  • Updated about 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
224
star
2

kubernetes-validate

Python
44
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
9
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
5
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

ansible-hooks

Shell
3
star
19

devops-bris-ansible

Ruby
3
star
20

devopsweeklyindex

scripts for indexing devops weekly archive
Python
3
star
21

rails_sql_views

Rails SQL Views project extracted from ActiveWarehouse
Ruby
3
star
22

khaleesi

Ansible framework for setting up OpenStack test environments
Python
2
star
23

whatisdevops

HTML
2
star
24

listcircles

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

kubernetes-the-ansible-way

Python
2
star
26

ansible-brisbane-june-2017

HTML
2
star
27

wordle-guesses

Python
2
star
28

docker-debug-ts

TypeScript
2
star
29

playbook-versioning-example

2
star
30

firefox-ssl-research

2
star
31

docker-debug

Python
1
star
32

fakates

Python
1
star
33

mysql_setup

1
star
34

terraform-kubernetes-module-namespaces

HCL
1
star
35

jmx-perms

Java
1
star
36

postgresql-role

1
star
37

terraform-kubernetes-module-fluent-bit

HCL
1
star
38

terraform-willtham.es

HCL
1
star
39

db_testing

Python
1
star
40

devopsdays2014

JavaScript
1
star
41

client_9.4_setup

1
star
42

ansible-demo-docker-debug

1
star
43

terraform-civo-kubernetes

HCL
1
star
44

ansible-demo-common

1
star
45

pg_setup

1
star
46

jmc

The GitHub repo for JDK Mission Control
Java
1
star
47

copy_with_null_items

1
star
48

terraform-kubernetes-module-cilium

HCL
1
star
49

pgpool

Shell
1
star
50

ansible-jenkins-ci

Python
1
star
51

training

Python
1
star
52

ansible-brisbane-07-2016

CSS
1
star
53

badmeta

1
star
54

terraform-kubernetes-module-docker-debug

HCL
1
star
55

git-another-dep

1
star
56

willtham.es

CSS
1
star
57

terraform-kubernetes-module-ingress-nginx

HCL
1
star
58

geekforum-2014-01

JavaScript
1
star
59

env_dashboard

Python
1
star
60

clojure-books

fiddling around with clojure
Clojure
1
star
61

terraform-kubernetes-module-grafana

HCL
1
star
62

strava_activities

Python
1
star
63

common_setup

Perl
1
star
64

dynamic_include_test

1
star
65

aws-hipaa

1
star
66

filesrepo

Python
1
star
67

terraform-kubernetes-module-prometheus

HCL
1
star
68

opentelemetry-exporter-honeycomb

TypeScript
1
star
69

ansible-bris-nov-2017

HTML
1
star
70

ansible-bris-oct-2016

HTML
1
star
71

terraform-module-bug-test

1
star
72

terraform-kubernetes-module-civo-external-dns

HCL
1
star
73

weather

Python
1
star
74

adventofcode

Rust
1
star
75

application-operator-example

Python
1
star
76

opentracing-processor

Go
1
star
77

ansible-blog-examples

Example playbooks from posts on the Ansible blog (https://www.ansible.com/blog)
Python
1
star
78

otre

Opentracing Rules Engine
Go
1
star
79

terraform-kubernetes-module-otel-collector

HCL
1
star
80

openshift-restclient-python

Python client for the OpenShift API
Python
1
star
81

opentelemetry-tests

JavaScript
1
star
82

terraform-kubernetes-module-civo-cert-manager

HCL
1
star
83

devops-bris-ignite

HTML
1
star
84

urllib_kerberos

Python
1
star
85

ansible-role-vpc

1
star
86

d3

d3
JavaScript
1
star
87

ansible-demo-kuard

1
star
88

terraform-civo

HCL
1
star