diff options
author | Lars Wirzenius <liw@liw.fi> | 2022-11-05 12:02:13 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2022-11-05 12:02:35 +0200 |
commit | e3942be72b103f3ca99e836e5bc15abfbb504178 (patch) | |
tree | d4004816acab03e592f9a97e2227ab5b2ba7e097 | |
parent | 0915a60346d3bb9d75d9f95958279c0f46337431 (diff) | |
download | vmadm-e3942be72b103f3ca99e836e5bc15abfbb504178.tar.gz |
refactor: write a host_id.conf file with keys, certs listed
Sponsored-by: author
-rw-r--r-- | cloud-init.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/cloud-init.py b/cloud-init.py index 3618ad8..abbbcb8 100644 --- a/cloud-init.py +++ b/cloud-init.py @@ -1,11 +1,13 @@ import os import yaml +HOST_ID_CONF = "host_id.conf" USER_CA_KEYS = "user-ca-keys" ETC = "/etc/ssh" CONFIG = "ssh_config" +CONFIG_D = "ssh_config" LGGFILE = "/tmp/vmadm.script" USER_DATA = "/var/lib/cloud/instance/user-data.txt" @@ -84,13 +86,23 @@ log(f"configuring sshd {config}") log(f"keys {keys}") log(f"certs {certs}") -with open(config, "w") as f: +config_d = etc_join(CONFIG_D) +if not os.path.exists(config_d): + log(f"mkdir {config_d}") + os.mkdir(config_d) + +host_id_conf = etc.join(CONFIG_D, HOST_ID_CONF) +log(f"write {host_id_conf}") +with open(host_id_conf, "w") as f: for filename in keys: log(f"hostkey {filename}") f.write(f"hostkey {filename}\n") for filename in certs: log(f"hostcert {filename}") f.write(f"hostcertificate {filename}\n") + + +with open(config, "w") as f: if user_ca_pubkey: log(f"trustedusercakeys {user_ca_filename}") f.write(f"trustedusercakeys {user_ca_filename}\n") |