mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-26 20:31:27 -07:00
Reworking the way end of role detection is done
Rather than trying to enumerate tasks or track an ever changing cur_role flag in PlayIterator, this change simply sets a flag on the last block in the list of blocks returned by Role.compile(). The PlayIterator then checks for that flag when the cur_block number is incremented, and marks the role as complete if the given host had any tasks run in that role. Fixes #20224
This commit is contained in:
parent
d7967aa3a1
commit
cae682607c
4 changed files with 56 additions and 99 deletions
|
@ -87,8 +87,22 @@ class TestPlayIterator(unittest.TestCase):
|
|||
- debug: msg="this is a post_task"
|
||||
""",
|
||||
'/etc/ansible/roles/test_role/tasks/main.yml': """
|
||||
- debug: msg="this is a role task"
|
||||
- name: role task
|
||||
debug: msg="this is a role task"
|
||||
- block:
|
||||
- name: role block task
|
||||
debug: msg="inside block in role"
|
||||
always:
|
||||
- name: role always task
|
||||
debug: msg="always task in block in role"
|
||||
- include: foo.yml
|
||||
- name: role task after include
|
||||
debug: msg="after include in role"
|
||||
""",
|
||||
'/etc/ansible/roles/test_role/tasks/foo.yml': """
|
||||
- name: role included task
|
||||
debug: msg="this is task in an include from a role"
|
||||
"""
|
||||
})
|
||||
|
||||
mock_var_manager = MagicMock()
|
||||
|
@ -141,6 +155,31 @@ class TestPlayIterator(unittest.TestCase):
|
|||
(host_state, task) = itr.get_next_task_for_host(hosts[0])
|
||||
self.assertIsNotNone(task)
|
||||
self.assertEqual(task.action, 'debug')
|
||||
self.assertEqual(task.name, "role task")
|
||||
self.assertIsNotNone(task._role)
|
||||
# role block task
|
||||
(host_state, task) = itr.get_next_task_for_host(hosts[0])
|
||||
self.assertIsNotNone(task)
|
||||
self.assertEqual(task.action, 'debug')
|
||||
self.assertEqual(task.name, "role block task")
|
||||
self.assertIsNotNone(task._role)
|
||||
# role block always task
|
||||
(host_state, task) = itr.get_next_task_for_host(hosts[0])
|
||||
self.assertIsNotNone(task)
|
||||
self.assertEqual(task.action, 'debug')
|
||||
self.assertEqual(task.name, "role always task")
|
||||
self.assertIsNotNone(task._role)
|
||||
# role include task
|
||||
#(host_state, task) = itr.get_next_task_for_host(hosts[0])
|
||||
#self.assertIsNotNone(task)
|
||||
#self.assertEqual(task.action, 'debug')
|
||||
#self.assertEqual(task.name, "role included task")
|
||||
#self.assertIsNotNone(task._role)
|
||||
# role task after include
|
||||
(host_state, task) = itr.get_next_task_for_host(hosts[0])
|
||||
self.assertIsNotNone(task)
|
||||
self.assertEqual(task.action, 'debug')
|
||||
self.assertEqual(task.name, "role task after include")
|
||||
self.assertIsNotNone(task._role)
|
||||
# regular play task
|
||||
(host_state, task) = itr.get_next_task_for_host(hosts[0])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue