Use AnsibleFileNotFound instead of AnsibleParsingError when YAML files are not found
And update portions of code to expect the proper error. Fixes #12512
This commit is contained in:
parent
0250beb68a
commit
95b371dd60
2 changed files with 9 additions and 7 deletions
|
@ -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():
|
||||||
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():
|
||||||
|
|
||||||
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:
|
||||||
|
|
||||||
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
|
||||||
|
@ -269,11 +269,13 @@ class VariableManager:
|
||||||
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)
|
||||||
|
|
Loading…
Reference in a new issue