<h5 dir="auto">Issue Type: Bug Report</h5>
<h5 dir="auto">Ansible Version: 1.5</h5>
<h5 dir="auto">Environment: CentOS 6.5</h5>
<h5 dir="auto">Summary: includes in templates loose their variable context</h5>
<h5 dir="auto">Steps To Reproduce:</h5>
<p dir="auto">In one template file i have this code snippet:<br>
{% for group in group_names %}<br>
{% include "debug_include.j2" with context %}<br>
{% endfor %}</p>
<p dir="auto">In the included template 'debug_include.j2' i have this code:<br>
This is the included Template. The current group is {{group}}</p>
<p dir="auto">The documentation claims that included templates have the same variable context as the main file.<br>
So i would expect to see something like:<br>
This is the included Template. The current group is mailserver</p>
<h5 dir="auto">Expected Results:</h5>
<p dir="auto">I would expect to see something like:<br>
This is the included Template. The current group is mailserver</p>
<h5 dir="auto">Actual Results:</h5>
<p dir="auto">Instead i get an error on the commandline when executing this play:<br>
TASK: [common-linux | dump all variables] *************************************<br>
fatal: [ltesthost] =&gt; {'msg': "One or more undefined variables: 'group' is undefined", 'failed': True}<br>
fatal: [testhost] =&gt; {'msg': "One or more undefined variables: 'group' is undefined", 'failed': True}</p>
<p dir="auto">FATAL: all hosts have already failed -- aborting</p>
<h5 dir="auto">Issue Type:</h5>
<p dir="auto">Bug Report</p>
<h5 dir="auto">Ansible Version:</h5>
<p dir="auto">ansible 1.5</p>
<h5 dir="auto">Environment:</h5>
<p dir="auto">debian 7</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto">Variables go out of scope inside an included template</p>
<h5 dir="auto">Steps To Reproduce:</h5>
<p dir="auto">hosts.yml:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
---
- hosts: all
  vars:
    mylist:
      - alpha
      - bravo
  tasks:
  - name: template test
    template: src=test.j2 dest=/tmp/testfile"><pre class="notranslate"><code class="notranslate">
---
- hosts: all
  vars:
    mylist:
      - alpha
      - bravo
  tasks:
  - name: template test
    template: src=test.j2 dest=/tmp/testfile
</code></pre></div>
<p dir="auto">test.j2:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{% for x in mylist %}

  X: {{ x }}

  {% include 'test-inc.j2' with context %}

{% endfor %}"><pre class="notranslate"><code class="notranslate">{% for x in mylist %}

  X: {{ x }}

  {% include 'test-inc.j2' with context %}

{% endfor %}
</code></pre></div>
<p dir="auto">test-inc.j2:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{{ x }}
"><pre class="notranslate"><code class="notranslate">{{ x }}

</code></pre></div>
<h5 dir="auto">Expected Results:</h5>
<p dir="auto">I expect x in test-inc.j2 to be properly dereferenced</p>
<h5 dir="auto">Actual Results:</h5>
<p dir="auto">fatal: [myhost] =&gt; {'msg': "One or more undefined variables: 'x' is undefined", 'failed': True}<br>
fatal: [myhost] =&gt; {'msg': "One or more undefined variables: 'x' is undefined", 'failed': True}</p>