Skip to content

Commit

Permalink
Properly sort groups by name as well as depth when getting vars
Browse files Browse the repository at this point in the history
Fixes #17243
  • Loading branch information
jimi-c committed Nov 19, 2016
1 parent 3ce19f4 commit 23b5764
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/ansible/inventory/host.py
Expand Up @@ -138,6 +138,6 @@ def get_vars(self):
def get_group_vars(self):
results = {}
groups = self.get_groups()
for group in sorted(groups, key=lambda g: g.depth):
for group in sorted(groups, key=lambda g: (g.depth, g.name)):
results = combine_vars(results, group.get_vars())
return results
2 changes: 1 addition & 1 deletion lib/ansible/vars/__init__.py
Expand Up @@ -252,7 +252,7 @@ def get_vars(self, loader, play=None, host=None, task=None, include_hostvars=Tru
# we merge in vars from groups specified in the inventory (INI or script)
all_vars = combine_vars(all_vars, host.get_group_vars())

for group in sorted(host.get_groups(), key=lambda g: g.depth):
for group in sorted(host.get_groups(), key=lambda g: (g.depth, g.name)):
if group.name in self._group_vars_files and group.name != 'all':
for data in self._group_vars_files[group.name]:
data = preprocess_vars(data)
Expand Down

0 comments on commit 23b5764

Please sign in to comment.