summaryrefslogtreecommitdiff
path: root/cloudinit/config
diff options
context:
space:
mode:
authorSergio Lystopad <slystopad@mirantis.com>2017-02-20 16:45:33 +0200
committerScott Moser <smoser@brickies.net>2017-03-09 15:14:12 -0500
commit7f2b51054a5defec4c04fc40026bda7dd29f69fe (patch)
treeb2290f6ae389ce36f048178d8a57350fac5e125c /cloudinit/config
parent5a0bee770fe80573e8efad9ca97233079adebd78 (diff)
downloadvyos-cloud-init-7f2b51054a5defec4c04fc40026bda7dd29f69fe.tar.gz
vyos-cloud-init-7f2b51054a5defec4c04fc40026bda7dd29f69fe.zip
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
Diffstat (limited to 'cloudinit/config')
-rwxr-xr-xcloudinit/config/cc_set_passwords.py22
1 files 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()