diff --git a/lib/ansible/playbook/__init__.py b/lib/ansible/playbook/__init__.py index ee8db143a3..fdedec78cd 100644 --- a/lib/ansible/playbook/__init__.py +++ b/lib/ansible/playbook/__init__.py @@ -224,9 +224,9 @@ class PlayBook(object): # if we have matched_tags, the play must be run. # if the play contains no tasks, assume we just want to gather facts - # in this case there are actually 4 meta tasks (handler flushes) not 0 - # tasks, so that's why there's a check against 4. - if (len(matched_tags) > 0 or len(play.tasks()) == 4): + # in this case there are actually 3 meta tasks (handler flushes) not 0 + # tasks, so that's why there's a check against 3 + if (len(matched_tags) > 0 or len(play.tasks()) == 3): plays.append(play) # if the playbook is invoked with --tags that don't exist at all in the playbooks diff --git a/lib/ansible/playbook/play.py b/lib/ansible/playbook/play.py index e7aceb5802..984a32d5cc 100644 --- a/lib/ansible/playbook/play.py +++ b/lib/ansible/playbook/play.py @@ -140,6 +140,8 @@ class Play(object): pre_tasks = [] for x in pre_tasks: new_tasks.append(x) + + # flush handlers after pre_tasks new_tasks.append(dict(meta='flush_handlers')) # variables if the role was parameterized (i.e. given as a hash) @@ -201,10 +203,11 @@ class Play(object): if type(post_tasks) != list: post_tasks = [] - new_tasks.append(dict(meta='flush_handlers')) new_tasks.extend(tasks) + # flush handlers after tasks + role tasks new_tasks.append(dict(meta='flush_handlers')) new_tasks.extend(post_tasks) + # flush handlers after post tasks new_tasks.append(dict(meta='flush_handlers')) new_handlers.extend(handlers) new_vars_files.extend(vars_files)