From 1950bcc14e66ca6c99c15dc5b13b37a66d87c2c6 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Thu, 14 Sep 2017 10:15:45 -0400 Subject: [PATCH] better error on bad playbook encoding --- lib/ansible/playbook/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/ansible/playbook/__init__.py b/lib/ansible/playbook/__init__.py index 5f6dfcc449..7391414949 100644 --- a/lib/ansible/playbook/__init__.py +++ b/lib/ansible/playbook/__init__.py @@ -23,7 +23,7 @@ import os from ansible import constants as C from ansible.errors import AnsibleParserError -from ansible.module_utils._text import to_text +from ansible.module_utils._text import to_text, to_native from ansible.playbook.play import Play from ansible.playbook.playbook_include import PlaybookInclude from ansible.plugins.loader import get_all_plugin_loaders @@ -74,7 +74,11 @@ class Playbook: if os.path.isdir(plugin_path): obj.add_directory(plugin_path) - ds = self._loader.load_from_file(os.path.basename(file_name)) + try: + ds = self._loader.load_from_file(os.path.basename(file_name)) + 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 self._loader.set_basedir(cur_basedir)