From 2c3f88259122323eb73eb40f4dec9d66483d926c Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 7 Jan 2022 15:06:29 +0200 Subject: feat: make v-i script support my standard base install Also, put as many packages as possible inside the cached portion, for speed. Sponsored-by: author --- v-i | 64 ++++++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 20 deletions(-) (limited to 'v-i') diff --git a/v-i b/v-i index bf1903e..49721e4 100755 --- a/v-i +++ b/v-i @@ -107,7 +107,7 @@ def clean_up_disks(): run(["cryptsetup", "close", mapping], check=False) -def vmdb_spec(cryptsetup_password, playbook): +def vmdb_spec(cryptsetup_password, playbook, extra_vars): device = "{{ image }}" spec = { "steps": [ @@ -190,15 +190,16 @@ def vmdb_spec(cryptsetup_password, playbook): { "mount": "root", }, - {"mount": "boot", "dirname": "/boot", "mount-on": "root"}, + { + "mount": "boot", + "dirname": "/boot", + "mount-on": "root", + }, { "mount": "efi", "dirname": "/boot/efi", "mount-on": "boot", }, - { - "virtual-filesystems": "root", - }, { "unpack-rootfs": "root", }, @@ -208,36 +209,47 @@ def vmdb_spec(cryptsetup_password, playbook): "target": "root", "unless": "rootfs_unpacked", }, + { + "apt": "install", + "packages": [ + "console-setup", + "dosfstools", + "ifupdown", + "linux-image-amd64", + "locales-all", + "lvm2", + "psmisc", + "python3", + "ssh", + "strace", + ], + "tag": "root", + "unless": "rootfs_unpacked", + }, { "cache-rootfs": "root", "unless": "rootfs_unpacked", }, { - "fstab": "root", + # This MUST be after the debootstrap step. + "virtual-filesystems": "root", }, { - "apt": "install", - "packages": ["linux-image-amd64"], - "tag": "root", + "fstab": "root", }, { + # These MUST come after the fstab step so that they add the + # crypttab in the initramfs. "apt": "install", "packages": [ - "console-setup", "cryptsetup", "cryptsetup-initramfs", - "dosfstools", - "ifupdown", - "locales-all", - "lvm2", - "psmisc", - "python3", - "ssh", - "strace", ], "tag": "root", }, { + # This also MUST come outside the rootfs caching, as it install + # things outside the file systems. "grub": "uefi", "tag": "root", "efi": "efi", @@ -249,7 +261,9 @@ def vmdb_spec(cryptsetup_password, playbook): # If a playbook has been specified, add an ansible step. if playbook: - spec["steps"].append({"ansible": "root", "playbook": playbook}) + spec["steps"].append( + {"ansible": "root", "playbook": playbook, "extra_vars": extra_vars} + ) return spec @@ -260,13 +274,19 @@ def main(): p.add_argument("--log", default="install.log") p.add_argument("--cache", default="cache.tar.gz") p.add_argument("--playbook") + p.add_argument("--vars") p.add_argument("--luks") p.add_argument("device") args = p.parse_args() + extra_vars = {} + if args.vars: + with open(args.vars) as f: + extra_vars = yaml.safe_load(f) + clean_up_disks() - spec = vmdb_spec(args.luks, args.playbook) + spec = vmdb_spec(args.luks, args.playbook, extra_vars) tmp = tempfile.mkdtemp() specfile = os.path.join(tmp, "spec.yaml") if args.verbose: @@ -275,6 +295,10 @@ def main(): yaml.dump(spec, stream=f, indent=4) log(f"run vmdb2 to install on {args.device}") + env = dict(os.environ) + env["ANSIBLE_STDOUT_CALLBACK"] = "yaml" + env["ANSIBLE_NOCOWS"] = "1" + env["ANSIBLE_LOG_PATH"] = "ansible.log" run( [ "vmdb2", -- cgit v1.2.1