diff --git a/lib/ansible/playbook/play.py b/lib/ansible/playbook/play.py index 706d3962224..892c7ec2f50 100644 --- a/lib/ansible/playbook/play.py +++ b/lib/ansible/playbook/play.py @@ -103,6 +103,8 @@ class Play(Base, Taggable, CollectionSearch): @staticmethod def load(data, variable_manager=None, loader=None, vars=None): if ('name' not in data or data['name'] is None) and 'hosts' in data: + if data['hosts'] is None or all(host is None for host in data['hosts']): + raise AnsibleParserError("Hosts list cannot be empty - please check your playbook") if isinstance(data['hosts'], list): data['name'] = ','.join(data['hosts']) else: