changes to not clear the setup cache between runs, and also decide to run plays with no tasks

in them if it looks like they are not tagged, because if that is the case, then we may just
be gathering facts about them.
pull/694/head
Michael DeHaan 13 years ago
parent f371092845
commit da4562f495

@ -24,6 +24,8 @@ import os
import collections import collections
from play import Play from play import Play
SETUP_CACHE = collections.defaultdict(dict)
class PlayBook(object): class PlayBook(object):
''' '''
runs an ansible playbook, given as a datastructure or YAML filename. 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 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: if playbook is None or callbacks is None or runner_callbacks is None or stats is None:
raise Exception('missing required arguments') raise Exception('missing required arguments')
@ -148,7 +150,6 @@ class PlayBook(object):
# loop through all patterns and run them # loop through all patterns and run them
self.callbacks.on_start() self.callbacks.on_start()
for play_ds in self.playbook: for play_ds in self.playbook:
self.SETUP_CACHE = collections.defaultdict(dict)
self._run_play(Play(self,play_ds)) self._run_play(Play(self,play_ds))
# summarize the results # summarize the results
@ -219,11 +220,6 @@ class PlayBook(object):
if results is None: if results is None:
results = {} 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) self.stats.compute(results)
# flag which notify handlers need to be run # flag which notify handlers need to be run

@ -178,15 +178,20 @@ class Play(object):
def should_run(self, tags): def should_run(self, tags):
''' does the play match any of the tags? ''' ''' does the play match any of the tags? '''
if len(self._tasks) == 0: tags_counted = 0
return False
for task in self._tasks: for task in self._tasks:
for task_tag in task.tags: for task_tag in task.tags:
tags_counted = tags_counted + 1
if task_tag in tags: if task_tag in tags:
return True return True
if tags_counted > 0:
return False return False
# didn't tag the play, and the play contains no steps
# so assume we just want to gather facts
return True
# ************************************************* # *************************************************
def _has_vars_in(self, msg): def _has_vars_in(self, msg):

Loading…
Cancel
Save