title: Ansible loop break at condition
body: <p>I need first item with a certain condition. For example, in this case, I want 'banana', the first item with state: true. Sample playbook:</p>
  
  <pre><code>- hosts: localhost
    vars:
      my_fruit:
      fruits: [
        {state: false, fruit: apple},
        {state: true, fruit: banana},
        {state: true, fruit: orange},
        {state: false, fruit: pear}
      ]
    tasks:
      - name: get first fruit with state = true.
        set_fact:
          my_fruit: "{{ item.fruit }}"
        loop: "{{ fruits }}"
        when: 
          - item.state == true
          - my_fruit == ''
  
      - name: Check true fruit.
        debug:
          var: my_fruit
  
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>PLAY [localhost] ********************************************************************************************************************************************************************************************
  
  TASK [Gathering Facts] **************************************************************************************************************************************************************************************
  ok: [localhost]
  
  TASK [get first fruit with state = true.] *******************************************************************************************************************************************************************
  skipping: [localhost] =&gt; (item={'state': False, 'fruit': 'apple'}) 
  skipping: [localhost] =&gt; (item={'state': True, 'fruit': 'banana'}) 
  skipping: [localhost] =&gt; (item={'state': True, 'fruit': 'orange'}) 
  skipping: [localhost] =&gt; (item={'state': False, 'fruit': 'pear'}) 
  
  TASK [Check true fruit.] ************************************************************************************************************************************************************************************
  ok: [localhost] =&gt; {
      "my_fruit": null
  }
  
  PLAY RECAP **************************************************************************************************************************************************************************************************
  localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0
  </code></pre>
  
  <p><code>my_fruit</code> result is null, if I skip <code>- my_fruit == ''</code> condition, the result is 'orange':</p>
  
  <pre><code>PLAY [localhost] ********************************************************************************************************************************************************************************************
  
  TASK [Gathering Facts] **************************************************************************************************************************************************************************************
  ok: [localhost]
  
  TASK [get first fruit with state = true.] *******************************************************************************************************************************************************************
  skipping: [localhost] =&gt; (item={'state': False, 'fruit': 'apple'}) 
  ok: [localhost] =&gt; (item={'state': True, 'fruit': 'banana'})
  ok: [localhost] =&gt; (item={'state': True, 'fruit': 'orange'})
  skipping: [localhost] =&gt; (item={'state': False, 'fruit': 'pear'}) 
  
  TASK [Check true fruit.] ************************************************************************************************************************************************************************************
  ok: [localhost] =&gt; {
      "my_fruit": "orange"
  }
  
  PLAY RECAP **************************************************************************************************************************************************************************************************
  localhost                  : ok=3    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0 
  </code></pre>
  
  <p>How can I do to get 'banana'?</p>
  
  <p>Thanks!</p>