1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fixes #1715 Allow authorized_module accept multi. (#3573)

This will allow the authorized_module to accept options that can be
passed multiple times into ssh options. For instance permitopen.
This commit is contained in:
Allen Sanabria 2016-06-20 17:32:44 -04:00 committed by Matt Clay
parent 88e4e1af18
commit 6d6b8a1823

View file

@ -169,7 +169,7 @@ class keydict(dict):
def __iter__(self): def __iter__(self):
return iter(self.itemlist) return iter(self.itemlist)
def keys(self): def keys(self):
return self.itemlist return list(set(self.itemlist))
def values(self): def values(self):
return [self[key] for key in self] return [self[key] for key in self]
def itervalues(self): def itervalues(self):
@ -254,7 +254,13 @@ def parseoptions(module, options):
for part in parts: for part in parts:
if "=" in part: if "=" in part:
(key, value) = part.split("=", 1) (key, value) = part.split("=", 1)
options_dict[key] = value if options_dict.has_key(key):
if isinstance(options_dict[key], list):
options_dict[key].append(value)
else:
options_dict[key] = [options_dict[key], value]
else:
options_dict[key] = value
elif part != ",": elif part != ",":
options_dict[part] = None options_dict[part] = None
except: except:
@ -348,10 +354,13 @@ def writekeys(module, filename, keys):
option_strings = [] option_strings = []
for option_key in options.keys(): for option_key in options.keys():
if options[option_key]: if options[option_key]:
option_strings.append("%s=%s" % (option_key, options[option_key])) if isinstance(options[option_key], list):
for value in options[option_key]:
option_strings.append("%s=%s" % (option_key, value))
else:
option_strings.append("%s=%s" % (option_key, options[option_key]))
else: else:
option_strings.append("%s" % option_key) option_strings.append("%s" % option_key)
option_str = ",".join(option_strings) option_str = ",".join(option_strings)
option_str += " " option_str += " "
key_line = "%s%s %s %s\n" % (option_str, type, keyhash, comment) key_line = "%s%s %s %s\n" % (option_str, type, keyhash, comment)