Hello,
An example is welcomed, but I don't want to see it sprawling in the
commit message, and I still find this hard to understand.As such I think this does not fit our complexity threshold criteria.
First of all, I think that commit messages are really important for
understanding changes. I see no problem with them being lengthy and I
think including examples in them can only add to their quality. That
said, if you absolutely think that this particular commit message should
not include an example, I can fix it for you.
As for the functionality that this commit gives us, perhaps it would
help your understanding of this if you think of a nested loop as a tree.
I am copying from one of my posts in the ansible-project list:
With my addition, with_nested is extended allowing you to use item.0,
item.1, etc... in your expressions. The numbers 0, 1, 2, etc.. denote
the loop level. 0 is for the first (outer) loop level, 1 is for one
level deeper, 2 is for one more level deeper, etc... Nothing more,
nothing less, but this addition is quite powerful because it gives you
the ability, in each possible loop branch (think of a nested loop as a
tree, see below), to reference back to the values that were evaluated
in previous loop levels (nodes) in the same branch.with_nested:
- ['a', 'b', 'c']
- ['d', 'e', 'f']
- item.0,------ 'd' ----- 'a'
/
'a' -------- 'e' ----- 'a'
\
`------ 'f' ----- 'a',------ 'd' ----- 'b'
/
'b' -------- 'e' ----- 'b'
\
`------ 'f' ----- 'b'.------ 'd' ----- 'c'
/
'c' -------- 'e' ----- 'c'
\
`------ 'f' ----- 'c'0 1 2 <-- loop levels
So, if you are in the 'a' branch of the nested loop, item.0 gives you
'a'. If you are in the 'b' branch, it gives you 'b' and if you are in
the 'c' branch it gives you 'c'.
I am not doing magic. I just follow the nested loop tree and use the
already-available ability to inject things in the template engine. For
each branch in the nested loop, I inject an "item" var with values
corresponding to nodes in that branch. I believe that other developers
could understand this.
Besides, if you still find it difficult to understand this or explain it
to others, please just merge it and make it an undocumented feature. Not
only it will not hurt anyone (it does not break current deployments),
but it will also help people who understand this to do nested loops that
cannot be done without this. So, I do not see a practical reason for
this not to be merged.