diff --git a/lib/ansible/playbook/base.py b/lib/ansible/playbook/base.py index fe4c0fe9e74..6c952128a98 100644 --- a/lib/ansible/playbook/base.py +++ b/lib/ansible/playbook/base.py @@ -482,7 +482,7 @@ class Base(with_metaclass(BaseMeta, object)): except TypeError as e: raise AnsibleParserError("Invalid variable name in vars specified for %s: %s" % (self.__class__.__name__, e), obj=ds) - def _extend_value(self, value, new_value): + def _extend_value(self, value, new_value, prepend=False): ''' Will extend the value given with new_value (and will turn both into lists if they are not so already). The values are run through @@ -494,7 +494,12 @@ class Base(with_metaclass(BaseMeta, object)): if not isinstance(new_value, list): new_value = [ new_value ] - return [i for i,_ in itertools.groupby(value + new_value) if i is not None] + if prepend: + combined = new_value + value + else: + combined = value + new_value + + return [i for i,_ in itertools.groupby(combined) if i is not None] def serialize(self): ''' diff --git a/lib/ansible/playbook/block.py b/lib/ansible/playbook/block.py index 7d6dab32f64..be04963704c 100644 --- a/lib/ansible/playbook/block.py +++ b/lib/ansible/playbook/block.py @@ -273,7 +273,7 @@ class Block(Base, Become, Conditional, Taggable): def _get_attr_environment(self): return self._get_parent_attribute('environment', extend=True) - def _get_parent_attribute(self, attr, extend=False): + def _get_parent_attribute(self, attr, extend=False, prepend=False): ''' Generic logic to get the attribute or parent attribute for a block value. ''' @@ -286,7 +286,7 @@ class Block(Base, Become, Conditional, Taggable): try: parent_value = getattr(self._parent, attr, None) if extend: - value = self._extend_value(value, parent_value) + value = self._extend_value(value, parent_value, prepend) else: value = parent_value except AttributeError: @@ -295,7 +295,7 @@ class Block(Base, Become, Conditional, Taggable): try: parent_value = getattr(self._role, attr, None) if extend: - value = self._extend_value(value, parent_value) + value = self._extend_value(value, parent_value, prepend) else: value = parent_value @@ -305,7 +305,7 @@ class Block(Base, Become, Conditional, Taggable): for dep in dep_chain: dep_value = getattr(dep, attr, None) if extend: - value = self._extend_value(value, dep_value) + value = self._extend_value(value, dep_value, prepend) else: value = dep_value @@ -317,7 +317,7 @@ class Block(Base, Become, Conditional, Taggable): try: parent_value = getattr(self._play, attr, None) if extend: - value = self._extend_value(value, parent_value) + value = self._extend_value(value, parent_value, prepend) else: value = parent_value except AttributeError: diff --git a/lib/ansible/playbook/conditional.py b/lib/ansible/playbook/conditional.py index 0fada8258c9..0efe9f4a76f 100644 --- a/lib/ansible/playbook/conditional.py +++ b/lib/ansible/playbook/conditional.py @@ -59,7 +59,7 @@ class Conditional: if when is None: when = [] if hasattr(self, '_get_parent_attribute'): - when = self._get_parent_attribute('when', extend=True) + when = self._get_parent_attribute('when', extend=True, prepend=True) return when def evaluate_conditional(self, templar, all_vars): @@ -130,5 +130,5 @@ class Conditional: elif "is defined" in original: return False else: - raise AnsibleError("error while evaluating conditional (%s): %s" % (original, e)) + raise AnsibleUndefinedVariable("error while evaluating conditional (%s): %s" % (original, e)) diff --git a/lib/ansible/playbook/task.py b/lib/ansible/playbook/task.py index 275a59f9e88..503c97f322f 100644 --- a/lib/ansible/playbook/task.py +++ b/lib/ansible/playbook/task.py @@ -388,7 +388,7 @@ class Task(Base, Conditional, Taggable, Become): if self._parent: self._parent.set_loader(loader) - def _get_parent_attribute(self, attr, extend=False): + def _get_parent_attribute(self, attr, extend=False, prepend=False): ''' Generic logic to get the attribute or parent attribute for a task value. ''' @@ -399,7 +399,7 @@ class Task(Base, Conditional, Taggable, Become): if self._parent and (value is None or extend): parent_value = getattr(self._parent, attr, None) if extend: - value = self._extend_value(value, parent_value) + value = self._extend_value(value, parent_value, prepend) else: value = parent_value except KeyError: