<p dir="auto">From the mailing list:</p>
<p dir="auto">I am referring to the documentation<br>
here: <a href="http://docs.ansible.com/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable" rel="nofollow">http://docs.ansible.com/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable</a></p>
<p dir="auto">When I use vars_files and "-e" (command line) variables together, I get<br>
results that appear to fly in the face of the aforementioned documentation.<br>
Exhibit A:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ ansible --version
ansible 1.5.3
$ cat test_vars.yml

---
test_var: &quot;from vars_files&quot;
$ cat test.yml

---
- hosts: 127.0.0.1
  connection: local
  vars_files:
    - test_vars.yml
  tasks:
    - name: Testing variables
      debug: msg=&quot;{{ test_var }}&quot;
$ ansible-playbook -i test test.yml -e &quot;test_var='from command line'&quot;

PLAY [127.0.0.1] **************************************************************

GATHERING FACTS ***************************************************************
ok: [127.0.0.1]

TASK: [Testing variables] *****************************************************
ok: [127.0.0.1] =&gt; {
&quot;msg&quot;: &quot;from vars_files&quot;
}

PLAY RECAP ********************************************************************
127.0.0.1 : ok=2 changed=0 unreachable=0 failed=0"><pre class="notranslate"><code class="notranslate">$ ansible --version
ansible 1.5.3
$ cat test_vars.yml

---
test_var: "from vars_files"
$ cat test.yml

---
- hosts: 127.0.0.1
  connection: local
  vars_files:
    - test_vars.yml
  tasks:
    - name: Testing variables
      debug: msg="{{ test_var }}"
$ ansible-playbook -i test test.yml -e "test_var='from command line'"

PLAY [127.0.0.1] **************************************************************

GATHERING FACTS ***************************************************************
ok: [127.0.0.1]

TASK: [Testing variables] *****************************************************
ok: [127.0.0.1] =&gt; {
"msg": "from vars_files"
}

PLAY RECAP ********************************************************************
127.0.0.1 : ok=2 changed=0 unreachable=0 failed=0
</code></pre></div>
<p dir="auto">Note that according to the docs, -e variables should "always win" but in<br>
this case, they clearly do not.</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.3</p>
<h5 dir="auto">Environment:</h5>
<p dir="auto">N/A</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto">Variables referenced in tasks (the ones which appear directly in the playbook/are included with <code class="notranslate">include</code> as well as ones in roles) have their value changed across tasks when they are specified both in <code class="notranslate">vars_files</code> and with <code class="notranslate">--extra-vars</code>: the first time a tasks refers to it the value in <code class="notranslate">vars_files</code> is used, and all subsequent tasks get the value passed via <code class="notranslate">--extra-vars</code>.</p>
<h5 dir="auto">Steps To Reproduce:</h5>
<p dir="auto">my_vars.yml:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
---
some_var: foo"><pre class="notranslate">---
<span class="pl-ent">some_var</span>: <span class="pl-s">foo</span></pre></div>
<p dir="auto">playbook.yml:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
---
- hosts: 127.0.0.1
  connection: local
  vars_files: [my_vars.yml]
  tasks:
  - command: echo {{ some_var }}
  - command: echo {{ some_var }}
  - command: echo {{ some_var }}"><pre class="notranslate">---
- <span class="pl-ent">hosts</span>: <span class="pl-s">127.0.0.1</span>
  <span class="pl-ent">connection</span>: <span class="pl-s">local</span>
  <span class="pl-ent">vars_files</span>: <span class="pl-s">[my_vars.yml]</span>
  <span class="pl-ent">tasks</span>:
  - <span class="pl-ent">command</span>: <span class="pl-s">echo {{ some_var }}</span>
  - <span class="pl-ent">command</span>: <span class="pl-s">echo {{ some_var }}</span>
  - <span class="pl-ent">command</span>: <span class="pl-s">echo {{ some_var }}</span></pre></div>
<p dir="auto">Then call ansible-playbook with <code class="notranslate">ansible-playbook -e some_var=bar playbook.yml</code>.</p>
<h5 dir="auto">Expected Results:</h5>
<p dir="auto">The <code class="notranslate">echo</code> calls show me "bar" 3 times.</p>
<h5 dir="auto">Actual Results:</h5>
<p dir="auto">The first <code class="notranslate">echo</code> call shows "foo", the other 2 show "bar".</p>