Make the loop variable (item by default) settable per task

Required for include+with* tasks which may include files that also
have tasks containing a with* loop.

Fixes #12736
This commit is contained in:
James Cammarata
2015-10-23 03:27:09 -04:00
parent ff0296f98a
commit 6eefc11c39
11 changed files with 151 additions and 36 deletions

View File

@@ -9,13 +9,17 @@
# Make sure we start fresh
- name: remove rpm dependencies for postgresql test
package: name={{ item }} state=absent
package: name={{ postgresql_package_item }} state=absent
with_items: "{{postgresql_packages}}"
loop_control:
loop_var: postgresql_package_item
when: ansible_os_family == "RedHat"
- name: remove dpkg dependencies for postgresql test
apt: name={{ item }} state=absent
apt: name={{ postgresql_package_item }} state=absent
with_items: "{{postgresql_packages}}"
loop_control:
loop_var: postgresql_package_item
when: ansible_pkg_mgr == 'apt'
- name: remove old db (red hat)
@@ -35,13 +39,17 @@
when: ansible_os_family == "Debian"
- name: install rpm dependencies for postgresql test
package: name={{ item }} state=latest
package: name={{ postgresql_package_item }} state=latest
with_items: "{{postgresql_packages}}"
loop_control:
loop_var: postgresql_package_item
when: ansible_os_family == "RedHat"
- name: install dpkg dependencies for postgresql test
apt: name={{ item }} state=latest
apt: name={{ postgresql_package_item }} state=latest
with_items: "{{postgresql_packages}}"
loop_control:
loop_var: postgresql_package_item
when: ansible_pkg_mgr == 'apt'
- name: Initialize postgres (systemd)

View File

@@ -212,22 +212,22 @@ class TestTaskExecutor(unittest.TestCase):
# No replacement
#
mock_task.action = 'yum'
new_items = te._squash_items(items=items, variables=job_vars)
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
self.assertEqual(new_items, ['a', 'b', 'c'])
mock_task.action = 'foo'
mock_task.args={'name': '{{item}}'}
new_items = te._squash_items(items=items, variables=job_vars)
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
self.assertEqual(new_items, ['a', 'b', 'c'])
mock_task.action = 'yum'
mock_task.args={'name': 'static'}
new_items = te._squash_items(items=items, variables=job_vars)
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
self.assertEqual(new_items, ['a', 'b', 'c'])
mock_task.action = 'yum'
mock_task.args={'name': '{{pkg_mgr}}'}
new_items = te._squash_items(items=items, variables=job_vars)
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
self.assertEqual(new_items, ['a', 'b', 'c'])
#
@@ -235,12 +235,12 @@ class TestTaskExecutor(unittest.TestCase):
#
mock_task.action = 'yum'
mock_task.args={'name': '{{item}}'}
new_items = te._squash_items(items=items, variables=job_vars)
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
self.assertEqual(new_items, [['a','c']])
mock_task.action = '{{pkg_mgr}}'
mock_task.args={'name': '{{item}}'}
new_items = te._squash_items(items=items, variables=job_vars)
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
self.assertEqual(new_items, [['a', 'c']])
#
@@ -249,7 +249,7 @@ class TestTaskExecutor(unittest.TestCase):
#
mock_task.action = '{{unknown}}'
mock_task.args={'name': '{{item}}'}
new_items = te._squash_items(items=items, variables=job_vars)
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
self.assertEqual(new_items, ['a', 'b', 'c'])
items = [dict(name='a', state='present'),
@@ -257,7 +257,7 @@ class TestTaskExecutor(unittest.TestCase):
dict(name='c', state='present')]
mock_task.action = 'yum'
mock_task.args={'name': '{{item}}'}
new_items = te._squash_items(items=items, variables=job_vars)
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
self.assertEqual(new_items, items)
def test_task_executor_execute(self):