Warn if no hosts matched

This commit is contained in:
Michael DeHaan 2012-04-11 21:05:46 -04:00
parent f3489a53cd
commit 08c593bee1
3 changed files with 12 additions and 0 deletions

View file

@ -95,6 +95,9 @@ class DefaultRunnerCallbacks(object):
def on_unreachable(self, host, res): def on_unreachable(self, host, res):
pass pass
def on_no_hosts(self):
pass
######################################################################## ########################################################################
class CliRunnerCallbacks(DefaultRunnerCallbacks): class CliRunnerCallbacks(DefaultRunnerCallbacks):
@ -121,6 +124,9 @@ class CliRunnerCallbacks(DefaultRunnerCallbacks):
def on_error(self, host, err): def on_error(self, host, err):
print >>sys.stderr, "stderr: [%s] => %s\n" % (host, err) print >>sys.stderr, "stderr: [%s] => %s\n" % (host, err)
def on_no_hosts(self):
print >>sys.stderr, "no hosts matched\n"
def _on_any(self, host, result): def _on_any(self, host, result):
print utils.host_report_msg(host, self.options.module_name, result, self.options.one_line) print utils.host_report_msg(host, self.options.module_name, result, self.options.one_line)
if self.options.tree: if self.options.tree:
@ -159,6 +165,9 @@ class PlaybookRunnerCallbacks(DefaultRunnerCallbacks):
def on_skipped(self, host): def on_skipped(self, host):
print "skipping: [%s]\n" % host print "skipping: [%s]\n" % host
def on_no_hosts(self):
print "no hosts matched or remaining\n"
######################################################################## ########################################################################
class PlaybookCallbacks(object): class PlaybookCallbacks(object):

View file

@ -750,6 +750,7 @@ class Runner(object):
# find hosts that match the pattern # find hosts that match the pattern
hosts = self._match_hosts(self.pattern) hosts = self._match_hosts(self.pattern)
if len(hosts) == 0: if len(hosts) == 0:
self.callbacks.on_no_hosts()
return dict(contacted={}, dark={}) return dict(contacted={}, dark={})
hosts = [ (self,x) for x in hosts ] hosts = [ (self,x) for x in hosts ]

View file

@ -89,6 +89,8 @@ class TestCallbacks(object):
def on_setup_secondary(self): def on_setup_secondary(self):
pass pass
def on_no_hosts(self):
pass
class TestPlaybook(unittest.TestCase): class TestPlaybook(unittest.TestCase):