I’ve created a filter plugin for use with my own project and thought it might be useful to others.
It’s a filter which takes a list of dicts which have been compacted down to reduce duplicated values between items and it will expand them out to a single flat list.
The idea is to enable more concise readable lists and flatten them down to be easily fed into a module’s ‘with_items’.
It’s awkward to explain so here is a gist with code and example data.
If you guys think it would be suitable for core, let me know and I’m happy to fix it up for consumption and PR.
If you insist on using with_items to loop over your data then I guess this is a good way to transform your config data to support that. But why not just restructure your data a little bit and use http://docs.ansible.com/ansible/playbooks_loops.html#looping-over-subelements
As I understand with_subelements would require every item in the list to have the same structure. My proposal allows a mixed structure where elements can be compacted selectively. Also my original use case was for a role which uses with_items and accepts a list of elements as an argument. This way the end user of the role can make the decision to use this structure if they feel it benefits the readability of their configuration.
The value of being able to compact lists like this is going to be in the eye of the beholder, it’s essentially syntactic sugar. I like it, I feel my config is easier to read and having the filter available means my roles don’t need to be written any differently to account for it.