# generate ascii graph of topology based on inventory

**URL:** <https://forum.ansible.com/t/generate-ascii-graph-of-topology-based-on-inventory/14669>\
**Category:** Ansible Developer\
**Created:** [February 27, 2014, 8:28pm UTC](https://forum.ansible.com/t/generate-ascii-graph-of-topology-based-on-inventory/14669 "2014-02-27T20:28:09Z")\
**Posts on this page:** 13\
**Page:** 2

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [March 10, 2014, 8:36pm UTC](https://forum.ansible.com/t/generate-ascii-graph-of-topology-based-on-inventory/14669/21 "2014-03-10T20:36:08Z")

</div>

I finally finished my patch set into a PR:

[https://github.com/ansible/ansible/pull/6379](https://github.com/ansible/ansible/pull/6379)

/me dances fully dressed around the trees

Trevor: with this patch set you should be able to build some nice graphs or treeviews. Keep us posted!

Serge

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [March 10, 2014, 9:14pm UTC](https://forum.ansible.com/t/generate-ascii-graph-of-topology-based-on-inventory/14669/22 "2014-03-10T21:14:08Z")

</div>

Before we review the above, are there any assumptions that the inventory is actually a tree, seeing I see that in the information?

(It’s technically a graph, not a tree)

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [March 10, 2014, 9:29pm UTC](https://forum.ansible.com/t/generate-ascii-graph-of-topology-based-on-inventory/14669/23 "2014-03-10T21:29:09Z")

</div>

​Not really, saying the inventory is more of a group of mixed trees. would  
put it better, than talking about "a tree", which, yes, makes it a graph.

By stressing the word \*tree\* I'm really only talking about making sure the  
parent-child relation between groups and their respective depth is fully  
correct.

​ Serge​

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [March 10, 2014, 9:37pm UTC](https://forum.ansible.com/t/generate-ascii-graph-of-topology-based-on-inventory/14669/24 "2014-03-10T21:37:20Z")

</div>

Multiple groups of trees might be a forrest 🙂

But the branches can grow back together – this is the behavior that I want to make sure is supported, and why I say “graph”.

Further, it’s really not multiple disconnected graphs, because everything should connect at the “all” group.

It is important that this continue to be a thing.

So if nothing has changed, it’s still a graph, and life is good.

If something insists it’s a tree or does not allow graphishness, we could break some inventories.

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [March 10, 2014, 9:59pm UTC](https://forum.ansible.com/t/generate-ascii-graph-of-topology-based-on-inventory/14669/25 "2014-03-10T21:59:05Z")

</div>

> ​Multiple groups of trees might be a forrest :)​

​We need to find an excuse to think of it as cattle.​

But the branches can grow back together -- this is the behavior that I want

> to make sure is supported, and why I say "graph".

It certainly still is.​​ I think my patches are small and concise enough  
when you'' look at it.

Further, it's really not multiple disconnected graphs, because everything

> should connect at the "all" group.

Also, still is, only difference now we have a proper distinction between  
"direct parent" and "all ancestors", the latter still are parent-wise  
connecting to "all".​​

> It is important that this continue to be a thing.

Very obviously.​​

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [March 10, 2014, 10:07pm UTC](https://forum.ansible.com/t/generate-ascii-graph-of-topology-based-on-inventory/14669/26 "2014-03-10T22:07:28Z")

</div>

excellent

---

<div class="post-metadata">

**Author:** ![willthames](https://avatars.discourse-cdn.com/v4/letter/w/8dc957/32.png) [@willthames](https://forum.ansible.com/u/willthames)\
**Post date:** [April 3, 2014, 11:30am UTC](https://forum.ansible.com/t/generate-ascii-graph-of-topology-based-on-inventory/14669/27 "2014-04-03T11:30:11Z")

</div>

I’ve had a crack at generating graphviz dot files from inventory.

It’s quite opinionated, but it does work for the simple example I chose (I’m sure Serge can break it)

[http://willthames.github.io/2014/04/03/an-ansible-inventory-grapher.html](http://willthames.github.io/2014/04/03/an-ansible-inventory-grapher.html)  
[https://github.com/willthames/ansible-inventory-grapher](https://github.com/willthames/ansible-inventory-grapher)

Once any wrinkles are ironed out I’d be perfectly happy for it to go into examples/

Will

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [April 3, 2014, 12:57pm UTC](https://forum.ansible.com/t/generate-ascii-graph-of-topology-based-on-inventory/14669/28 "2014-04-03T12:57:10Z")

</div>

Cool stuff!

One of my hosts with default ansible: [http://oi57.tinypic.com/282kq4n.jpg](http://oi57.tinypic.com/282kq4n.jpg)  
Same with my improved inventory patch: [http://oi61.tinypic.com/4sbsox.jpg](http://oi61.tinypic.com/4sbsox.jpg)

Which shows me I still have a bug, as group ‘1’ should not be member of ‘all’ here neither…

BTW, my graphviz dot didn’t accept shape=record; so I left that out  
dot - graphviz version 2.26.3 (20100126.1600)  
Found a bug too, will make you a PR for that

Thanks!

Serge

---

<div class="post-metadata">

**Author:** ![willthames](https://avatars.discourse-cdn.com/v4/letter/w/8dc957/32.png) [@willthames](https://forum.ansible.com/u/willthames)\
**Post date:** [April 3, 2014, 1:07pm UTC](https://forum.ansible.com/t/generate-ascii-graph-of-topology-based-on-inventory/14669/29 "2014-04-03T13:07:32Z")

</div>

Excellent, glad to hear it works with other peoples inventory.

That’s quite an old dot, it’s four years old! (judging by version date - I’m on dot - graphviz version 2.36.0 (20140111.2315))

Better styling customisation will be good to have all round (people probably want different fonts) etc., shame dot doesn’t just have something like CSS classes (or maybe it does).

PRs welcome, just merged my first third-party one (the default filenames had quotes in it, oops)

Will

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [April 3, 2014, 1:22pm UTC](https://forum.ansible.com/t/generate-ascii-graph-of-topology-based-on-inventory/14669/30 "2014-04-03T13:22:02Z")

</div>

> That's quite an old dot, it's four years old! (judging by version date -  
> I'm on dot - graphviz version 2.36.0 (20140111.2315))

​Blame Ubuntu 13.10 ☹ or the debian upstream​

Better styling customisation will be good to have all round (people

> probably want different fonts) etc., shame dot doesn't just have something  
> like CSS classes (or maybe it does).

​I'd love to generate a graph of my full inventory 🙂 Thinking of options  
to limit depth, showing opnly groups, etc.  
​

Serge

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [April 3, 2014, 10:22pm UTC](https://forum.ansible.com/t/generate-ascii-graph-of-topology-based-on-inventory/14669/31 "2014-04-03T22:22:15Z")

</div>

This was nice to see.

As I’ve mentioned, if you want to add a pull request to [https://github.com/ansible/ansible/tree/devel/examples/scripts](https://github.com/ansible/ansible/tree/devel/examples/scripts) we’d be happy to include it.

I think graphviz usually breaks down for a large large number of things - but for simpler configs (or just showing groups, not all the hosts in them) this is definitely neat.

---

<div class="post-metadata">

**Author:** ![willthames](https://avatars.discourse-cdn.com/v4/letter/w/8dc957/32.png) [@willthames](https://forum.ansible.com/u/willthames)\
**Post date:** [April 4, 2014, 3:51am UTC](https://forum.ansible.com/t/generate-ascii-graph-of-topology-based-on-inventory/14669/32 "2014-04-04T03:51:21Z")

</div>

Did my reply to this get deleted? Please get in touch via other methods if there is a problem with my content. I can’t see anything objectionable in my message (any mention of culling links back to the all group was related to the graph, not the inventory internals code)

The script now has templating and there is a branch that reduces number of graph edges.

It’s pretty much ready to go into examples/scripts if that’s still desirable.

Will

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [April 4, 2014, 7:07am UTC](https://forum.ansible.com/t/generate-ascii-graph-of-topology-based-on-inventory/14669/33 "2014-04-04T07:07:04Z")

</div>

> Glad you like it. Still ironing out a few things (I really want to add  
> templating) and then I'll submit it into core.
> 
> I'm curious as to what people think about culling links back to the 'all'  
> group so that only groups without other parents link to all.

​​That's something I fixed in my patches to optimize the inventory, so  
hopefully something you wouldn't need to address in your script.

[Previous page](https://forum.ansible.com/t/generate-ascii-graph-of-topology-based-on-inventory/14669.md?page=1)
