Repository: ansible/ansible

Issue:
group vars under group_vars/groupname broken
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report


##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
core

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.4.0 (devel 6dc2a6ce8b) last updated 2017/05/24 10:51:52 (GMT +300)
  config file = /home/lpolonen/.ansible.cfg
  configured module search path = [u'/home/lpolonen/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/lpolonen/git/ansible/lib/ansible
  executable location = /home/lpolonen/git/ansible/bin/ansible
  python version = 2.7.13 (default, Jan 13 2017, 10:15:16) [GCC 6.3.1 20161221 (Red Hat 6.3.1-1)]

```

##### CONFIGURATION
nothing significant

##### OS / ENVIRONMENT
Fedora 24

##### SUMMARY
<!--- Explain the problem briefly -->
Group variables no longer work from `group_vars/groupname/*`, failing every play.
Most likely broken by #23001 

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->

<!--- Paste example playbooks or commands between quotes below -->
```
ansible-playbook -i inventory testplay.yml
```

```yaml
---
- name: testplay
  hosts: all
  become: no
  tasks:
    - debug: msg=foo
```

tree group_vars
```
group_vars
└── testgroup
    └── file1

1 directory, 1 file
```

cat inventory
```
[testgroup]
localhost
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
```

PLAY [testplay] ****************************************************************************************************************************************************************************************************

TASK [Gathering Facts] *********************************************************************************************************************************************************************************************
ok: [localhost]

TASK [debug] *******************************************************************************************************************************************************************************************************
ok: [localhost] => {
    "changed": false, 
    "msg": "foo"
}
```
##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->
<!--- Paste verbatim command output between quotes below -->
```
PLAY [testplay] ****************************************************************************************************************************************************************************************************
ERROR! the file_name '/home/lpolonen/tmp/file1' does not exist, or is not readable

```



Discussion:
looks like an issue with the host_group_vars plugin 'loosing' the group name

Resolving patch:
diff --git a/lib/ansible/plugins/vars/host_group_vars.py b/lib/ansible/plugins/vars/host_group_vars.py
--- a/lib/ansible/plugins/vars/host_group_vars.py
+++ b/lib/ansible/plugins/vars/host_group_vars.py
@@ -99,10 +99,11 @@ def _find_vars_files(self, path, name):
                 if os.path.isdir(full_path):
                     # matched dir name, so use all files included recursively
                     for spath in os.listdir(full_path):
-                        if os.path.isdir(spath):
-                            found.extend(self._find_vars_files(spath, name))
+                        full_spath = os.path.join(full_path, spath)
+                        if os.path.isdir(full_spath):
+                            found.extend(self._find_vars_files(full_spath, ''))
                         else:
-                            found.append(spath)
+                            found.append(full_spath)
                 else:
                     found.append(full_path)
         return found


Test patch: