@@ -97,3 +97,48 @@ as the source path and then run a job against it.
97
97
It should encounter the same behavior (` testvar ` being a, not b)
98
98
because AWX, itself, implements a dumping-loading cycle with the ` --export `
99
99
flag as a basic component of its inventory system.
100
+
101
+ ### Depth Sort
102
+
103
+ Group resolution order is very non-trivial, similar to python MRO complexity.
104
+ This method is the best summary of what happens in my research.
105
+
106
+ ``` python
107
+ def sort_groups (groups ):
108
+ return sorted (groups, key = lambda g : (g.depth, g.priority, g.name))
109
+ ```
110
+
111
+ This is called in order to give the full group list (parents and ancestors) of a host.
112
+ The ` depth ` here increases with the distance from the root "all" group.
113
+
114
+ An example is given at ` depth_win.yml ` .
115
+
116
+ It is established from the prior example that "b_group" will come at
117
+ higher precedence than an "a_group" at the same level due to the alphabetical
118
+ ordering, the ` g.name ` criteria.
119
+
120
+ The ` sorted ` method puts the "higher" value last, which can be "b_group" due
121
+ to being later in the alphabet, or 2 (as opposed to 1), meaning "further down
122
+ the tree" of the group graph.
123
+ In other words, this example shows leaf nodes winning over parent nodes.
124
+
125
+ In this example the "b" variable wins.
126
+
127
+ An example to show nuance is given at ` depth_win2.yml ` .
128
+ In this case, the parent names are switched, so parentage is A->b an B->a.
129
+ The result here isn't surprising, because the parentage doesn't matter.
130
+
131
+ In this case, too, the "b" variable wins.
132
+
133
+ Depth is given the highest priority of all, but this is strange.
134
+ Often times, the greatest depth group winning isn't the most intuitive.
135
+ An example at ` depth_win3.yml ` is given.
136
+ In this case, the parentage is still A->b and B->a, but the b and a vars are removed.
137
+ Remember that in the last example, the "b" group wins, but in this example the "B" group wins.
138
+ This is surprising because adherence to the "path" isn't maintained.
139
+ The parent "B" group is a parent of the lower-precedence "a" group.
140
+
141
+ In this case, the "B_parent" variable wins.
142
+
143
+ As the sort suggests, the exact relationships between groups doesn't matter,
144
+ aside from the depth metric that it develops on the groups.
0 commit comments