From 6d6b8a182375004dfd5c79568c154be0484e8a1d Mon Sep 17 00:00:00 2001 From: Allen Sanabria Date: Mon, 20 Jun 2016 17:32:44 -0400 Subject: [PATCH] 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. --- lib/ansible/modules/system/authorized_key.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/system/authorized_key.py b/lib/ansible/modules/system/authorized_key.py index ab8440a892..f758eeb940 100644 --- a/lib/ansible/modules/system/authorized_key.py +++ b/lib/ansible/modules/system/authorized_key.py @@ -169,7 +169,7 @@ class keydict(dict): def __iter__(self): return iter(self.itemlist) def keys(self): - return self.itemlist + return list(set(self.itemlist)) def values(self): return [self[key] for key in self] def itervalues(self): @@ -254,7 +254,13 @@ def parseoptions(module, options): for part in parts: if "=" in part: (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 != ",": options_dict[part] = None except: @@ -348,10 +354,13 @@ def writekeys(module, filename, keys): option_strings = [] for option_key in options.keys(): 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: option_strings.append("%s" % option_key) - option_str = ",".join(option_strings) option_str += " " key_line = "%s%s %s %s\n" % (option_str, type, keyhash, comment)