diff options
author | Lars Wirzenius <liw@liw.fi> | 2022-09-17 13:04:26 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2022-09-17 13:04:26 +0000 |
commit | 5f046dc34a667ff0d1ec10e809c229c234d43056 (patch) | |
tree | 9a9905b0d2bfebc1ecbef9db4af0790479b19836 | |
parent | 4602d23c327841ef2f2e0e123dc7185d0ed92c05 (diff) | |
parent | 2e994ab9d9349e73f680b7499c991bd95e12f286 (diff) | |
download | v-i-5f046dc34a667ff0d1ec10e809c229c234d43056.tar.gz |
Merge branch 'ansible_vars_file' into 'main'
feat: allow additional files with Ansible vars
See merge request larswirzenius/v-i!40
-rwxr-xr-x | create-host-id | 33 | ||||
-rwxr-xr-x | v-i | 12 |
2 files changed, 43 insertions, 2 deletions
diff --git a/create-host-id b/create-host-id new file mode 100755 index 0000000..2c5748b --- /dev/null +++ b/create-host-id @@ -0,0 +1,33 @@ +#!/usr/bin/python3 + +import argparse +import yaml +import subprocess +import sys + + +def public_key(hostname): + p = subprocess.run( + ["sshca", "host", "public-key", hostname], check=True, capture_output=True + ) + return p.stdout.decode().strip() + + +def cert(ca, hostname): + p = subprocess.run( + ["sshca", "host", "certify", ca, hostname], check=True, capture_output=True + ) + return p.stdout.decode().strip() + + +p = argparse.ArgumentParser() +p.add_argument("--host", required=True) +p.add_argument("--ca", required=True) +args = p.parse_args() + +host_id = { + "host_key": public_key(args.host), + "host_cert": cert(args.ca, args.host), +} + +yaml.dump(host_id, sys.stdout) @@ -385,6 +385,7 @@ class SystemSpec: "extra_lvs": [], "extra_playbooks": [], "ansible_vars": {}, + "ansible_vars_files": [], "luks": "", } with open(filename) as f: @@ -442,10 +443,17 @@ def main(): system = SystemSpec(args.spec) log(f"spec: {system!r}") - clean_up_disks([system.drive] + system.extra_drives) - ansible_vars = dict(system.ansible_vars) ansible_vars["hostname"] = system.hostname + for filename in system.ansible_vars_files: + log(f"reading Ansible vars from {filename}") + with open(filename) as f: + vars_dict = yaml.safe_load(f) + ansible_vars.update(vars_dict) + log(f"ansible_vars: {ansible_vars!r}") + + clean_up_disks([system.drive] + system.extra_drives) + vmdb = vmdb_spec(system, ansible_vars) tmp = tempfile.mkdtemp() specfile = os.path.join(tmp, "spec.yaml") |