<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">core</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="2.4.2.0 - v2.4.3.0-0.5.rc2"><pre class="notranslate"><code class="notranslate">2.4.2.0 - v2.4.3.0-0.5.rc2
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>

<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">N/A</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">wrong error generated if import_tasks found in include_tasks file</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- include_tasks: &quot;os/{{ ansible_distribution }}/main.yml&quot;
...
inside
...
- import_tasks: &quot;firewall.yml&quot;
"><pre class="notranslate">- <span class="pl-ent">include_tasks</span>: <span class="pl-s"><span class="pl-pds">"</span>os/{{ ansible_distribution }}/main.yml<span class="pl-pds">"</span></span>
...
<span class="pl-s">inside</span>
...
- <span class="pl-ent">import_tasks</span>: <span class="pl-s"><span class="pl-pds">"</span>firewall.yml<span class="pl-pds">"</span></span>
</pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">import error/lint error/any error</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="fatal: [node1]: FAILED! =&gt; {
    &quot;reason&quot;: &quot;'ansible_distribution' is undefined&quot;
}"><pre class="notranslate"><code class="notranslate">fatal: [node1]: FAILED! =&gt; {
    "reason": "'ansible_distribution' is undefined"
}
</code></pre></div>
<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="ansible 2.4.2.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.12 (default, Nov 20 2017, 18:23:56) [GCC 5.4.0 20160609]"><pre class="notranslate"><code class="notranslate">ansible 2.4.2.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.12 (default, Nov 20 2017, 18:23:56) [GCC 5.4.0 20160609]
</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(/mnt/speedyg/johnn/Documents/EclipseWS/cloud-network/ansible.cfg) = True
ANSIBLE_SSH_ARGS(/mnt/speedyg/johnn/Documents/EclipseWS/cloud-network/ansible.cfg) = -o ControlMaster=auto -o ControlPersist=300s -o UserKnownHostsFile=./ssh_known_hosts
DEFAULT_BECOME(/mnt/speedyg/johnn/Documents/EclipseWS/cloud-network/ansible.cfg) = True
DEFAULT_LOG_PATH(/mnt/speedyg/johnn/Documents/EclipseWS/cloud-network/ansible.cfg) = /mnt/speedyg/johnn/Documents/EclipseWS/cloud-network/ansible.log
DEFAULT_REMOTE_USER(/mnt/speedyg/johnn/Documents/EclipseWS/cloud-network/ansible.cfg) = automation
DEFAULT_ROLES_PATH(/mnt/speedyg/johnn/Documents/EclipseWS/cloud-network/ansible.cfg) = [u'/mnt/speedyg/johnn/Documents/EclipseWS/cloud-network/roles']"><pre class="notranslate"><code class="notranslate">ANSIBLE_PIPELINING(/mnt/speedyg/johnn/Documents/EclipseWS/cloud-network/ansible.cfg) = True
ANSIBLE_SSH_ARGS(/mnt/speedyg/johnn/Documents/EclipseWS/cloud-network/ansible.cfg) = -o ControlMaster=auto -o ControlPersist=300s -o UserKnownHostsFile=./ssh_known_hosts
DEFAULT_BECOME(/mnt/speedyg/johnn/Documents/EclipseWS/cloud-network/ansible.cfg) = True
DEFAULT_LOG_PATH(/mnt/speedyg/johnn/Documents/EclipseWS/cloud-network/ansible.cfg) = /mnt/speedyg/johnn/Documents/EclipseWS/cloud-network/ansible.log
DEFAULT_REMOTE_USER(/mnt/speedyg/johnn/Documents/EclipseWS/cloud-network/ansible.cfg) = automation
DEFAULT_ROLES_PATH(/mnt/speedyg/johnn/Documents/EclipseWS/cloud-network/ansible.cfg) = [u'/mnt/speedyg/johnn/Documents/EclipseWS/cloud-network/roles']
</code></pre></div>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">Management node: Ubuntu 16.04<br>
Remote node: Debian 9</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">Untrue/incorrect error message shown when a dynamically-determined dynamic include contains an embedded reference to an unknown file.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>


<p dir="auto">test.yml:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- hosts: all
  tasks:
  - debug: var=ansible_system
  - include_tasks: '{{ ansible_system }}.yml'"><pre class="notranslate">- <span class="pl-ent">hosts</span>: <span class="pl-s">all</span>
  <span class="pl-ent">tasks</span>:
  - <span class="pl-ent">debug</span>: <span class="pl-s">var=ansible_system</span>
  - <span class="pl-ent">include_tasks</span>: <span class="pl-s"><span class="pl-pds">'</span>{{ ansible_system }}.yml<span class="pl-pds">'</span></span></pre></div>
<p dir="auto">Linux.yml:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- import_tasks: a_file_that_does_not_exist.yml"><pre class="notranslate">- <span class="pl-ent">import_tasks</span>: <span class="pl-s">a_file_that_does_not_exist.yml</span></pre></div>
<p dir="auto">Execute command:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible-playbook -l &quot;pick_an_inventory_host&quot; test.yml"><pre class="notranslate"><code class="notranslate">ansible-playbook -l "pick_an_inventory_host" test.yml
</code></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">The debug task should execute as expected, showing the remote system's platform (expected in this case to be "Linux").</p>
<p dir="auto">For the "include_tasks" task, it should result in an error along the lines of:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="FAILED! =&gt; {&quot;reason&quot;: &quot;Unable to retrieve file contents\nCould not find or access '...'&quot;}"><pre class="notranslate"><code class="notranslate">FAILED! =&gt; {"reason": "Unable to retrieve file contents\nCould not find or access '...'"}
</code></pre></div>
<p dir="auto">(which is what you get with a straight-up static include of a missing file)</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<p dir="auto">Debug task executes as expected (which also proves that <code class="notranslate">ansible_system</code> is defined).</p>
<p dir="auto">The "import_tasks" task fails, as expected, but does so with an entirely incorrect error message:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="FAILED! =&gt; {&quot;reason&quot;: &quot;'ansible_system' is undefined&quot;}"><pre class="notranslate"><code class="notranslate">FAILED! =&gt; {"reason": "'ansible_system' is undefined"}
</code></pre></div>
<p dir="auto">Ansible thus <strong>hides</strong> the actual fault in this case behind a completely false error.</p>