Repository: ansible/ansible

Issue:
helpful error "skipping: no hosts matched" is missing
<!---
Please do not report issues/requests related to Ansible modules here !!

Report them to the appropriate modules-core or modules-extras project:
  - https://github.com/ansible/ansible-modules-core/issues
  - https://github.com/ansible/ansible-modules-extras/issues

Also verify first that your issue/request is not already reported in GitHub
-->
##### ISSUE TYPE

<!--- Pick one below and delete the rest: -->
- Bug Report
##### COMPONENT NAME

ansible-playbook
##### ANSIBLE VERSION

<!--- Paste verbatim output from “ansible --version” between quotes below -->

```
# ansible --version
ansible 2.2.0 (devel dde7c11713) last updated 2016/09/22 15:38:51 (GMT +200)
  lib/ansible/modules/core: (devel 0f505378c3) last updated 2016/09/22 15:54:39 (GMT +200)
  lib/ansible/modules/extras: (devel 935a3ab2cb) last updated 2016/09/22 15:54:58 (GMT +200)
  config file =
  configured module search path = Default w/o overrides
```
##### CONFIGURATION

<!---  
-->

no settings changed in ansible.cfg
##### OS / ENVIRONMENT

<!---
Ubuntu 16.04
-->

Ubuntu 16.04
##### SUMMARY

Approximately two months ago (and maybe for many versions) ansible would output this error when the host was incorrect:

ansible-playbook main.yml

"skipping: no hosts matched".

However the latest devel version says
PLAY RECAP ****
Without the error.
##### STEPS TO REPRODUCE

<!---
For bugs, show exactly how to reproduce the problem.
For new features, show how the feature would be used.
-->

file main.yml:

<!--- Paste example playbooks or commands between quotes below -->

```

---
- hosts: 'wrongserver'
  remote_user: 'ansible'
  become: yes
  roles:
     - myrole
```

ansible-playbook main.yml

<!--- You can also paste gist.github.com links for larger files -->
##### EXPECTED RESULTS

<!--- What did you expect to happen when running the steps above? -->

"skipping: no hosts matched".
##### ACTUAL RESULTS

<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->

```
# ansible-playbook -vvvv  main.yml 
No config file found; using defaults
SSH password:
Loading callback plugin default of type stdout, v2.0 from /opt/github/ansible/lib/ansible/plugins/callback/__init__.pyc

PLAYBOOK: main.yml *************************************************************
1 plays in main.yml

PLAY RECAP *********************************************************************
```



Discussion:

Resolving patch:
diff --git a/lib/ansible/executor/playbook_executor.py b/lib/ansible/executor/playbook_executor.py
--- a/lib/ansible/executor/playbook_executor.py
+++ b/lib/ansible/executor/playbook_executor.py
@@ -142,12 +142,11 @@ def run(self):
 
                         break_play = False
                         # we are actually running plays
-                        for batch in self._get_serialized_batches(new_play):
-                            if len(batch) == 0:
-                                self._tqm.send_callback('v2_playbook_on_play_start', new_play)
-                                self._tqm.send_callback('v2_playbook_on_no_hosts_matched')
-                                break
-
+                        batches = self._get_serialized_batches(new_play)
+                        if len(batches) == 0:
+                            self._tqm.send_callback('v2_playbook_on_play_start', new_play)
+                            self._tqm.send_callback('v2_playbook_on_no_hosts_matched')
+                        for batch in batches:
                             # restrict the inventory to the hosts in the serialized batch
                             self._inventory.restrict_to_hosts(batch)
                             # and run it...


Test patch: