Question:
is it possible to use the result of Jinja2 filters in conditions in ansible playbooks?
I’m trying to get this working, but without success:
1 2 |
{% if (item | ipv4) %}{{ item }}{% else %}{{ lookup('dig', item) }}{% endif %}} |
where item in my current test is set to localhost (and could be any other private or public domain).
Should do: If item is an IPv4 address the adress should be returned, otherwise it should be “converted” (DNS lookup with dig) to an IPv4 address – but it always is returning the hostname.
Any idea?
Thanks in advance
Matthias
Answer:
Try
1 2 |
{{ item if (item | ipv4) else lookup('dig',item) }} |