Host Data Hierarchy and YAML Organization

Hi there,

I am trying to create the same hierarchy that ansible provides with regard to host and group variables. Basically, key/values that are listed in group or global files are overwritten if the same pairs are listed in host files.

Has anyone done this yet? I have a feeling it’s a fairly common challenge for those trying to replace ansible for network config management. I’m running mostly Juniper devices, so I’ve been organizing the YAML files based on certain sections, e.g. system, interfaces, etc. Is there a better way to organize this data?

So far, I’ve been playing with dictionaries and trying to update keys using update() sequentially (global -> group -> host, where host variables override all). There are certain keys that I don’t want to override and instead iterate through the next level, which at this point is kinda over my head. I feel like I’m making this harder than it needs to be, but any guidance is definitely appreciated!

I’d suggest rearchitecting your data to avoid complex operations but if you want to do that you could create your own task that loads the data from various sources and merges it using whatever logic you want. There is a library that can help you doing that:

This is wonderful, thank you. I’m absolutely open to rearchitecting the data. Do you know of any sites/videos/guides that show how to organize data for thousands of devices? We only have a few devices currently, but I want to have a data model that can scale to the thousands elegantly. I’m noticing that how we organize the data is among the toughest part of automating in general. Thanks again!

BTW, the deep_merge library does exactly what I was looking to do, thank you. However, I’m still curious to hear thoughts on how others are organizing their data for larger number of devices.