Iterate over unique list created from string split
<p>I have a list of domains:</p>

<pre><code>---
domains:
 - foo.bar
 - baz.bar
</code></pre>

<p>I have tasks, where I need to iterate over these domains, extract domain tail, make an unique list of these tails and then create directories named by these tails.</p>

<p>Something like this but AFAIK jinja2 doesn't support list comprehension:</p>

<pre><code>---
- name: Ensure all directories exist
  file:
    path: "/tmp/sandbox/{{ item }}"
    state: directory
  with_items: "[domain.split('.')[-1] for domain in domains] | unique"
</code></pre>

<p>Is it possible or do I need to create a custom jinja2 filter? Will this work?</p>

<pre><code>---
- name: Ensure all directories exist
  file:
    path: "/tmp/sandbox/{{ item }}"
    state: directory
  with_items: "{{ domain_tails | my_custom_filter }}"
</code></pre>

<p>Thanks!</p>