<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- name: debug
  debug: msg=&quot;{{ [1,2,3]|reject('odd') }}&quot;"><pre class="notranslate"><code class="notranslate">- name: debug
  debug: msg="{{ [1,2,3]|reject('odd') }}"
</code></pre></div>
<h5 dir="auto">Issue Type:</h5>
<p dir="auto">Can you help us out in labelling this by telling us what kind of ticket this this?  You can say “Bug Report”, “Feature Idea”, “Feature Pull Request”, “New Module Pull Request”, “Bugfix Pull Request”, “Documentation Report”, or “Docs Pull Request”.</p>
<h5 dir="auto">Ansible Version:</h5>
<p dir="auto">Let us know what version of Ansible you are using.  Please supply the verbatim output from running “ansible --version”.  If you're filing a ticket on a version of Ansible which is not the latest, we'd greatly appreciate it if you could retest on the latest version first.  We don't expect you to test against the development branch most of the time, but we may ask for that if you have cycles.  Thanks!</p>
<h5 dir="auto">Environment:</h5>
<p dir="auto">What OS are you running Ansible from and what OS are you managing?  Examples include RHEL 5/6, Centos 5/6, Ubuntu 12.04/13.10, *BSD, Solaris.  If this is a generic feature request or it doesn’t apply, just say “N/A”.  Not all tickets may be about operating system related things and we understand that.</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto">Please summarize your request in this space.  You will earn bonus points for being succinct, but please add enough detail so we can understand the request.  Thanks!</p>
<h5 dir="auto">Steps To Reproduce:</h5>
<p dir="auto">If this is a bug ticket, please enter the steps you use to reproduce the problem in the space below.  If this is a feature request, please enter the steps you would use to use the feature.  If an example playbook is useful, please include a short reproducer inline, indented by four spaces.  If a longer one is necessary, linking to one uploaded to gist.github.com would be great.  Much appreciated!</p>
<h5 dir="auto">Expected Results:</h5>
<p dir="auto">Please enter your expected results in this space.  When running the steps supplied above in the previous section, what did you expect to happen?  If showing example output, please indent your output by four spaces so it will render correctly in GitHub's viewer thingy.</p>
<h5 dir="auto">Actual Results:</h5>
<p dir="auto">Please enter your actual results in this space.  When running the steps supplied above, what actually happened?  If you are showing example output, please indent your output by four spaces so it will render correctly in GitHub.  Thanks again!</p>
<h5 dir="auto">Issue Type:</h5>
<p dir="auto">Bug Report</p>
<h5 dir="auto">Ansible Version:</h5>
<p dir="auto">ansible 1.8 (devel)</p>
<h5 dir="auto">Environment:</h5>
<p dir="auto">Ubuntu 12.04</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto">Some jinja filters (<code class="notranslate">select_attr</code> among others) return generators. It seems currently impossible to loop over these in playbooks. (also tested on ansible 1.6.3)</p>
<h5 dir="auto">Steps To Reproduce:</h5>
<p dir="auto">run the following playbook</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
---
- hosts: 127.0.0.1
  connection: local
  vars:
    stuff:
      - my_attr: true
        msg: 'pick me!'
      - my_attr: true
        msg: 'pick me too!'
      - my_attr: false
        msg: 'but do not pick me ...'
  tasks:
    # this works ...
    - command: /bin/echo {{ item.msg }}
      when: item.my_attr
      with_items: stuff

    # ... this works (note the explicit creation of a list) ...
    - command: /bin/echo {{ item.msg }}
      with_items: stuff|selectattr(&quot;my_attr&quot;)|list

    # ... this doesn't (but it would be nice if it would ...)
    - command: /bin/echo {{ item.msg }}
      with_items: stuff|selectattr(&quot;my_attr&quot;)"><pre class="notranslate">---
- <span class="pl-ent">hosts</span>: <span class="pl-s">127.0.0.1</span>
  <span class="pl-ent">connection</span>: <span class="pl-s">local</span>
  <span class="pl-ent">vars</span>:
    <span class="pl-ent">stuff</span>:
      - <span class="pl-ent">my_attr</span>: <span class="pl-c1">true</span>
        <span class="pl-ent">msg</span>: <span class="pl-s"><span class="pl-pds">'</span>pick me!<span class="pl-pds">'</span></span>
      - <span class="pl-ent">my_attr</span>: <span class="pl-c1">true</span>
        <span class="pl-ent">msg</span>: <span class="pl-s"><span class="pl-pds">'</span>pick me too!<span class="pl-pds">'</span></span>
      - <span class="pl-ent">my_attr</span>: <span class="pl-c1">false</span>
        <span class="pl-ent">msg</span>: <span class="pl-s"><span class="pl-pds">'</span>but do not pick me ...<span class="pl-pds">'</span></span>
  <span class="pl-ent">tasks</span>:
    <span class="pl-c"><span class="pl-c">#</span> this works ...</span>
    - <span class="pl-ent">command</span>: <span class="pl-s">/bin/echo {{ item.msg }}</span>
      <span class="pl-ent">when</span>: <span class="pl-s">item.my_attr</span>
      <span class="pl-ent">with_items</span>: <span class="pl-s">stuff</span>

    <span class="pl-c"><span class="pl-c">#</span> ... this works (note the explicit creation of a list) ...</span>
    - <span class="pl-ent">command</span>: <span class="pl-s">/bin/echo {{ item.msg }}</span>
      <span class="pl-ent">with_items</span>: <span class="pl-s">stuff|selectattr("my_attr")|list</span>

    <span class="pl-c"><span class="pl-c">#</span> ... this doesn't (but it would be nice if it would ...)</span>
    - <span class="pl-ent">command</span>: <span class="pl-s">/bin/echo {{ item.msg }}</span>
      <span class="pl-ent">with_items</span>: <span class="pl-s">stuff|selectattr("my_attr")</span></pre></div>
<h5 dir="auto">Expected Results:</h5>
<p dir="auto">all tasks doing the same thing (echoing the first two messages)</p>
<h5 dir="auto">Actual Results:</h5>
<p dir="auto">The third task fails with the the following error message:</p>
<p dir="auto"><code class="notranslate">fatal: [127.0.0.1] =&gt; One or more undefined variables: 'unicode object' has no attribute 'msg'</code></p>