<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
<li>Documentation Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">variables</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.5.0.32862.2cdf31d3a2
  config file = /etc/ansible/ansible.cfg
  configured module search path =  [u'~/.ansible/plugins/modules',u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.14 (default, Sep 20 2017, 01:25:59) [GCC 7.2.0]"><pre class="notranslate"><code class="notranslate">ansible 2.5.0.32862.2cdf31d3a2
  config file = /etc/ansible/ansible.cfg
  configured module search path =  [u'~/.ansible/plugins/modules',u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.14 (default, Sep 20 2017, 01:25:59) [GCC 7.2.0]
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">N/A</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">N/A</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">When multiple roles are pulled into a playbook, earlier roles can reference default variables from later roles, i.e., variables can be used before they are defined.<br>
Even after scouring the documentation I can only conclude that this is surprising behaviour.<br>
It has been stated elsewhere that defaults belong to the global scope. But this issue is tangential. It refers to ordering of roles when it comes to defaults.</p>
<p dir="auto">This is a duplicate of <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="126207155" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible/issues/13814" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible/issues/13814/hovercard" href="https://github.com/ansible/ansible/issues/13814">#13814</a> which has never been solved.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<p dir="auto">The example <a href="https://github.com/mrdrogdrog/ansible-var-default">https://github.com/mrdrogdrog/ansible-var-default</a> contains two roles which just print a var to debug output.<br>
The role <code class="notranslate">first</code> hasn't a default definition.<br>
The role <code class="notranslate">second</code> sets the default value of <code class="notranslate">var</code> to "second"</p>
<p dir="auto">Playbook:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="---
- hosts: local
  roles:
    - role: first
    - role: second"><pre class="notranslate">---
- <span class="pl-ent">hosts</span>: <span class="pl-s">local</span>
  <span class="pl-ent">roles</span>:
    - <span class="pl-ent">role</span>: <span class="pl-s">first</span>
    - <span class="pl-ent">role</span>: <span class="pl-s">second</span></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">The playbook shouldn't compile because <code class="notranslate">first</code> expects a value for <code class="notranslate">var</code> which is not set.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>

<p dir="auto">The playbook compiles and prints</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="second
second"><pre class="notranslate"><code class="notranslate">second
second
</code></pre></div>
<p dir="auto">to debug output</p>
<p dir="auto">Example code has been simplified to clearly demonstrate the variable scoping issue that occurs when a dependent role is activated.</p>
<p dir="auto">This is a duplicate of issue <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="21035715" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible/issues/4528" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible/issues/4528/hovercard" href="https://github.com/ansible/ansible/issues/4528">#4528</a>  -  which I've added after reading advice from: <a href="https://groups.google.com/forum/#!msg/ansible-project/BPnZPe_Ixhg/aDU9dkvrUjcJ" rel="nofollow">https://groups.google.com/forum/#!msg/ansible-project/BPnZPe_Ixhg/aDU9dkvrUjcJ</a></p>
<p dir="auto">The scoping issue is a major showstopper for us; and I'd like to at least get confirmation that this is a bug with intent to fix vs. desirable behavior.</p>
<p dir="auto">Summary:</p>
<p dir="auto"><a href="https://github.com/briceburg/ansible-variable-scoping/tree/master/simple">https://github.com/briceburg/ansible-variable-scoping/tree/master/simple</a></p>