diff --git a/lib/ansible/playbook/__init__.py b/lib/ansible/playbook/__init__.py index 796a570ff52..959a3279f11 100644 --- a/lib/ansible/playbook/__init__.py +++ b/lib/ansible/playbook/__init__.py @@ -24,6 +24,8 @@ import os import collections from play import Play +SETUP_CACHE = collections.defaultdict(dict) + class PlayBook(object): ''' runs an ansible playbook, given as a datastructure or YAML filename. @@ -75,7 +77,7 @@ class PlayBook(object): sudo: if not specified per play, requests all plays use sudo mode """ - self.SETUP_CACHE = collections.defaultdict(dict) + self.SETUP_CACHE = SETUP_CACHE if playbook is None or callbacks is None or runner_callbacks is None or stats is None: raise Exception('missing required arguments') @@ -148,7 +150,6 @@ class PlayBook(object): # loop through all patterns and run them self.callbacks.on_start() for play_ds in self.playbook: - self.SETUP_CACHE = collections.defaultdict(dict) self._run_play(Play(self,play_ds)) # summarize the results @@ -219,11 +220,6 @@ class PlayBook(object): if results is None: results = {} - # add facts to the global setup cache - for host, result in results['contacted'].iteritems(): - facts = result.get('ansible_facts', {}) - self.SETUP_CACHE[host].update(facts) - self.stats.compute(results) # flag which notify handlers need to be run diff --git a/lib/ansible/playbook/play.py b/lib/ansible/playbook/play.py index 39ca7ed58eb..a6fe723e2fa 100644 --- a/lib/ansible/playbook/play.py +++ b/lib/ansible/playbook/play.py @@ -178,14 +178,19 @@ class Play(object): def should_run(self, tags): ''' does the play match any of the tags? ''' - if len(self._tasks) == 0: - return False - + tags_counted = 0 for task in self._tasks: for task_tag in task.tags: + tags_counted = tags_counted + 1 if task_tag in tags: return True - return False + + if tags_counted > 0: + return False + + # didn't tag the play, and the play contains no steps + # so assume we just want to gather facts + return True # *************************************************