with_nested loop with more than 3 elements

921 views
Skip to first unread message

Vincent Hardion

unread,
Jul 23, 2013, 5:20:01 PM7/23/13
to ansible...@googlegroups.com
Hi,

I just want to confirm the behavior of "with_nested" before to submit a pull request.

If I add another element to the loop_nested example like this:
---
# this is a trivial example of how to do a nested loop.

- hosts: all
  tasks:
    - shell: echo "nested test a={{ item[0] }} b={{ item[1] }} c={{ item[2] }} d={{ item[3] }}"
      with_nested:
        - [ 'red', 'blue' ]
        - [ 1, 2 ]
        - [ 'up', 'down']
        - [ 'top', 'bottom']

Should the ouput be :
$ ansible-playbook -i hosts loop.yml 
...
TASK: [shell echo "nested test a={{item[0]}} b={{item[1]}} c={{item[2]}} d={{item[3]}}"] *** 
changed: [localhost] => (item=[['red', 1], 'up', 'top'])
changed: [localhost] => (item=[['red', 1], 'up', 'bottom'])
changed: [localhost] => (item=[['red', 1], 'down', 'top'])
changed: [localhost] => (item=[['red', 1], 'down', 'bottom'])
changed: [localhost] => (item=[['red', 2], 'up', 'top'])
changed: [localhost] => (item=[['red', 2], 'up', 'bottom'])
changed: [localhost] => (item=[['red', 2], 'down', 'top'])
changed: [localhost] => (item=[['red', 2], 'down', 'bottom'])
changed: [localhost] => (item=[['blue', 1], 'up', 'top'])
changed: [localhost] => (item=[['blue', 1], 'up', 'bottom'])
changed: [localhost] => (item=[['blue', 1], 'down', 'top'])
changed: [localhost] => (item=[['blue', 1], 'down', 'bottom'])
changed: [localhost] => (item=[['blue', 2], 'up', 'top'])
changed: [localhost] => (item=[['blue', 2], 'up', 'bottom'])
changed: [localhost] => (item=[['blue', 2], 'down', 'top'])
changed: [localhost] => (item=[['blue', 2], 'down', 'bottom'])

or

TASK: [shell echo "nested test a={{item[0]}} b={{item[1]}} c={{item[2]}} d={{item[3]}}"] *** 
changed: [localhost] => (item=['red', 1, 'up', 'top'])
changed: [localhost] => (item=['red', 1, 'up', 'bottom'])
changed: [localhost] => (item=['red', 1, 'down', 'top'])
changed: [localhost] => (item=['red', 1, 'down', 'bottom'])
changed: [localhost] => (item=['red', 2, 'up', 'top'])
changed: [localhost] => (item=['red', 2, 'up', 'bottom'])
changed: [localhost] => (item=['red', 2, 'down', 'top'])
changed: [localhost] => (item=['red', 2, 'down', 'bottom'])
changed: [localhost] => (item=['blue', 1, 'up', 'top'])
changed: [localhost] => (item=['blue', 1, 'up', 'bottom'])
changed: [localhost] => (item=['blue', 1, 'down', 'top'])
changed: [localhost] => (item=['blue', 1, 'down', 'bottom'])
changed: [localhost] => (item=['blue', 2, 'up', 'top'])
changed: [localhost] => (item=['blue', 2, 'up', 'bottom'])
changed: [localhost] => (item=['blue', 2, 'down', 'top'])
changed: [localhost] => (item=['blue', 2, 'down', 'bottom'])

Note in the second case, each element is a flatten list.

Thanks in advance.

Best regards,
Vincent

Michael DeHaan

unread,
Jul 23, 2013, 9:08:03 PM7/23/13
to ansible...@googlegroups.com
It should be the second.




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Michael DeHaan <mic...@ansibleworks.com>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/

Vincent Hardion

unread,
Jul 24, 2013, 1:37:14 PM7/24/13
to ansible...@googlegroups.com
Hi,

Here is the pull request included the unit test: https://github.com/ansible/ansible/pull/3654.

Cheers,
Vincent
Reply all
Reply to author
Forward
0 new messages