From 08c593bee19e0c6660c84b2a0c8477b90238a469 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Wed, 11 Apr 2012 21:05:46 -0400 Subject: [PATCH] Warn if no hosts matched --- lib/ansible/callbacks.py | 9 +++++++++ lib/ansible/runner.py | 1 + test/TestPlayBook.py | 2 ++ 3 files changed, 12 insertions(+) diff --git a/lib/ansible/callbacks.py b/lib/ansible/callbacks.py index 5e8ab823fd4..0b36a62ab33 100755 --- a/lib/ansible/callbacks.py +++ b/lib/ansible/callbacks.py @@ -95,6 +95,9 @@ class DefaultRunnerCallbacks(object): def on_unreachable(self, host, res): pass + def on_no_hosts(self): + pass + ######################################################################## class CliRunnerCallbacks(DefaultRunnerCallbacks): @@ -120,6 +123,9 @@ class CliRunnerCallbacks(DefaultRunnerCallbacks): def on_error(self, 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): print utils.host_report_msg(host, self.options.module_name, result, self.options.one_line) @@ -159,6 +165,9 @@ class PlaybookRunnerCallbacks(DefaultRunnerCallbacks): def on_skipped(self, host): print "skipping: [%s]\n" % host + def on_no_hosts(self): + print "no hosts matched or remaining\n" + ######################################################################## class PlaybookCallbacks(object): diff --git a/lib/ansible/runner.py b/lib/ansible/runner.py index edd9763e552..3396c550266 100755 --- a/lib/ansible/runner.py +++ b/lib/ansible/runner.py @@ -750,6 +750,7 @@ class Runner(object): # find hosts that match the pattern hosts = self._match_hosts(self.pattern) if len(hosts) == 0: + self.callbacks.on_no_hosts() return dict(contacted={}, dark={}) hosts = [ (self,x) for x in hosts ] diff --git a/test/TestPlayBook.py b/test/TestPlayBook.py index 72c0b69ccae..9e04e254320 100644 --- a/test/TestPlayBook.py +++ b/test/TestPlayBook.py @@ -89,6 +89,8 @@ class TestCallbacks(object): def on_setup_secondary(self): pass + def on_no_hosts(self): + pass class TestPlaybook(unittest.TestCase):