Code Monkey home page Code Monkey logo

ansible-inventory-grapher's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.