mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
check options exist before forcing assignment
This commit is contained in:
parent
e1416138f9
commit
0209685f8d
1 changed files with 19 additions and 17 deletions
|
@ -121,23 +121,24 @@ def merge_hash(a, b):
|
||||||
|
|
||||||
def load_extra_vars(loader, options):
|
def load_extra_vars(loader, options):
|
||||||
extra_vars = {}
|
extra_vars = {}
|
||||||
for extra_vars_opt in options.extra_vars:
|
if hasattr(options, 'extra_vars'):
|
||||||
data = None
|
for extra_vars_opt in options.extra_vars:
|
||||||
extra_vars_opt = to_text(extra_vars_opt, errors='surrogate_or_strict')
|
data = None
|
||||||
if extra_vars_opt.startswith(u"@"):
|
extra_vars_opt = to_text(extra_vars_opt, errors='surrogate_or_strict')
|
||||||
# Argument is a YAML file (JSON is a subset of YAML)
|
if extra_vars_opt.startswith(u"@"):
|
||||||
data = loader.load_from_file(extra_vars_opt[1:])
|
# Argument is a YAML file (JSON is a subset of YAML)
|
||||||
elif extra_vars_opt and extra_vars_opt[0] in u'[{':
|
data = loader.load_from_file(extra_vars_opt[1:])
|
||||||
# Arguments as YAML
|
elif extra_vars_opt and extra_vars_opt[0] in u'[{':
|
||||||
data = loader.load(extra_vars_opt)
|
# Arguments as YAML
|
||||||
else:
|
data = loader.load(extra_vars_opt)
|
||||||
# Arguments as Key-value
|
else:
|
||||||
data = parse_kv(extra_vars_opt)
|
# Arguments as Key-value
|
||||||
|
data = parse_kv(extra_vars_opt)
|
||||||
|
|
||||||
if isinstance(data, MutableMapping):
|
if isinstance(data, MutableMapping):
|
||||||
extra_vars = combine_vars(extra_vars, data)
|
extra_vars = combine_vars(extra_vars, data)
|
||||||
else:
|
else:
|
||||||
raise AnsibleOptionsError("Invalid extra vars data supplied. '%s' could not be made into a dictionary" % extra_vars_opt)
|
raise AnsibleOptionsError("Invalid extra vars data supplied. '%s' could not be made into a dictionary" % extra_vars_opt)
|
||||||
|
|
||||||
return extra_vars
|
return extra_vars
|
||||||
|
|
||||||
|
@ -146,7 +147,8 @@ def load_options_vars(options, version):
|
||||||
options_vars = {}
|
options_vars = {}
|
||||||
# For now only return check mode, but we can easily return more
|
# For now only return check mode, but we can easily return more
|
||||||
# options if we need variables for them
|
# options if we need variables for them
|
||||||
options_vars['ansible_check_mode'] = options.check
|
if hasattr(options, 'check'):
|
||||||
|
options_vars['ansible_check_mode'] = options.check
|
||||||
options_vars['ansible_version'] = version
|
options_vars['ansible_version'] = version
|
||||||
return options_vars
|
return options_vars
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue