From 3fd94769dc0d74e06e26dcde049f47c26edb8286 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Mon, 23 May 2016 14:53:18 -0400 Subject: [PATCH] Save and restore the loader's basedir when loading playbooks Fixes #15930 --- lib/ansible/playbook/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/ansible/playbook/__init__.py b/lib/ansible/playbook/__init__.py index 947224d61fc..865d3877ea7 100644 --- a/lib/ansible/playbook/__init__.py +++ b/lib/ansible/playbook/__init__.py @@ -61,6 +61,7 @@ class Playbook: self._basedir = os.path.normpath(os.path.join(self._basedir, os.path.dirname(file_name))) # set the loaders basedir + cur_basedir = self._loader.get_basedir() self._loader.set_basedir(self._basedir) self._file_name = file_name @@ -74,6 +75,8 @@ class Playbook: ds = self._loader.load_from_file(os.path.basename(file_name)) if not isinstance(ds, list): + # restore the basedir in case this error is caught and handled + self._loader.set_basedir(cur_basedir) raise AnsibleParserError("playbooks must be a list of plays", obj=ds) # Parse the playbook entries. For plays, we simply parse them @@ -81,6 +84,8 @@ class Playbook: # PlaybookInclude() object for entry in ds: if not isinstance(entry, dict): + # restore the basedir in case this error is caught and handled + self._loader.set_basedir(cur_basedir) raise AnsibleParserError("playbook entries must be either a valid play or an include statement", obj=entry) if 'include' in entry: @@ -93,6 +98,9 @@ class Playbook: entry_obj = Play.load(entry, variable_manager=variable_manager, loader=self._loader) self._entries.append(entry_obj) + # we're done, so restore the old basedir in the loader + self._loader.set_basedir(cur_basedir) + def get_loader(self): return self._loader