mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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 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:
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue