From 09ef7751e10c44808d6b82e7d6974f190d78f7e9 Mon Sep 17 00:00:00 2001 From: Vincent Hardion Date: Wed, 24 Jul 2013 14:10:15 +0200 Subject: [PATCH] Fix nested loop for more than 3 elements - combine flatten list for each nested level instead once at the end --- lib/ansible/runner/lookup_plugins/nested.py | 2 +- test/lookup_plugins.yml | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/ansible/runner/lookup_plugins/nested.py b/lib/ansible/runner/lookup_plugins/nested.py index e0d0e504a36..66e6b2413f7 100644 --- a/lib/ansible/runner/lookup_plugins/nested.py +++ b/lib/ansible/runner/lookup_plugins/nested.py @@ -34,7 +34,7 @@ def combine(a,b): results = [] for x in a: for y in b: - results.append([x,y]) + results.append(flatten([x,y])) return results class LookupModule(object): diff --git a/test/lookup_plugins.yml b/test/lookup_plugins.yml index 7d2141cc0d5..9df2f46fc96 100644 --- a/test/lookup_plugins.yml +++ b/test/lookup_plugins.yml @@ -55,6 +55,15 @@ action: copy src=sample.j2 dest=/tmp/ansible-test-with_lines-data - name: cleanup test file action: file path=/tmp/ansible-test-with_lines-data state=absent + + # Test nested loop + - name: test nested loop with more than 3 elements + command: test "{{ item[0] }}, {{ item[1] }}, {{ item[2] }}, {{ item[3] }}" = "red, 1, up, top" + with_nested: + - [ 'red' ] + - [ 1 ] + - [ 'up'] + - [ 'top'] # password lookup plugin - name: ensure test file doesn't exist