Add option to prepend inherited attributes when extending values

Fixes #18483
This commit is contained in:
James Cammarata 2016-11-14 16:29:13 -06:00
commit 435ca620b2
4 changed files with 16 additions and 11 deletions

View file

@ -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):
'''