<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">module include_tasks</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.4.1.0
  config file = /home/xxxx/.ansible.cfg
  configured module search path = [u'/home/xxxx/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/xxxx/venv/ansible2.4-python2.7/lib/python2.7/site-packages/ansible
  executable location = /opt/xxxx/venv/ansible2.4-python2.7/bin/ansible
  python version = 2.7.13 (default, Apr 12 2017, 06:53:51) [GCC 4.4.7 20120313 (Red Hat 4.4.7-18)]
"><pre class="notranslate"><code class="notranslate">ansible 2.4.1.0
  config file = /home/xxxx/.ansible.cfg
  configured module search path = [u'/home/xxxx/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/xxxx/venv/ansible2.4-python2.7/lib/python2.7/site-packages/ansible
  executable location = /opt/xxxx/venv/ansible2.4-python2.7/bin/ansible
  python version = 2.7.13 (default, Apr 12 2017, 06:53:51) [GCC 4.4.7 20120313 (Red Hat 4.4.7-18)]

</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ANSIBLE_PIPELINING(/home/xxxx/.ansible.cfg) = True
DEFAULT_HOST_LIST(/home/xxxx/.ansible.cfg) = [u'/home/xxxx/checkouts/ansible-tree/inventory']
DEFAULT_LOG_PATH(/home/xxxx/.ansible.cfg) = /home/xxxx/ansible.log
HOST_KEY_CHECKING(/home/xxxx/.ansible.cfg) = False
INVENTORY_IGNORE_EXTS(/home/xxxx/.ansible.cfg) = ['~', '.orig', '.bak', '.ini', '.cfg', '.retry', '.pyc', '.pyo', '.txt', '.back', 'script']
MAX_FILE_SIZE_FOR_DIFF(/home/xxxx/.ansible.cfg) = 4194304
RETRY_FILES_SAVE_PATH(/home/xxxx/.ansible.cfg) = /home/xxxx"><pre class="notranslate"><code class="notranslate">ANSIBLE_PIPELINING(/home/xxxx/.ansible.cfg) = True
DEFAULT_HOST_LIST(/home/xxxx/.ansible.cfg) = [u'/home/xxxx/checkouts/ansible-tree/inventory']
DEFAULT_LOG_PATH(/home/xxxx/.ansible.cfg) = /home/xxxx/ansible.log
HOST_KEY_CHECKING(/home/xxxx/.ansible.cfg) = False
INVENTORY_IGNORE_EXTS(/home/xxxx/.ansible.cfg) = ['~', '.orig', '.bak', '.ini', '.cfg', '.retry', '.pyc', '.pyo', '.txt', '.back', 'script']
MAX_FILE_SIZE_FOR_DIFF(/home/xxxx/.ansible.cfg) = 4194304
RETRY_FILES_SAVE_PATH(/home/xxxx/.ansible.cfg) = /home/xxxx
</code></pre></div>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">Centos 6</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">When you add a when condition to include_tasks which includes a undefined variable, it processes it as True instead of trowing an undefined error.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<p dir="auto">Do not define or set VAR</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- include_tasks: task.yml
  when: VAR == &quot;yes&quot;

- debug: msg=&quot;test&quot;
  when: VAR == &quot;yes&quot;
"><pre class="notranslate">- <span class="pl-ent">include_tasks</span>: <span class="pl-s">task.yml</span>
  <span class="pl-ent">when</span>: <span class="pl-s">VAR == "yes"</span>

- <span class="pl-ent">debug</span>: <span class="pl-s">msg="test"</span>
  <span class="pl-ent">when</span>: <span class="pl-s">VAR == "yes"</span>
</pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">include_tasks should fail with "'VAR' is undefined"</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<p dir="auto">Include_tasks just gets executed and debug message fails with  "'VAR' is undefined"</p>
<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">include_tasks</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="devel version on 2018/03/24
2.6.0-100.git201803241800.d502745a4e.devel"><pre class="notranslate"><code class="notranslate">devel version on 2018/03/24
2.6.0-100.git201803241800.d502745a4e.devel
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">standart</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">centos 7.4</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">include_tasks: i.yml<br>
when: undefinded_variable == ''</p>
<p dir="auto">when condition with an undefined variable not raise error - it is always true !</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<p dir="auto">role with two files:<br>
main.yml</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- debug: msg=&quot;{{test_undef_var}}&quot;
  ignore_errors: yes

- debug: msg=&quot;{{test_undef_var}}&quot;
  when:
  - test_undef_var == ''
  ignore_errors: yes

- debug: msg=&quot;{{ansible_user}}&quot;

- name: &quot;test include_task {{test_undef_var}}&quot;
  include_tasks: test_include.yml
  when:
    - test_undef_var != ''
    - ansible_user == &quot;bond&quot;"><pre class="notranslate">- <span class="pl-ent">debug</span>: <span class="pl-s">msg="{{test_undef_var}}"</span>
  <span class="pl-ent">ignore_errors</span>: <span class="pl-s">yes</span>

- <span class="pl-ent">debug</span>: <span class="pl-s">msg="{{test_undef_var}}"</span>
  <span class="pl-ent">when</span>:
  - <span class="pl-s">test_undef_var == ''</span>
  <span class="pl-ent">ignore_errors</span>: <span class="pl-s">yes</span>

- <span class="pl-ent">debug</span>: <span class="pl-s">msg="{{ansible_user}}"</span>

- <span class="pl-ent">name</span>: <span class="pl-s"><span class="pl-pds">"</span>test include_task {{test_undef_var}}<span class="pl-pds">"</span></span>
  <span class="pl-ent">include_tasks</span>: <span class="pl-s">test_include.yml</span>
  <span class="pl-ent">when</span>:
    - <span class="pl-s">test_undef_var != ''</span>
    - <span class="pl-s">ansible_user == "bond"</span></pre></div>
<p dir="auto">test_include.yml</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- debug: msg=&quot;{{ansible_user}}&quot;

- debug: msg=&quot;{{test_undef_var}}&quot;
  ignore_errors: yes"><pre class="notranslate">- <span class="pl-ent">debug</span>: <span class="pl-s">msg="{{ansible_user}}"</span>

- <span class="pl-ent">debug</span>: <span class="pl-s">msg="{{test_undef_var}}"</span>
  <span class="pl-ent">ignore_errors</span>: <span class="pl-s">yes</span></pre></div>
<p dir="auto">playbook.yml</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- hosts:
  - all
  vars:
    - ansible_ssh_user: bond
  roles:
    - test"><pre class="notranslate">- <span class="pl-ent">hosts</span>:
  - <span class="pl-s">all</span>
  <span class="pl-ent">vars</span>:
    - <span class="pl-ent">ansible_ssh_user</span>: <span class="pl-s">bond</span>
  <span class="pl-ent">roles</span>:
    - <span class="pl-s">test</span></pre></div>
<p dir="auto">and run:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible-playbook -i 192.168.100.71, -k --diff test.yml"><pre class="notranslate"><code class="notranslate">ansible-playbook -i 192.168.100.71, -k --diff test.yml
</code></pre></div>

<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">playbook should fail on include_task with message test_undef_var is undefined</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<p dir="auto">task included without error</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="SSH password:

PLAY [all] *************************************************************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************************************************************
ok: [192.168.100.71]

TASK [test : debug] ****************************************************************************************************************************************************
fatal: [192.168.100.71]: FAILED! =&gt; {&quot;msg&quot;: &quot;The task includes an option with an undefined variable. The error was: 'test_undef_var' is undefined\n\nThe error appears to have been in '/home/robot/test1/roles/test/tasks/main.yml': line 1, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- debug: msg=\&quot;{{test_undef_var}}\&quot;\n  ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes.  Always quote template expression brackets when they\nstart a value. For instance:\n\n    with_items:\n      - {{ foo }}\n\nShould be written as:\n\n    with_items:\n      - \&quot;{{ foo }}\&quot;\n&quot;}
...ignoring

TASK [test : debug] ****************************************************************************************************************************************************
fatal: [192.168.100.71]: FAILED! =&gt; {&quot;msg&quot;: &quot;The conditional check 'test_undef_var == ''' failed. The error was: error while evaluating conditional (test_undef_var == ''): 'test_undef_var' is undefined\n\nThe error appears to have been in '/home/robot/test1/roles/test/tasks/main.yml': line 4, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- debug: msg=\&quot;{{test_undef_var}}\&quot;\n  ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes.  Always quote template expression brackets when they\nstart a value. For instance:\n\n    with_items:\n      - {{ foo }}\n\nShould be written as:\n\n    with_items:\n      - \&quot;{{ foo }}\&quot;\n&quot;}
...ignoring

TASK [test : debug] ****************************************************************************************************************************************************
ok: [192.168.100.71] =&gt; {
    &quot;msg&quot;: &quot;bond&quot;
}

TASK [test : test include_task {{test_undef_var}}] *********************************************************************************************************************
included: /home/robot/test1/roles/test/tasks/test_include.yml for 192.168.100.71

TASK [test : debug] ****************************************************************************************************************************************************
ok: [192.168.100.71] =&gt; {
    &quot;msg&quot;: &quot;bond&quot;
}

TASK [test : debug] ****************************************************************************************************************************************************
fatal: [192.168.100.71]: FAILED! =&gt; {&quot;msg&quot;: &quot;The task includes an option with an undefined variable. The error was: 'test_undef_var' is undefined\n\nThe error appears to have been in '/home/robot/test1/roles/test/tasks/test_include.yml': line 3, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- debug: msg=\&quot;{{test_undef_var}}\&quot;\n  ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes.  Always quote template expression brackets when they\nstart a value. For instance:\n\n    with_items:\n      - {{ foo }}\n\nShould be written as:\n\n    with_items:\n      - \&quot;{{ foo }}\&quot;\n&quot;}
...ignoring

PLAY RECAP *************************************************************************************************************************************************************
192.168.100.71             : ok=7    changed=0    unreachable=0    failed=0"><pre class="notranslate"><code class="notranslate">SSH password:

PLAY [all] *************************************************************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************************************************************
ok: [192.168.100.71]

TASK [test : debug] ****************************************************************************************************************************************************
fatal: [192.168.100.71]: FAILED! =&gt; {"msg": "The task includes an option with an undefined variable. The error was: 'test_undef_var' is undefined\n\nThe error appears to have been in '/home/robot/test1/roles/test/tasks/main.yml': line 1, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- debug: msg=\"{{test_undef_var}}\"\n  ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes.  Always quote template expression brackets when they\nstart a value. For instance:\n\n    with_items:\n      - {{ foo }}\n\nShould be written as:\n\n    with_items:\n      - \"{{ foo }}\"\n"}
...ignoring

TASK [test : debug] ****************************************************************************************************************************************************
fatal: [192.168.100.71]: FAILED! =&gt; {"msg": "The conditional check 'test_undef_var == ''' failed. The error was: error while evaluating conditional (test_undef_var == ''): 'test_undef_var' is undefined\n\nThe error appears to have been in '/home/robot/test1/roles/test/tasks/main.yml': line 4, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- debug: msg=\"{{test_undef_var}}\"\n  ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes.  Always quote template expression brackets when they\nstart a value. For instance:\n\n    with_items:\n      - {{ foo }}\n\nShould be written as:\n\n    with_items:\n      - \"{{ foo }}\"\n"}
...ignoring

TASK [test : debug] ****************************************************************************************************************************************************
ok: [192.168.100.71] =&gt; {
    "msg": "bond"
}

TASK [test : test include_task {{test_undef_var}}] *********************************************************************************************************************
included: /home/robot/test1/roles/test/tasks/test_include.yml for 192.168.100.71

TASK [test : debug] ****************************************************************************************************************************************************
ok: [192.168.100.71] =&gt; {
    "msg": "bond"
}

TASK [test : debug] ****************************************************************************************************************************************************
fatal: [192.168.100.71]: FAILED! =&gt; {"msg": "The task includes an option with an undefined variable. The error was: 'test_undef_var' is undefined\n\nThe error appears to have been in '/home/robot/test1/roles/test/tasks/test_include.yml': line 3, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- debug: msg=\"{{test_undef_var}}\"\n  ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes.  Always quote template expression brackets when they\nstart a value. For instance:\n\n    with_items:\n      - {{ foo }}\n\nShould be written as:\n\n    with_items:\n      - \"{{ foo }}\"\n"}
...ignoring

PLAY RECAP *************************************************************************************************************************************************************
192.168.100.71             : ok=7    changed=0    unreachable=0    failed=0
</code></pre></div>
<p dir="auto">i try with == task included</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- name: &quot;test include_task {{test_undef_var}}&quot;
  include_tasks: test_include.yml
  when:
    - test_undef_var == ''
    - ansible_user == &quot;bond&quot;"><pre class="notranslate"><code class="notranslate">- name: "test include_task {{test_undef_var}}"
  include_tasks: test_include.yml
  when:
    - test_undef_var == ''
    - ansible_user == "bond"
</code></pre></div>
<p dir="auto">include task skipped only when trye anisble_user == 'nobond'</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- name: &quot;test include_task {{test_undef_var}}&quot;
  include_tasks: test_include.yml
  when:
    - test_undef_var == ''
    - ansible_user == &quot;nobond&quot;"><pre class="notranslate"><code class="notranslate">- name: "test include_task {{test_undef_var}}"
  include_tasks: test_include.yml
  when:
    - test_undef_var == ''
    - ansible_user == "nobond"
</code></pre></div>