<h5 dir="auto">Issue Type:</h5>
<p dir="auto">Bug Report</p>
<h5 dir="auto">Ansible Version:</h5>
<p dir="auto">Ansible &gt;= 1.8.0</p>
<h5 dir="auto">Environment:</h5>
<p dir="auto">N/A</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto">Ever since <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/ansible/ansible/commit/313f26f866cec92e4dbe0e1d713a0ab0da647c98/hovercard" href="https://github.com/ansible/ansible/commit/313f26f866cec92e4dbe0e1d713a0ab0da647c98"><tt>313f26f</tt></a>, if a variable is set in <code class="notranslate">group_vars</code> and overridden via <code class="notranslate">--extra-vars</code>, the value from <code class="notranslate">group_vars</code> ends up being used when the variable is referenced in role variables.</p>
<h5 dir="auto">Steps To Reproduce:</h5>
<p dir="auto">group_vars/all:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="some_var: val1"><pre class="notranslate"><span class="pl-ent">some_var</span>: <span class="pl-s">val1</span></pre></div>
<p dir="auto">roles/test-role/vars/main.yml:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="derived_var: &quot;{{ some_var }}&quot;"><pre class="notranslate"><span class="pl-ent">derived_var</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ some_var }}<span class="pl-pds">"</span></span></pre></div>
<p dir="auto">roles/test-role/tasks/main.yml:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
---
- action: debug var=derived_var"><pre class="notranslate">---
- <span class="pl-ent">action</span>: <span class="pl-s">debug var=derived_var</span></pre></div>
<p dir="auto">main.yml:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
---
- hosts: all
  roles: [test-role]"><pre class="notranslate">---
- <span class="pl-ent">hosts</span>: <span class="pl-s">all</span>
  <span class="pl-ent">roles</span>: <span class="pl-s">[test-role]</span></pre></div>
<p dir="auto">Then call <code class="notranslate">ansible-playbook -e some_var=val2 main.yml</code>.</p>
<h5 dir="auto">Expected Results:</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ok: [localhost] =&gt; {
    &quot;var&quot;: {
        &quot;derived_var&quot;: &quot;val2&quot;
    }
}"><pre class="notranslate"><code class="notranslate">ok: [localhost] =&gt; {
    "var": {
        "derived_var": "val2"
    }
}
</code></pre></div>
<h5 dir="auto">Actual Results:</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ok: [localhost] =&gt; {
    &quot;var&quot;: {
        &quot;derived_var&quot;: &quot;val1&quot;
    }
}"><pre class="notranslate"><code class="notranslate">ok: [localhost] =&gt; {
    "var": {
        "derived_var": "val1"
    }
}
</code></pre></div>
<p dir="auto">If I set a variable in a role which refers to another variable, then override the second variable with <code class="notranslate">--extra-vars</code> the original variable is unchanged.</p>
<p dir="auto">Here's an example:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="cat &lt;&lt;'EOF' &gt; playbook

---
- hosts: 127.0.0.1
  connection: local
  gather_facts: false
  roles:
    - x

EOF

mkdir -p roles/x/{vars,tasks}

cat &lt;&lt;'EOF' &gt; roles/x/vars/main.yml

---
var: 1
var2: &quot;This is {{var}}&quot;
EOF

cat &lt;&lt;'EOF' &gt; roles/x/tasks/main.yml

---
- debug: var=var
- debug: var=var2
EOF

ansible-playbook playbook -e var=2"><pre class="notranslate"><code class="notranslate">cat &lt;&lt;'EOF' &gt; playbook

---
- hosts: 127.0.0.1
  connection: local
  gather_facts: false
  roles:
    - x

EOF

mkdir -p roles/x/{vars,tasks}

cat &lt;&lt;'EOF' &gt; roles/x/vars/main.yml

---
var: 1
var2: "This is {{var}}"
EOF

cat &lt;&lt;'EOF' &gt; roles/x/tasks/main.yml

---
- debug: var=var
- debug: var=var2
EOF

ansible-playbook playbook -e var=2
</code></pre></div>
<p dir="auto">Expected output:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PLAY [127.0.0.1] ************************************************************** 

TASK: [x | debug var=var] ***************************************************** 
ok: [127.0.0.1] =&gt; {
    &quot;var&quot;: &quot;2&quot;
}

TASK: [x | debug var=var2] **************************************************** 
ok: [127.0.0.1] =&gt; {
    &quot;var2&quot;: &quot;This is 2&quot;
}

PLAY RECAP ******************************************************************** 
127.0.0.1                  : ok=2    changed=0    unreachable=0    failed=0   "><pre class="notranslate"><code class="notranslate">PLAY [127.0.0.1] ************************************************************** 

TASK: [x | debug var=var] ***************************************************** 
ok: [127.0.0.1] =&gt; {
    "var": "2"
}

TASK: [x | debug var=var2] **************************************************** 
ok: [127.0.0.1] =&gt; {
    "var2": "This is 2"
}

PLAY RECAP ******************************************************************** 
127.0.0.1                  : ok=2    changed=0    unreachable=0    failed=0   
</code></pre></div>
<p dir="auto">Actual output:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PLAY [127.0.0.1] ************************************************************** 

TASK: [x | debug var=var] ***************************************************** 
ok: [127.0.0.1] =&gt; {
    &quot;var&quot;: &quot;2&quot;
}

TASK: [x | debug var=var2] **************************************************** 
ok: [127.0.0.1] =&gt; {
    &quot;var2&quot;: &quot;This is 1&quot;
}

PLAY RECAP ******************************************************************** 
127.0.0.1                  : ok=2    changed=0    unreachable=0    failed=0   "><pre class="notranslate"><code class="notranslate">PLAY [127.0.0.1] ************************************************************** 

TASK: [x | debug var=var] ***************************************************** 
ok: [127.0.0.1] =&gt; {
    "var": "2"
}

TASK: [x | debug var=var2] **************************************************** 
ok: [127.0.0.1] =&gt; {
    "var2": "This is 1"
}

PLAY RECAP ******************************************************************** 
127.0.0.1                  : ok=2    changed=0    unreachable=0    failed=0   
</code></pre></div>
<p dir="auto">I am running ansible 1.8.2 from EPEL (ansible-1.8.2-3.el6.noarch).</p>