Handling lists in ansible

+

I love it when a plan comes together

I wanted to combine Gist and Hugo, and I was struggling with lists in Ansible. The result is this post.

How much I like Ansible sometimes it can be rather cumbersome. Maybe I’m not using it as it should be, but selecting one item from a list was something I struggled with. I wanted to be able to make a selection at runtime depending on the value of a variable at that time.

Unfortunately Ansible doesn’t allow nesting of vars or as they call it ‘moustaches don’t stack’.
The solution is to use the ninja2 selectattr in combination with the varslookup plugin.

I created a step-by-step example in this gist

And embedding the gist in the post appeared to be a no-brainer, just use the shortcode.