how to select regex matches in jinja2?

Question:

toy example

Essentially, I want to do something like:

Which would yield:

what am I talking about?

The match filter and select filter. My issue arises from the fact that the select filter only supports unary “tests”.

I’m on Ansible 1.9.x.

my actual use case

…is closer to:

So, I want to get all the PTR records associated with an IP and then filter out all the ones that don’t fit a given regex. I’d also want to ensure that there’s only one element in the resulting list, and output that element, but that’s a different concern.

Answer:

This design pattern worked for me:

Leave a Reply