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:
{% 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
Jinja2 filter is something we use to transform data held in variables. We apply filters by placing pipe symbol | after the variable followed by name of the filter. Filters can change the look and format of the source data, or even generate new data derived from the input values.
Bloom Filter is a data structure that can do this job. For understanding bloom filters, you must know what is hashing. A hash function takes input and outputs a unique identifier of fixed length which is used for identification of input.
Try
{{ item if (item | ipv4) else lookup('dig',item) }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With