mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-09 01:44:03 -07:00
parent
ebfd99e307
commit
e7d0c9f820
5 changed files with 33 additions and 35 deletions
|
@ -36,9 +36,8 @@ from ansible.parsing import DataLoader
|
|||
from ansible.playbook.attribute import Attribute, FieldAttribute
|
||||
from ansible.template import Templar
|
||||
from ansible.utils.boolean import boolean
|
||||
|
||||
from ansible.utils.debug import debug
|
||||
|
||||
from ansible.utils.vars import combine_vars
|
||||
from ansible.template import template
|
||||
|
||||
class Base:
|
||||
|
@ -48,6 +47,9 @@ class Base:
|
|||
_port = FieldAttribute(isa='int')
|
||||
_remote_user = FieldAttribute(isa='string')
|
||||
|
||||
# variables
|
||||
_vars = FieldAttribute(isa='dict', default=dict())
|
||||
|
||||
# flags and misc. settings
|
||||
_environment = FieldAttribute(isa='list', default=[])
|
||||
_no_log = FieldAttribute(isa='bool', default=False)
|
||||
|
@ -351,6 +353,30 @@ class Base:
|
|||
# restore the UUID field
|
||||
setattr(self, '_uuid', data.get('uuid'))
|
||||
|
||||
def _load_vars(self, attr, ds):
|
||||
'''
|
||||
Vars in a play can be specified either as a dictionary directly, or
|
||||
as a list of dictionaries. If the later, this method will turn the
|
||||
list into a single dictionary.
|
||||
'''
|
||||
|
||||
try:
|
||||
if isinstance(ds, dict):
|
||||
return ds
|
||||
elif isinstance(ds, list):
|
||||
all_vars = dict()
|
||||
for item in ds:
|
||||
if not isinstance(item, dict):
|
||||
raise ValueError
|
||||
all_vars = combine_vars(all_vars, item)
|
||||
return all_vars
|
||||
elif ds is None:
|
||||
return {}
|
||||
else:
|
||||
raise ValueError
|
||||
except ValueError:
|
||||
raise AnsibleParserError("Vars in a %s must be specified as a dictionary, or a list of dictionaries" % self.__class__.__name__, obj=ds)
|
||||
|
||||
def _extend_value(self, value, new_value):
|
||||
'''
|
||||
Will extend the value given with new_value (and will turn both
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue