<h5 dir="auto">Issue Type:</h5>
<p dir="auto">Bug Report</p>
<h5 dir="auto">Ansible Version:</h5>
<p dir="auto">Ansible 1.8 (devel <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/ansible/ansible/commit/a1f09bd89f6daec9365f0654bda6e4e9654be45c/hovercard" href="https://github.com/ansible/ansible/commit/a1f09bd89f6daec9365f0654bda6e4e9654be45c"><tt>a1f09bd</tt></a>) last updated 2014/08/20 17:28:56 (GMT +400)</p>
<h5 dir="auto">Environment:</h5>
<p dir="auto">Linux Ubuntu 12.04, Mac OS X</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto">There is an <code class="notranslate">app_user</code> variable which is defined in <code class="notranslate">group_vars/all</code> as <code class="notranslate">all_user</code> and in external variables file <code class="notranslate">vars/staging.yml</code> as <code class="notranslate">staging_user</code>.  I've got weird win order for the variable when the second external variables file is used and it is not empty.</p>
<h5 dir="auto">Steps To Reproduce:</h5>
<p dir="auto">I made a public repository with files for convenience <a href="https://github.com/hostmaster/ansible-bugreport">https://github.com/hostmaster/ansible-bugreport</a></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# group_vars/all
app_user: all_user"><pre class="notranslate"><code class="notranslate"># group_vars/all
app_user: all_user
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# inventory/staging
localhost ansible_connection=local

[all:vars]
deploy_env=staging"><pre class="notranslate"><code class="notranslate"># inventory/staging
localhost ansible_connection=local

[all:vars]
deploy_env=staging
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# vars/secrets/staging.yml
test_url: 'google.com'"><pre class="notranslate"><code class="notranslate"># vars/secrets/staging.yml
test_url: 'google.com'
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# vars/staging.yml
app_user: staging_user"><pre class="notranslate"><code class="notranslate"># vars/staging.yml
app_user: staging_user
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
---
# test.yml
- hosts: localhost
  gather_facts: no
  vars_files:
    - 'vars/{{ deploy_env }}.yml'
    - 'vars/secrets/{{ deploy_env }}.yml'

  tasks:
    - local_action: debug var=deploy_env
    - local_action: debug var=app_user"><pre class="notranslate"><code class="notranslate">
---
# test.yml
- hosts: localhost
  gather_facts: no
  vars_files:
    - 'vars/{{ deploy_env }}.yml'
    - 'vars/secrets/{{ deploy_env }}.yml'

  tasks:
    - local_action: debug var=deploy_env
    - local_action: debug var=app_user
</code></pre></div>
<p dir="auto">I have expected to get <code class="notranslate">staging_user</code> here but I've got <code class="notranslate">all_user</code> instead.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ ansible-playbook -i inventory/staging test.yml

PLAY [localhost] **************************************************************
localhost: importing /Users/igor/Temp/ansible/test_run/vars/staging.yml
localhost: importing /Users/igor/Temp/ansible/test_run/vars/secrets/staging.yml

TASK: [debug var=deploy_env] **************************************************
ok: [localhost -&gt; 127.0.0.1] =&gt; {
    &quot;deploy_env&quot;: &quot;staging&quot;
}

TASK: [debug var=app_user] ****************************************************
ok: [localhost -&gt; 127.0.0.1] =&gt; {
    &quot;app_user&quot;: &quot;all_user&quot;
}

PLAY RECAP ********************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0"><pre class="notranslate"><code class="notranslate">$ ansible-playbook -i inventory/staging test.yml

PLAY [localhost] **************************************************************
localhost: importing /Users/igor/Temp/ansible/test_run/vars/staging.yml
localhost: importing /Users/igor/Temp/ansible/test_run/vars/secrets/staging.yml

TASK: [debug var=deploy_env] **************************************************
ok: [localhost -&gt; 127.0.0.1] =&gt; {
    "deploy_env": "staging"
}

TASK: [debug var=app_user] ****************************************************
ok: [localhost -&gt; 127.0.0.1] =&gt; {
    "app_user": "all_user"
}

PLAY RECAP ********************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0
</code></pre></div>
<p dir="auto">Now comment out the line in <code class="notranslate">vars/secrets/staging.yml</code></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# vars/secrets/staging.yml
# test_url: 'google.com'"><pre class="notranslate"><code class="notranslate"># vars/secrets/staging.yml
# test_url: 'google.com'
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ ansible-playbook -i inventory/staging test.yml

PLAY [localhost] **************************************************************
localhost: importing /Users/igor/Temp/ansible/test_run/vars/staging.yml

TASK: [debug var=deploy_env] **************************************************
ok: [localhost -&gt; 127.0.0.1] =&gt; {
    &quot;deploy_env&quot;: &quot;staging&quot;
}

TASK: [debug var=app_user] ****************************************************
ok: [localhost -&gt; 127.0.0.1] =&gt; {
    &quot;app_user&quot;: &quot;staging_user&quot;
}

PLAY RECAP ********************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0"><pre class="notranslate"><code class="notranslate">$ ansible-playbook -i inventory/staging test.yml

PLAY [localhost] **************************************************************
localhost: importing /Users/igor/Temp/ansible/test_run/vars/staging.yml

TASK: [debug var=deploy_env] **************************************************
ok: [localhost -&gt; 127.0.0.1] =&gt; {
    "deploy_env": "staging"
}

TASK: [debug var=app_user] ****************************************************
ok: [localhost -&gt; 127.0.0.1] =&gt; {
    "app_user": "staging_user"
}

PLAY RECAP ********************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0
</code></pre></div>
<h5 dir="auto">Expected Results:</h5>
<p dir="auto">ok: [localhost -&gt; 127.0.0.1] =&gt; {<br>
"app_user": "staging_user"<br>
}</p>
<h5 dir="auto">Actual Results:</h5>
<p dir="auto">ok: [localhost -&gt; 127.0.0.1] =&gt; {<br>
"app_user": "all_user"<br>
}</p>
<h5 dir="auto">Issue Type: Bug Report</h5>
<h5 dir="auto">Ansible Version: 1.6.2 - 1.7.1</h5>
<h5 dir="auto">Environment: any</h5>
<h5 dir="auto">Summary:</h5>
<p dir="auto">Playbook level variable are ignored when we use vars_files with filename defined with {{ansible_os_family}}</p>
<p dir="auto">If we import variable file with static name (RedHat.yml for example) - no issue</p>
<h5 dir="auto">Steps To Reproduce:</h5>
<p dir="auto">Test playbook</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
---

- name: 'Test Precedence'
  hosts: vagrantcentos
  user: vagrant
  sudo: yes

  vars:
    some_var: &quot;foo&quot;

  vars_files:
    - vars/{{ ansible_os_family }}.yml
    #- vars/RedHat.yml
    - vars/other_vars.yml

  tasks: 
    - debug: msg={{some_var}}
      tags:
        - test"><pre class="notranslate">---

- <span class="pl-ent">name</span>: <span class="pl-s"><span class="pl-pds">'</span>Test Precedence<span class="pl-pds">'</span></span>
  <span class="pl-ent">hosts</span>: <span class="pl-s">vagrantcentos</span>
  <span class="pl-ent">user</span>: <span class="pl-s">vagrant</span>
  <span class="pl-ent">sudo</span>: <span class="pl-s">yes</span>

  <span class="pl-ent">vars</span>:
    <span class="pl-ent">some_var</span>: <span class="pl-s"><span class="pl-pds">"</span>foo<span class="pl-pds">"</span></span>

  <span class="pl-ent">vars_files</span>:
    - <span class="pl-s">vars/{{ ansible_os_family }}.yml</span>
    <span class="pl-c"><span class="pl-c">#</span>- vars/RedHat.yml</span>
    - <span class="pl-s">vars/other_vars.yml</span>

  <span class="pl-ent">tasks</span>: 
    - <span class="pl-ent">debug</span>: <span class="pl-s">msg={{some_var}}</span>
      <span class="pl-ent">tags</span>:
        - <span class="pl-s">test</span></pre></div>
<p dir="auto">and additional files<br>
group_vars/all</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="some_var: &quot;bar&quot;"><pre class="notranslate"><span class="pl-ent">some_var</span>: <span class="pl-s"><span class="pl-pds">"</span>bar<span class="pl-pds">"</span></span></pre></div>
<p dir="auto">vars/RedHat.yml</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="useless_var: &quot;oops&quot;"><pre class="notranslate"><span class="pl-ent">useless_var</span>: <span class="pl-s"><span class="pl-pds">"</span>oops<span class="pl-pds">"</span></span></pre></div>
<p dir="auto">vars/other_vars.yml</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="other_var: &quot;woot&quot;"><pre class="notranslate"><span class="pl-ent">other_var</span>: <span class="pl-s"><span class="pl-pds">"</span>woot<span class="pl-pds">"</span></span></pre></div>
<h5 dir="auto">Expected Results:</h5>
<p dir="auto">debug message should be<br>
<code class="notranslate">"msg": "foo"</code><br>
this result returned when I comment<br>
<code class="notranslate">- vars/{{ ansible_os_family }}.yml</code> line</p>
<h5 dir="auto">Actual Results:</h5>
<p dir="auto">Unexpectedly we got:<br>
<code class="notranslate">"msg": "bar"</code></p>