From 7f2b51054a5defec4c04fc40026bda7dd29f69fe Mon Sep 17 00:00:00 2001 From: Sergio Lystopad Date: Mon, 20 Feb 2017 16:45:33 +0200 Subject: Support chpasswd/list being a list in addition to a string. cc_set_passwords previously supported 'list' as a multiline string: chpasswd: list: | user:pass1 user015:R This patch adds support for user/pairs as a list: chpasswd: list: - user:pass1 - user015:R LP: #1665694 --- cloudinit/config/cc_set_passwords.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/cloudinit/config/cc_set_passwords.py b/cloudinit/config/cc_set_passwords.py index af6704c6..fa343a7a 100755 --- a/cloudinit/config/cc_set_passwords.py +++ b/cloudinit/config/cc_set_passwords.py @@ -50,6 +50,16 @@ enabled, disabled, or left to system defaults using ``ssh_pwauth``. user2:Random user3:password3 user4:R + + ## + # or as yaml list + ## + chpasswd: + list: + - user1:password1 + - user2:Random + - user3:password3 + - user4:R """ import sys @@ -79,7 +89,15 @@ def handle(_name, cfg, cloud, log, args): if 'chpasswd' in cfg: chfg = cfg['chpasswd'] - plist = util.get_cfg_option_str(chfg, 'list', plist) + if isinstance(chfg['list'], list): + log.debug("Handling input for chpasswd as list.") + plist = util.get_cfg_option_list(chfg, 'list', plist) + else: + log.debug("Handling input for chpasswd as multiline string.") + plist = util.get_cfg_option_str(chfg, 'list', plist) + if plist: + plist = plist.spitlines() + expire = util.get_cfg_option_bool(chfg, 'expire', expire) if not plist and password: @@ -95,7 +113,7 @@ def handle(_name, cfg, cloud, log, args): plist_in = [] randlist = [] users = [] - for line in plist.splitlines(): + for line in plist: u, p = line.split(':', 1) if p == "R" or p == "RANDOM": p = rand_user_password() -- cgit v1.2.3