with_nested produces Cartesian product.

My pull request got rejected, so I’ll plead my case for https://github.com/ansible/ansible/pull/3503 :

The with_nested function/whatever it’s called is broken. It produces, incorrectly, a Cartesian product. Look at the end of this email for the output from 3x3 arrays.

Here’s the example that’s supposed to define how with_nested works:

https://github.com/ansible/ansible-examples/blob/master/language_features/loop_nested.yml

This playbook should produce 3 lines of output (so said, because there is no definition anywhere of how this is supposed to function or expected output). However, it produces the output from the end of the email.

This is because the combine function (in https://github.com/ansible/ansible/blob/devel/lib/ansible/runner/lookup_plugins/nested.py) looks like this, comments mine:

Yeah so when you first don’t understand something, ask.

It’s supposed to work EXACTLY that way, because it’s there to do nested loops.

As I’ve mentioned on IRC I’m totally open to another form that does the equivalent of zip.

​I don't think I ever used with_nested yet, but how I read the docs, I
actually expected it to behave as that latter.​
So +1 for showing what it does in the docs.

Serge

Yeah, I thought so too-- but let’s not break compatibility. Created a pull request for new transpose lookup method: https://github.com/ansible/ansible/pull/3511

It’s actually not in the docs outside of the language features part of ansible examples :slight_smile: