<p dir="auto">Included tasks use different variable definitions in roles activated by the role dependency mechanism.</p>
<ul dir="auto">
<li>ansible 1.4 -devel <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/ansible/ansible/commit/214b0b052c3d54b58a531b0f7fb401ec3c0229f5/hovercard" href="https://github.com/ansible/ansible/commit/214b0b052c3d54b58a531b0f7fb401ec3c0229f5"><tt>214b0b0</tt></a></li>
</ul>
<h1 dir="auto">Description</h1>
<p dir="auto">The alpha-&gt;beta scope, <code class="notranslate">port</code> when called from roles/beta/<code class="notranslate">tasks/main.yml</code> acts like a <code class="notranslate">var</code>, whereas when called from roles/beta/<code class="notranslate">tasks/include.yml</code> port acts like a <code class="notranslate">default</code>.</p>
<h1 dir="auto">Demonstration</h1>
<p dir="auto"><code class="notranslate">main.yml</code> :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
---
# beta role tasks

- debug: msg=&quot;beta role (tasks/main.yml) - port - expected beta-port, got {{ port }}&quot;
  failed_when: &quot;port != 'beta-port'&quot;
  ignore_errors: True

- { include: &quot;include.yml&quot;}"><pre class="notranslate"><code class="notranslate">
---
# beta role tasks

- debug: msg="beta role (tasks/main.yml) - port - expected beta-port, got {{ port }}"
  failed_when: "port != 'beta-port'"
  ignore_errors: True

- { include: "include.yml"}
</code></pre></div>
<p dir="auto"><code class="notranslate">include.yml</code> :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
---
# beta role included task(s)

- debug: msg=&quot;beta role (tasks/include.yml) - port - expected beta-port, got {{ port }}&quot;
  failed_when: &quot;port != 'beta-port'&quot;
  ignore_errors: True"><pre class="notranslate"><code class="notranslate">
---
# beta role included task(s)

- debug: msg="beta role (tasks/include.yml) - port - expected beta-port, got {{ port }}"
  failed_when: "port != 'beta-port'"
  ignore_errors: True
</code></pre></div>
<p dir="auto">exhibit#2,</p>
<p dir="auto">functional demo:<br>
<a href="https://github.com/briceburg/ansible-variable-scoping/tree/master/simple_include">https://github.com/briceburg/ansible-variable-scoping/tree/master/simple_include</a></p>
<p dir="auto">Edit: Improved description to include <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/aboyett/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/aboyett">@aboyett</a> synopsis <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="21399421" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible/issues/4642" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible/issues/4642/hovercard?comment_id=31992722&amp;comment_type=issue_comment" href="https://github.com/ansible/ansible/issues/4642#issuecomment-31992722">#4642 (comment)</a></p>
<p dir="auto">Roles do not use their variable definitions when actvated via the role dependency mechanism.</p>
<ul dir="auto">
<li>ansible 1.4 -devel <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/ansible/ansible/commit/214b0b052c3d54b58a531b0f7fb401ec3c0229f5/hovercard" href="https://github.com/ansible/ansible/commit/214b0b052c3d54b58a531b0f7fb401ec3c0229f5"><tt>214b0b0</tt></a></li>
</ul>
<h1 dir="auto">Description</h1>
<ol dir="auto">
<li>alpha role depends on beta role</li>
<li>Each role provides a unique value for a variable named 'port' /vars/main.yml</li>
<li>When beta role is executed (aka <strong>"active"</strong>) via the role dependency mechanism, the role uses variable definitions from alpha role instead of its own definitions (roles/beta/vars/main.yml).</li>
<li>It has been noted that active roles use their variable definitions [unless higher precedent variables are passed via --extra-vars, or variable definitions in the base playbook]
<ul dir="auto">
<li>"... within a role, the variables in roles/y/vars/main.yml are guaranteed to be applied to that specific role, just as if they were parameters explicitly passed to the role." ( <a href="https://groups.google.com/d/msg/ansible-project/0JIrNlnRXuI/tx1-inKYoUQJ" rel="nofollow">https://groups.google.com/d/msg/ansible-project/0JIrNlnRXuI/tx1-inKYoUQJ</a> )</li>
</ul>
</li>
</ol>
<h1 dir="auto">Demonstration</h1>
<p dir="auto"><a href="https://github.com/briceburg/ansible-variable-scoping/tree/master/simple_vars">https://github.com/briceburg/ansible-variable-scoping/tree/master/simple_vars</a></p>