<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/6180d9a6933586359dc2846bb5521290cd6ee0e3/hovercard" href="https://github.com/ansible/ansible/commit/6180d9a6933586359dc2846bb5521290cd6ee0e3"><tt>6180d9a</tt></a>) last updated 2014/08/18 17:03:49 (GMT +1100)</p>
<h5 dir="auto">Environment:</h5>
<p dir="auto">Bug discovered with Debian x86_64, confirmed and bisected with Gentoo x86_64.</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto">When using group_by to create a group on the fly (e.g. <code class="notranslate">group_by: key="{{ ansible_os_family }}"</code>), the group_vars fail to override vars in <code class="notranslate">group_vars/all</code>.</p>
<p dir="auto">I bisected this to <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/ansible/ansible/commit/f6a55a35525a6ca0b56ad856f2ab11bbd226c1b4/hovercard" href="https://github.com/ansible/ansible/commit/f6a55a35525a6ca0b56ad856f2ab11bbd226c1b4"><tt>f6a55a3</tt></a>.</p>
<h5 dir="auto">Steps To Reproduce:</h5>
<p dir="auto"><code class="notranslate">site.yml</code>:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
---
- hosts: all
  tasks:
  - group_by: key={{ ansible_os_family }}
  - fail: msg=&quot;testvar = {{ testvar }}&quot;
    when: testvar != &quot;override OK&quot;"><pre class="notranslate">---
- <span class="pl-ent">hosts</span>: <span class="pl-s">all</span>
  <span class="pl-ent">tasks</span>:
  - <span class="pl-ent">group_by</span>: <span class="pl-s">key={{ ansible_os_family }}</span>
  - <span class="pl-ent">fail</span>: <span class="pl-s">msg="testvar = {{ testvar }}"</span>
    <span class="pl-ent">when</span>: <span class="pl-s">testvar != "override OK"</span></pre></div>
<p dir="auto"><code class="notranslate">group_vars/all</code>:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
---
testvar: override FAIL"><pre class="notranslate">---
<span class="pl-ent">testvar</span>: <span class="pl-s">override FAIL</span></pre></div>
<p dir="auto"><code class="notranslate">group_vars/Gentoo</code> (where "Gentoo" is whatever your <code class="notranslate">ansible_os_family</code> actually resolves to):</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
---
testvar: override OK"><pre class="notranslate">---
<span class="pl-ent">testvar</span>: <span class="pl-s">override OK</span></pre></div>
<h5 dir="auto">Expected Results:</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PLAY [all] ******************************************************************** 

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

TASK: [group_by key={{ ansible_os_family }}] ********************************** 
changed: [127.0.0.1]

TASK: [fail msg=&quot;testvar = {{ testvar }}&quot;] ************************************ 
skipping: [127.0.0.1]

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

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

TASK: [group_by key={{ ansible_os_family }}] ********************************** 
changed: [127.0.0.1]

TASK: [fail msg="testvar = {{ testvar }}"] ************************************ 
skipping: [127.0.0.1]

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

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

TASK: [group_by key={{ansible_os_family}}] ************************************ 
changed: [127.0.0.1]

TASK: [fail msg=&quot;testvar = {{testvar}}&quot;] ************************************** 
failed: [127.0.0.1] =&gt; {&quot;failed&quot;: true}
msg: testvar = override FAIL

FATAL: all hosts have already failed -- aborting

PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/home/direvus/site.retry

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

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

TASK: [group_by key={{ansible_os_family}}] ************************************ 
changed: [127.0.0.1]

TASK: [fail msg="testvar = {{testvar}}"] ************************************** 
failed: [127.0.0.1] =&gt; {"failed": true}
msg: testvar = override FAIL

FATAL: all hosts have already failed -- aborting

PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/home/direvus/site.retry

127.0.0.1                  : ok=2    changed=1    unreachable=0    failed=1   

</code></pre></div>
<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>