Skip to content

Commit 0f0e38a

Browse files
committed
Add some analysis of general precedence rules
1 parent f61c7f5 commit 0f0e38a

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed

precedence/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,48 @@ as the source path and then run a job against it.
9797
It should encounter the same behavior (`testvar` being a, not b)
9898
because AWX, itself, implements a dumping-loading cycle with the `--export`
9999
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.

precedence/depth_win.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
b_parent:
2+
children:
3+
b_group:
4+
hosts:
5+
foohost:
6+
vars:
7+
testvar: b
8+
vars:
9+
testvar: b_parent
10+
a_parent:
11+
children:
12+
a_group:
13+
vars:
14+
testvar: a
15+
hosts:
16+
foohost:
17+
vars:
18+
testvar: a_parent

precedence/depth_win2.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
A:
2+
children:
3+
b_group:
4+
hosts:
5+
foohost:
6+
vars:
7+
testvar: b
8+
vars:
9+
testvar: A_parent
10+
B:
11+
children:
12+
a_group:
13+
vars:
14+
testvar: a
15+
hosts:
16+
foohost:
17+
vars:
18+
testvar: B_parent

precedence/depth_win3.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
A:
2+
children:
3+
b_group:
4+
hosts:
5+
foohost:
6+
vars:
7+
testvar: A_parent
8+
B:
9+
children:
10+
a_group:
11+
hosts:
12+
foohost:
13+
vars:
14+
testvar: B_parent

0 commit comments

Comments
 (0)