diff options
-rw-r--r-- | cloudinit/DataSourceConfigDrive.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/cloudinit/DataSourceConfigDrive.py b/cloudinit/DataSourceConfigDrive.py index f44344a2..2db4a76a 100644 --- a/cloudinit/DataSourceConfigDrive.py +++ b/cloudinit/DataSourceConfigDrive.py @@ -162,6 +162,7 @@ def read_config_drive_dir(source_dir): flist = ("etc/network/interfaces", "root/.ssh/authorized_keys", "meta.js") found = [f for f in flist if os.path.isfile("%s/%s" % (source_dir, f))] + keydata = "" if len(found) == 0: raise nonConfigDriveDir("%s: %s" % (source_dir, "no files found")) @@ -172,10 +173,7 @@ def read_config_drive_dir(source_dir): if "root/.ssh/authorized_keys" in found: with open("%s/%s" % (source_dir, "root/.ssh/authorized_keys")) as fp: - content = fp.read() - lines = content.splitlines() - keys = [l for l in lines if len(l) and not l.startswith("#")] - md['public-keys'] = keys + keydata = fp.read() meta_js = {} @@ -190,7 +188,14 @@ def read_config_drive_dir(source_dir): raise nonConfigDriveDir("%s: %s" % (source_dir, "invalid json in meta.js")) - for copy in ('public-keys', 'dsmode', 'instance-id', 'dscfg'): + keydata = meta_js.get('public-keys', keydata) + + if keydata: + lines = keydata.splitlines() + md['public-keys'] = [l for l in lines + if len(l) and not l.startswith("#")] + + for copy in ('dsmode', 'instance-id', 'dscfg'): if copy in meta_js: md[copy] = meta_js[copy] |