Commit 95b371dd by James Cammarata

Use AnsibleFileNotFound instead of AnsibleParsingError when YAML files are not found

And update portions of code to expect the proper error.

Fixes #12512
parent 0250beb6
...@@ -27,7 +27,7 @@ import stat ...@@ -27,7 +27,7 @@ import stat
from yaml import load, YAMLError from yaml import load, YAMLError
from six import text_type, string_types 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.errors.yaml_strings import YAML_SYNTAX_ERROR
from ansible.parsing.vault import VaultLib from ansible.parsing.vault import VaultLib
from ansible.parsing.splitter import unquote from ansible.parsing.splitter import unquote
...@@ -158,7 +158,7 @@ class DataLoader(): ...@@ -158,7 +158,7 @@ class DataLoader():
raise AnsibleParserError("Invalid filename: '%s'" % str(file_name)) raise AnsibleParserError("Invalid filename: '%s'" % str(file_name))
if not self.path_exists(file_name) or not self.is_file(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 show_content = True
try: try:
...@@ -267,7 +267,7 @@ class DataLoader(): ...@@ -267,7 +267,7 @@ class DataLoader():
this_path = os.path.realpath(os.path.expanduser(vault_password_file)) this_path = os.path.realpath(os.path.expanduser(vault_password_file))
if not os.path.exists(this_path): 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): if self.is_executable(this_path):
try: try:
......
...@@ -33,7 +33,7 @@ except ImportError: ...@@ -33,7 +33,7 @@ except ImportError:
from ansible import constants as C from ansible import constants as C
from ansible.cli import CLI 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.inventory.host import Host
from ansible.parsing import DataLoader from ansible.parsing import DataLoader
from ansible.plugins.cache import FactCache from ansible.plugins.cache import FactCache
...@@ -268,12 +268,14 @@ class VariableManager: ...@@ -268,12 +268,14 @@ class VariableManager:
if data is not None: if data is not None:
for item in data: for item in data:
all_vars = combine_vars(all_vars, item) all_vars = combine_vars(all_vars, item)
break break
except AnsibleParserError as e: except AnsibleFileNotFound as e:
# we continue on loader failures # we continue on loader failures
continue continue
except AnsibleParserError as e:
raise
else: 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): except (UndefinedError, AnsibleUndefinedVariable):
if host is not None and self._fact_cache.get(host.name, dict()).get('module_setup') and task is not None: 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) raise AnsibleUndefinedVariable("an undefined variable was found when attempting to template the vars_files item '%s'" % vars_file_item, obj=vars_file_item)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment