From 2d01966e87a20e004af41af3dbca59426ae51c17 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Fri, 14 Sep 2018 22:47:50 -0400 Subject: [PATCH] better error on empty playbook fixes #45480 --- lib/ansible/playbook/__init__.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/ansible/playbook/__init__.py b/lib/ansible/playbook/__init__.py index f365566f90..6c07250721 100644 --- a/lib/ansible/playbook/__init__.py +++ b/lib/ansible/playbook/__init__.py @@ -79,10 +79,13 @@ class Playbook: except UnicodeDecodeError as e: raise AnsibleParserError("Could not read playbook (%s) due to encoding issues: %s" % (file_name, to_native(e))) - if not isinstance(ds, list): - # restore the basedir in case this error is caught and handled + # check for errors and restore the basedir in case this error is caught and handled + if not ds: self._loader.set_basedir(cur_basedir) - raise AnsibleParserError("playbooks must be a list of plays", obj=ds) + raise AnsibleParserError("Empty playbook, nothing to do", obj=ds) + elif not isinstance(ds, list): + self._loader.set_basedir(cur_basedir) + raise AnsibleParserError("A playbook must be a list of plays, got a %s instead" % type(ds), obj=ds) # Parse the playbook entries. For plays, we simply parse them # using the Play() object, and includes are parsed using the