diff --git a/lib/ansible/parsing/__init__.py b/lib/ansible/parsing/__init__.py index 4efb19f16d..dcd76208ac 100644 --- a/lib/ansible/parsing/__init__.py +++ b/lib/ansible/parsing/__init__.py @@ -27,7 +27,7 @@ import stat from yaml import load, YAMLError from six import text_type, string_types -from ansible.errors import AnsibleParserError +from ansible.errors import AnsibleFileNotFound, AnsibleParserError from ansible.errors.yaml_strings import YAML_SYNTAX_ERROR from ansible.parsing.vault import VaultLib from ansible.parsing.splitter import unquote @@ -158,7 +158,7 @@ class DataLoader(): raise AnsibleParserError("Invalid filename: '%s'" % str(file_name)) if not self.path_exists(file_name) or not self.is_file(file_name): - raise AnsibleParserError("the file_name '%s' does not exist, or is not readable" % file_name) + raise AnsibleFileNotFound("the file_name '%s' does not exist, or is not readable" % file_name) show_content = True try: @@ -267,7 +267,7 @@ class DataLoader(): this_path = os.path.realpath(os.path.expanduser(vault_password_file)) if not os.path.exists(this_path): - raise AnsibleError("The vault password file %s was not found" % this_path) + raise AnsibleFileNotFound("The vault password file %s was not found" % this_path) if self.is_executable(this_path): try: diff --git a/lib/ansible/vars/__init__.py b/lib/ansible/vars/__init__.py index 8822742230..eabc6c38dc 100644 --- a/lib/ansible/vars/__init__.py +++ b/lib/ansible/vars/__init__.py @@ -33,7 +33,7 @@ except ImportError: from ansible import constants as C from ansible.cli import CLI -from ansible.errors import AnsibleError, AnsibleParserError, AnsibleUndefinedVariable +from ansible.errors import AnsibleError, AnsibleParserError, AnsibleUndefinedVariable, AnsibleFileNotFound from ansible.inventory.host import Host from ansible.parsing import DataLoader from ansible.plugins.cache import FactCache @@ -268,12 +268,14 @@ class VariableManager: if data is not None: for item in data: all_vars = combine_vars(all_vars, item) - break - except AnsibleParserError as e: + break + except AnsibleFileNotFound as e: # we continue on loader failures continue + except AnsibleParserError as e: + raise else: - raise AnsibleError("vars file %s was not found" % vars_file_item) + raise AnsibleFileNotFound("vars file %s was not found" % vars_file_item) except (UndefinedError, AnsibleUndefinedVariable): if host is not None and self._fact_cache.get(host.name, dict()).get('module_setup') and task is not None: raise AnsibleUndefinedVariable("an undefined variable was found when attempting to template the vars_files item '%s'" % vars_file_item, obj=vars_file_item)