mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-28 23:51:23 -07:00
Add option to prepend inherited attributes when extending values
Fixes #18483
This commit is contained in:
parent
11465134fa
commit
435ca620b2
4 changed files with 16 additions and 11 deletions
|
@ -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):
|
||||
'''
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue