title: Ansible: complicated conditions
body: <p>I want to write this piece of code in my playbook:</p>
  
  <pre><code>- debug:
      msg: hello
    when: '2 in [x*2 for x in range(1, 10)]'
  </code></pre>
  
  <p>But I have an error:</p>
  
  <pre><code>The conditional check '2 in [x*2 for x in range(1, 10)]' failed.
  The error was: template error while templating string: expected token ',',
  got 'for'.
  String: {% if 2 in [x*2 for x in range(1, 10)] %} True {% else %} False 
  </code></pre>
  
  <p>How can I rewrite it? I want to use generators for complicated conditions with <code>with_items</code>. Here is python example:</p>
  
  <pre><code>Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
  &gt;&gt;&gt; 2 in [x*2 for x in range(1, 10)]
  True
  </code></pre>