Skip to content
This repository

Group depths are incorrectly assigned by the default inventory parser #2016

Closed
zsolt-erl opened this Issue · 3 comments

3 participants

Zsolt Keszthelyi Michael DeHaan Daniel Hokka Zakrisson
Zsolt Keszthelyi

group.py incorrectly calculates group depth. This can cause groups on different levels to have the same depth. In turn this can result in reading the files under 'group_vars/' in the wrong order which means that a higher level group can overwrite a lower level group variable.

Here's the fix for group.py:

diff --git a/lib/ansible/inventory/group.py b/lib/ansible/inventory/group.py
index a460b48..88231a4 100644
--- a/lib/ansible/inventory/group.py
+++ b/lib/ansible/inventory/group.py
@@ -36,7 +36,10 @@ class Group(object):
         if self == group:
             raise Exception("can't add group to itself")
         self.child_groups.append(group)
-        group.depth = group.depth + 1
+        group.depth = self.depth + 1
         group.parent_groups.append(self)

     def add_host(self, host):
Michael DeHaan
Owner

Hi @zsolt-erl can you submit this as a pull request?

I'd like to include attribution to you in the source.

See https://help.github.com/articles/using-pull-requests if you need help!

Daniel Hokka Zakrisson

Note that it should be max([group.depth, self.depth + 1]) to get the correct value.

Michael DeHaan
Owner

Committed 0ad6ac4 per @dhozac's suggestion

Thanks folks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.