mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
fix environment validation, make setup exception
removed bare vars now environment inheritance correclty prepends this allows more local to override more general fixes #23180
This commit is contained in:
parent
729b0e3bee
commit
df5895e585
2 changed files with 34 additions and 19 deletions
|
@ -280,7 +280,7 @@ class Block(Base, Become, Conditional, Taggable):
|
||||||
dep.set_loader(loader)
|
dep.set_loader(loader)
|
||||||
|
|
||||||
def _get_attr_environment(self):
|
def _get_attr_environment(self):
|
||||||
return self._get_parent_attribute('environment', extend=True)
|
return self._get_parent_attribute('environment', extend=True, prepend=True)
|
||||||
|
|
||||||
def _get_parent_attribute(self, attr, extend=False, prepend=False):
|
def _get_parent_attribute(self, attr, extend=False, prepend=False):
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -21,7 +21,7 @@ __metaclass__ = type
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from ansible.errors import AnsibleError, AnsibleParserError
|
from ansible.errors import AnsibleError, AnsibleParserError, AnsibleUndefinedVariable
|
||||||
from ansible.module_utils.six import iteritems, string_types
|
from ansible.module_utils.six import iteritems, string_types
|
||||||
from ansible.module_utils._text import to_native
|
from ansible.module_utils._text import to_native
|
||||||
from ansible.parsing.mod_args import ModuleArgsParser
|
from ansible.parsing.mod_args import ModuleArgsParser
|
||||||
|
@ -258,25 +258,40 @@ class Task(Base, Conditional, Taggable, Become):
|
||||||
Override post validation of vars on the play, as we don't want to
|
Override post validation of vars on the play, as we don't want to
|
||||||
template these too early.
|
template these too early.
|
||||||
'''
|
'''
|
||||||
if value is None:
|
env = {}
|
||||||
return dict()
|
if value is not None:
|
||||||
|
|
||||||
elif isinstance(value, list):
|
print(value)
|
||||||
if len(value) == 1:
|
def _parse_env_kv(k, v):
|
||||||
return templar.template(value[0], convert_bare=True)
|
try:
|
||||||
else:
|
env[k] = templar.template(v, convert_bare=False)
|
||||||
env = []
|
except AnsibleUndefinedVariable as e:
|
||||||
|
if self.action in ('setup', 'gather_facts') and 'ansible_env' in to_native(e):
|
||||||
|
# ignore as fact gathering sets ansible_env
|
||||||
|
pass
|
||||||
|
|
||||||
|
if isinstance(value, list):
|
||||||
for env_item in value:
|
for env_item in value:
|
||||||
if isinstance(env_item, (string_types, AnsibleUnicode)) and env_item in templar._available_variables:
|
if isinstance(env_item, dict):
|
||||||
env[env_item] = templar.template(env_item, convert_bare=False)
|
for k in env_item:
|
||||||
elif isinstance(value, dict):
|
_parse_env_kv(k, env_item[k])
|
||||||
env = dict()
|
else:
|
||||||
for env_item in value:
|
isdict = templar.template(env_item, convert_bare=False)
|
||||||
if isinstance(env_item, (string_types, AnsibleUnicode)) and env_item in templar._available_variables:
|
if isinstance(isdict, dict):
|
||||||
env[env_item] = templar.template(value[env_item], convert_bare=False)
|
env.update(isdict)
|
||||||
|
else:
|
||||||
|
display.warning("could not parse environment value, skipping: %s" % value)
|
||||||
|
|
||||||
# at this point it should be a simple string
|
elif isinstance(value, dict):
|
||||||
return templar.template(value, convert_bare=True)
|
# should not really happen
|
||||||
|
env = dict()
|
||||||
|
for env_item in value:
|
||||||
|
_parse_env_kv(env_item, value[env_item])
|
||||||
|
else:
|
||||||
|
# at this point it should be a simple string, also should not happen
|
||||||
|
env = templar.template(value, convert_bare=False)
|
||||||
|
|
||||||
|
return env
|
||||||
|
|
||||||
def _post_validate_changed_when(self, attr, value, templar):
|
def _post_validate_changed_when(self, attr, value, templar):
|
||||||
'''
|
'''
|
||||||
|
@ -410,7 +425,7 @@ class Task(Base, Conditional, Taggable, Become):
|
||||||
'''
|
'''
|
||||||
Override for the 'tags' getattr fetcher, used from Base.
|
Override for the 'tags' getattr fetcher, used from Base.
|
||||||
'''
|
'''
|
||||||
return self._get_parent_attribute('environment', extend=True)
|
return self._get_parent_attribute('environment', extend=True, prepend=True)
|
||||||
|
|
||||||
def get_dep_chain(self):
|
def get_dep_chain(self):
|
||||||
if self._parent:
|
if self._parent:
|
||||||
|
|
Loading…
Reference in a new issue