mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 13:50:22 -07:00
Fixing up serialize_args utility function
This commit is contained in:
parent
e99db078b4
commit
04da466c7b
2 changed files with 13 additions and 14 deletions
|
@ -545,6 +545,18 @@ def parse_json(raw_data, from_remote=False, from_inventory=False):
|
|||
|
||||
return results
|
||||
|
||||
def serialize_args(args):
|
||||
'''
|
||||
Flattens a dictionary args to a k=v string
|
||||
'''
|
||||
module_args = ""
|
||||
for (k,v) in args.iteritems():
|
||||
if isinstance(v, basestring):
|
||||
module_args = "%s=%s %s" % (k, pipes.quote(v), module_args)
|
||||
elif isinstance(v, bool):
|
||||
module_args = "%s=%s %s" % (k, str(v), module_args)
|
||||
return module_args.strip()
|
||||
|
||||
def merge_module_args(current_args, new_args):
|
||||
'''
|
||||
merges either a dictionary or string of k=v pairs with another string of k=v pairs,
|
||||
|
@ -559,14 +571,7 @@ def merge_module_args(current_args, new_args):
|
|||
elif isinstance(new_args, basestring):
|
||||
new_args_kv = parse_kv(new_args)
|
||||
final_args.update(new_args_kv)
|
||||
# then we re-assemble into a string
|
||||
module_args = ""
|
||||
for (k,v) in final_args.iteritems():
|
||||
if isinstance(v, basestring):
|
||||
module_args = "%s=%s %s" % (k, pipes.quote(v), module_args)
|
||||
elif isinstance(v, bool):
|
||||
module_args = "%s=%s %s" % (k, str(v), module_args)
|
||||
return module_args.strip()
|
||||
return serialize_args(final_args)
|
||||
|
||||
def parse_yaml(data, path_hint=None):
|
||||
''' convert a yaml string to a data structure. Also supports JSON, ssssssh!!!'''
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue