title: Ansible: understanding a compound conditional when statement
body: <p>Consider this trivial ansible playbook and associated output below. Why
  does task 5 get executed? These tasks were run against debian. Task 1
  fails as expected. So, why does and'ing it with
  'ansible_lsb.major_release|int &lt; 14' make it true? Does this have 
  something to do with operator precedence?</p>
  
  <p>-jk</p>
  
  <pre><code>---
  - name: These tests run against debian
    hosts: frontend001
    vars:
      - bcbio_dir: /mnt/bcbio
      - is_ubuntu: "'{{ansible_distribution}}' == 'Ubuntu'"
      - is_debian: "'{{ansible_distribution}}' == 'Debian'"
    tasks:
      - name: 1. Expect skip because test is_ubuntu
        debug: msg="ansible distribution - {{ansible_distribution}}, release - {{ansible_distribution_release}}, {{ ansible_lsb.major_release }}"
        when: is_ubuntu 
  
      - name: 2. Expect to print msg because test is_debian
        debug: msg="ansible distribution - {{ansible_distribution}}, release - {{ansible_distribution_release}}, {{ ansible_lsb.major_release }}"
        when: is_debian
  
      - name: 3. Expect to print msg because release 7 of wheezy
        debug: msg="ansible distribution - {{ansible_distribution}}, release - {{ansible_distribution_release}}, {{ ansible_lsb.major_release }}"
        when:  ansible_lsb.major_release|int &lt; 14
  
      - name: 4. Expect to print msg because true and true is true
        debug: msg="ansible distribution - {{ansible_distribution}}, release - {{ansible_distribution_release}}, {{ ansible_lsb.major_release }}"
        when: is_debian and ansible_lsb.major_release|int &lt; 14
  
      - name: 5. Expect to skip because false and true is false
        debug: msg="ansible distribution - {{ansible_distribution}}, release - {{ansible_distribution_release}}, {{ ansible_lsb.major_release }}"
        when: is_ubuntu and ansible_lsb.major_release|int &lt; 14 
  
  
  $ ansible-playbook -i ~/.elasticluster/storage/ansible-inventory.jkcluster  zbcbio.yml 
  
  PLAY [These tests run against debian] ***************************************** 
  
  GATHERING FACTS *************************************************************** 
  ok: [frontend001]
  
  TASK: [1. Expect skip because test is_ubuntu] ********************************* 
  skipping: [frontend001]
  
  TASK: [2. Expect to print msg because test is_debian] ************************* 
  ok: [frontend001] =&gt; {
      "msg": "ansible distribution - Debian, release - wheezy, 7"
  }
  
  TASK: [3. Expect to print msg because release 7 of wheezy] ******************** 
  ok: [frontend001] =&gt; {
      "msg": "ansible distribution - Debian, release - wheezy, 7"
  }
  
  TASK: [4. Expect to print msg because true and true is true] ****************** 
  ok: [frontend001] =&gt; {
      "msg": "ansible distribution - Debian, release - wheezy, 7"
  }
  
  TASK: [5. Expect to skip because false and true is false] ********************* 
  ok: [frontend001] =&gt; {
      "msg": "ansible distribution - Debian, release - wheezy, 7"
  }
  
  PLAY RECAP ******************************************************************** 
  frontend001                : ok=5    changed=0    unreachable=0    failed=0   
  </code></pre>
  
  <p><strong>Edited</strong>: 
  Listing the changes based on tedder42's answer below in case someone is following along at home.</p>
  
  <p>1) Changed</p>
  
  <pre><code>- is_ubuntu: "'{{ansible_distribution}}' == 'Ubuntu'"
  </code></pre>
  
  <p>to </p>
  
  <pre><code>- is_ubuntu: "{{ansible_distribution == 'Ubuntu'}}"
  </code></pre>
  
  <p>2) change</p>
  
  <pre><code>when: is_ubuntu and ansible_lsb.major_release|int &lt; 14 
  </code></pre>
  
  <p>to </p>
  
  <pre><code>when: is_ubuntu|bool and ansible_lsb.major_release|int &lt; 14 
  </code></pre>
  
  <p>That did it! </p>
  
  <p>-jk</p>