diff --git a/lib/ansible/executor/playbook_executor.py b/lib/ansible/executor/playbook_executor.py index 91d5a69fc1..1a7301992b 100644 --- a/lib/ansible/executor/playbook_executor.py +++ b/lib/ansible/executor/playbook_executor.py @@ -25,6 +25,7 @@ from ansible import constants as C from ansible.errors import * from ansible.executor.task_queue_manager import TaskQueueManager from ansible.playbook import Playbook +from ansible.playbook.role import role_reset_has_run from ansible.plugins import module_loader from ansible.template import Templar @@ -83,6 +84,10 @@ class PlaybookExecutor: self._display.vv('%d plays in %s' % (len(plays), playbook_path)) for play in plays: + # clear out the flag on all roles indicating they had any tasks run + role_reset_has_run() + + # clear any filters which may have been applied to the inventory self._inventory.remove_restriction() # Create a temporary copy of the play here, so we can run post_validate diff --git a/lib/ansible/playbook/role/__init__.py b/lib/ansible/playbook/role/__init__.py index c84f0f8677..120b851ccf 100644 --- a/lib/ansible/playbook/role/__init__.py +++ b/lib/ansible/playbook/role/__init__.py @@ -41,7 +41,7 @@ from ansible.plugins import get_all_plugin_loaders, push_basedir from ansible.utils.vars import combine_vars -__all__ = ['Role', 'ROLE_CACHE', 'hash_params'] +__all__ = ['Role', 'ROLE_CACHE', 'hash_params', 'role_reset_has_run'] # FIXME: this should be a utility function, but can't be a member of # the role due to the fact that it would require the use of self @@ -70,6 +70,10 @@ def hash_params(params): # will be based on the repr() of the dictionary object) ROLE_CACHE = dict() +def role_reset_has_run(): + for (role_name, cached_roles) in ROLE_CACHE.iteritems(): + for (hashed_params, role) in cached_roles.iteritems(): + role._had_task_run = False class Role(Base, Become, Conditional, Taggable): diff --git a/lib/ansible/plugins/strategies/__init__.py b/lib/ansible/plugins/strategies/__init__.py index 9173a2f378..0452a7616d 100644 --- a/lib/ansible/plugins/strategies/__init__.py +++ b/lib/ansible/plugins/strategies/__init__.py @@ -195,7 +195,7 @@ class StrategyBase: # with the correct object and mark it as executed for (entry, role_obj) in ROLE_CACHE[task_result._task._role._role_name].iteritems(): hashed_entry = hash_params(task_result._task._role._role_params) - if entry == hashed_entry : + if entry == hashed_entry: role_obj._had_task_run = True ret_results.append(task_result)