Abort a play at the start when no hosts matches, or no hosts are remaining

This change makes a distinction between no_hosts_matched and no_hosts_remaining.

In both cases we do not start facts-gathering, or run any tasks.

In the case that there are no more hosts remaining, we abort running tasks and abort the playbook.

I also cleaned up the leftovers from the previous patchsets, as these are no longer required.

This closes #1187.

Example playbook:

```yaml
---
- hosts: emptygroup
  tasks:
  - action: command date
  - action: command false

- hosts: all
  gather_facts: False
  tasks:
  - action: command ls
  - action: command false
  - action: command true

- hosts: all
  tasks:
  - action: command true
  - action: command false

- hosts: all
  tasks:
  - action: command pwd
```
This commit is contained in:
Dag Wieers 2012-10-02 15:15:55 +02:00
commit 20c1a67711
3 changed files with 29 additions and 6 deletions

View file

@ -414,6 +414,14 @@ class PlaybookCallbacks(object):
def on_notify(self, host, handler):
call_callback_module('playbook_on_notify', host, handler)
def on_no_hosts_matched(self):
print stringc("no hosts matched", 'red')
call_callback_module('playbook_on_no_hosts_matched')
def on_no_hosts_remaining(self):
print stringc("\nFATAL: all hosts have already failed -- aborting", 'red')
call_callback_module('playbook_on_no_hosts_remaining')
def on_task_start(self, name, is_conditional):
msg = "TASK: [%s]" % name
if is_conditional: