<h5 dir="auto">Issue Type:</h5>
<p dir="auto">Bug Report</p>
<h5 dir="auto">Ansible Version:</h5>
<p dir="auto">1.8 (devel) - works in 1.7</p>
<h5 dir="auto">Environment:</h5>
<p dir="auto">running on: Linux Ubuntu<br>
managing: Linux Ubuntu</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto"><code class="notranslate">vars/main.yml</code> gets loaded from all roles at the beginning of playbook (expected). In case one variable is in multiple roles, it <strong>gets overwritten</strong> and receives the content from the last role in playbook, not the current role (unexpected, regression).</p>
<p dir="auto">In Ansible versions prior 1.8 (devel) any such variable got the current role's <code class="notranslate">vars/main.yml</code> content. The current behavior breaks our infrastructure and effectively eliminates our variable and task reuse.</p>
<h5 dir="auto">Steps To Reproduce:</h5>
<p dir="auto">playbook-role-example.yml:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- hosts: server
  roles:
    - role-1
    - role-2"><pre class="notranslate"><code class="notranslate">- hosts: server
  roles:
    - role-1
    - role-2
</code></pre></div>
<p dir="auto">roles/role-1/vars/main.yml:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="current_role: role-1"><pre class="notranslate"><code class="notranslate">current_role: role-1
</code></pre></div>
<p dir="auto">roles/role-1/tasks/main.yml:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- name:         print current_role variable
  debug:        msg=&quot;Variable current_role is {{ current_role }}&quot;"><pre class="notranslate"><code class="notranslate">- name:         print current_role variable
  debug:        msg="Variable current_role is {{ current_role }}"
</code></pre></div>
<p dir="auto">roles/role-2/vars/main.yml:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="current_role: role-2"><pre class="notranslate"><code class="notranslate">current_role: role-2
</code></pre></div>
<p dir="auto">roles/role-2/tasks/main.yml:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- name:         print current_role variable
  debug:        msg=&quot;Variable current_role is {{ current_role }}&quot;"><pre class="notranslate"><code class="notranslate">- name:         print current_role variable
  debug:        msg="Variable current_role is {{ current_role }}"
</code></pre></div>
<h5 dir="auto">Expected Results:</h5>
<p dir="auto">Output until (and including) 1.7.2:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TASK: [role-1 | print current_role variable] ********************************** 
ok: [192.168.56.101] =&gt; {
    &quot;msg&quot;: &quot;Variable current_role is role-1&quot;
}

TASK: [role-2 | print current_role variable] ********************************** 
ok: [192.168.56.101] =&gt; {
    &quot;msg&quot;: &quot;Variable current_role is role-2&quot;
}"><pre class="notranslate"><code class="notranslate">TASK: [role-1 | print current_role variable] ********************************** 
ok: [192.168.56.101] =&gt; {
    "msg": "Variable current_role is role-1"
}

TASK: [role-2 | print current_role variable] ********************************** 
ok: [192.168.56.101] =&gt; {
    "msg": "Variable current_role is role-2"
}
</code></pre></div>
<h5 dir="auto">Actual Results:</h5>
<p dir="auto">Output in 1.8 (devel):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TASK: [role-1 | print current_role variable] ********************************** 
ok: [192.168.56.101] =&gt; {
    &quot;msg&quot;: &quot;Variable current_role is role-2&quot;
}

TASK: [role-2 | print current_role variable] ********************************** 
ok: [192.168.56.101] =&gt; {
    &quot;msg&quot;: &quot;Variable current_role is role-2&quot;
}"><pre class="notranslate"><code class="notranslate">TASK: [role-1 | print current_role variable] ********************************** 
ok: [192.168.56.101] =&gt; {
    "msg": "Variable current_role is role-2"
}

TASK: [role-2 | print current_role variable] ********************************** 
ok: [192.168.56.101] =&gt; {
    "msg": "Variable current_role is role-2"
}
</code></pre></div>
<p dir="auto">This has come and gone over the previous releases, and is currently present on the devel branch.</p>
<p dir="auto">To reproduce:</p>
<p dir="auto">roles/test1/vars/main.yml:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="myvar: test1"><pre class="notranslate"><code class="notranslate">myvar: test1
</code></pre></div>
<p dir="auto">roles/test2/vars/main.yml:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="myvar: test2"><pre class="notranslate"><code class="notranslate">myvar: test2
</code></pre></div>
<p dir="auto">both roles' task file is:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- debug: var=myvar"><pre class="notranslate"><code class="notranslate">- debug: var=myvar
</code></pre></div>
<p dir="auto">and the playbook:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- hosts: localhost
  roles:
    - test1
    - test2"><pre class="notranslate"><code class="notranslate">- hosts: localhost
  roles:
    - test1
    - test2
</code></pre></div>
<p dir="auto">The results should be:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TASK: [test1 | debug var=myvar] *********************************************** 
ok: [localhost] =&gt; {
    &quot;myvar&quot;: &quot;test1&quot;
}

TASK: [test2 | debug var=myvar] *********************************************** 
ok: [localhost] =&gt; {
    &quot;myvar&quot;: &quot;test2&quot;
}"><pre class="notranslate"><code class="notranslate">TASK: [test1 | debug var=myvar] *********************************************** 
ok: [localhost] =&gt; {
    "myvar": "test1"
}

TASK: [test2 | debug var=myvar] *********************************************** 
ok: [localhost] =&gt; {
    "myvar": "test2"
}
</code></pre></div>
<p dir="auto">But are actually:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TASK: [test1 | debug var=myvar] *********************************************** 
ok: [localhost] =&gt; {
    &quot;myvar&quot;: &quot;test2&quot;
}

TASK: [test2 | debug var=myvar] *********************************************** 
ok: [localhost] =&gt; {
    &quot;myvar&quot;: &quot;test2&quot;
}"><pre class="notranslate"><code class="notranslate">TASK: [test1 | debug var=myvar] *********************************************** 
ok: [localhost] =&gt; {
    "myvar": "test2"
}

TASK: [test2 | debug var=myvar] *********************************************** 
ok: [localhost] =&gt; {
    "myvar": "test2"
}
</code></pre></div>
<p dir="auto"><code class="notranslate">git bisect</code> points to <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/ansible/ansible/commit/8a1fbed5d6a61583950024df60ac74d5c98d6cca/hovercard" href="https://github.com/ansible/ansible/commit/8a1fbed5d6a61583950024df60ac74d5c98d6cca"><tt>8a1fbed</tt></a></p>