title: Ansible | Set_fact with condition
body: <p>I have the list:</p>
  <pre><code>val_list:
      - val: &quot;D&quot;
      - val: &quot;A&quot;
      - val: &quot;B&quot;
      - val: &quot;C&quot;
  </code></pre>
  <p>I would like to set variable true if list contain <code>val: B</code> without creating register variable task, for example:</p>
  <pre><code>- set_fact:
      containB: false
  
  - set_fact:
      containB: true
    when: item.val=='B'
    with_items
      - &quot;{{ val_list }}&quot;
  </code></pre>
  <p>I would like to convert to something like that:</p>
  <pre><code>- set_fact: 
      containB: true if item.val=='B' | default(false)
  #or containB: true if any val in val_list is 'B'
    with_items
      - &quot;{{ val_list }}&quot;
  </code></pre>