enforce required config

(cherry picked from commit cbedbd3c9c)
(cherry picked from commit bcabbe33c8)
pull/41006/head
Brian Coca 7 years ago committed by Matt Clay
parent 8f2c34fc69
commit 6e7bdb04ee

@ -343,11 +343,20 @@ class ConfigManager(object):
# set default if we got here w/o a value # set default if we got here w/o a value
if value is None: if value is None:
value = defs[config].get('default') if defs[config].get('required', False):
origin = 'default' entry = ''
# skip typing as this is a temlated default that will be resolved later in constants, which has needed vars if plugin_type:
if plugin_type is None and isinstance(value, string_types) and (value.startswith('{{') and value.endswith('}}')): entry += 'plugin_type: %s ' % plugin_type
return value, origin if plugin_name:
entry += 'plugin: %s ' % plugin_name
entry += 'setting: %s ' % config
raise AnsibleError("No setting was provided for required configuration %s" % (entry))
else:
value = defs[config].get('default')
origin = 'default'
# skip typing as this is a temlated default that will be resolved later in constants, which has needed vars
if plugin_type is None and isinstance(value, string_types) and (value.startswith('{{') and value.endswith('}}')):
return value, origin
# ensure correct type # ensure correct type
try: try:

@ -11,7 +11,7 @@ DOCUMENTATION = """
description: description:
- Retrieves the value of an Ansible variable. - Retrieves the value of an Ansible variable.
options: options:
_term: _terms:
description: The variable names to look up. description: The variable names to look up.
required: True required: True
default: default:
@ -69,6 +69,7 @@ class LookupModule(LookupBase):
self._templar.set_available_variables(variables) self._templar.set_available_variables(variables)
myvars = getattr(self._templar, '_available_variables', {}) myvars = getattr(self._templar, '_available_variables', {})
self.set_option('_terms', terms)
self.set_options(direct=kwargs) self.set_options(direct=kwargs)
default = self.get_option('default') default = self.get_option('default')

Loading…
Cancel
Save