title: Ansible - Checking for variable value when using "with_dict"
body: <p>I'm currently using a self-build playbook for managing webservers. I've specified the websites that should be created in another file, called sites.yml.</p>
  
  <p>So far, everything is working perfectly. Except, I would like to add Let's Encrypt support to my websites, and here comes the problem.. How?</p>
  
  <p>I'm executing various tasks based on the content of the file sites.yml. But I would like to enable Let's encrypt using a variable per site.</p>
  
  <p>My sites.yml is as follow:</p>
  
  <pre><code>sites:
    site1:
      name: site1
      server_name: site1.example.com
      document_root: /var/vhosts/site1.example.com
      environment: staging
      db_name: site1
      db_password: password
    site2:
      name: site2
      server_name: site2.example.com
      document_root: /var/vhosts/site2.staging.sddev.nl
      environment: staging
      db_name: site2
      db_password: password
  </code></pre>
  
  <p>I'd like to just add a variable like <code>letsencrypt: true</code> to enable Let's Encrypt, but how do I check for this variable in a with_dict loop? The Letsencrypt tasks should only be executed when the variable is set.</p>
  
  <p>I thought it should be something like this:</p>
  
  <pre><code>- name: LETSENCRYPT | Securing websites
    command: --COMMAND FOR OBTAINING CERTIFICATE--
    with_dict: "{{ sites }}"
    when: "site.letsencrypt = true?"
  </code></pre>
  
  <p>Can anyone give me more information for using <code>when</code> in <code>with_dict</code> loops?</p>