diff --git a/group_vars/all.yml b/group_vars/all.yml index bd99af2..101db44 100644 --- a/group_vars/all.yml +++ b/group_vars/all.yml @@ -54,7 +54,7 @@ instance_debootstrap: - name: default arch: amd64 suite: bookworm - extra_pkgs: "acpi-support-base,udev,linux-image-amd64,sudo,vim,grub-pc,openssh-server" + extra_pkgs: "linux-image-amd64" rapi: - name: admin diff --git a/roles/node/files/ganeti/instance-debootstrap/hooks/clear-root-password b/roles/node/files/ganeti/instance-debootstrap/hooks/clear-root-password new file mode 100755 index 0000000..417b62d --- /dev/null +++ b/roles/node/files/ganeti/instance-debootstrap/hooks/clear-root-password @@ -0,0 +1,21 @@ +#!/bin/sh + +set -e + +# Make sure we're not working on the root directory +if [ -z "$TARGET" -o "$TARGET" = "/" ]; then + echo "Invalid target directory '$TARGET', aborting." 1>&2 + exit 1 +fi + +if [ "$(mountpoint -d /)" = "$(mountpoint -d "$TARGET")" ]; then + echo "The target directory seems to be the root dir, aborting." 1>&2 + exit 1 +fi + +# Disable root's password, as the switch to enable shadow by default +# has left root with a disabled password, preventing the initial login +echo "Disabling root's password" +chroot "$TARGET" passwd -d root + +exit 0 diff --git a/roles/node/files/ganeti/instance-debootstrap/hooks/grub-pc b/roles/node/files/ganeti/instance-debootstrap/hooks/grub-pc new file mode 100755 index 0000000..d261b21 --- /dev/null +++ b/roles/node/files/ganeti/instance-debootstrap/hooks/grub-pc @@ -0,0 +1,57 @@ +#!/bin/bash +# +# This is an example script that install and configure grub after installation. +# To use it put it in your CUSTOMIZE_DIR and make it executable. +# +# Do not include grub in EXTRA_PKGS of +# $sysconfdir/default/ganeti-instance-debootstrap because it will +# cause error of debootstrap. + +set -e + +. common.sh + +CLEANUP=( ) + +trap cleanup EXIT + +if [ -z "$TARGET" -o ! -d "$TARGET" ]; then + echo "Missing target directory" + exit 1 +fi + +# install grub +export LANG=C +if [ "$PROXY" ]; then + export http_proxy="$PROXY" + export https_proxy="$PROXY" +fi + +umount_sys_fuse() +{ + umount $TARGET/sys/fs/fuse/connections 2>/dev/null || true +} + +mount --bind /dev $TARGET/dev +CLEANUP+=("umount $TARGET/dev") +mount --bind /proc $TARGET/proc +CLEANUP+=("umount $TARGET/proc") +mount --bind /sys $TARGET/sys +CLEANUP+=("umount $TARGET/sys") +CLEANUP+=("umount_sys_fuse") + +DEBIAN_FRONTEND=noninteractive chroot "$TARGET" apt-get -y install grub-pc grub-common + +echo "(hd0) $BLOCKDEV" > $TARGET/boot/grub/device.map +CLEANUP+=("rm $TARGET/boot/grub/device.map") + +chroot "$TARGET" sed -Ei 's/^(GRUB_CMDLINE_LINUX=\".*)\"$/\1 net.ifnames=0"/' /etc/default/grub +chroot "$TARGET" grub-install "(hd0)" +GRUB_DISABLE_OS_PROBER=true chroot "$TARGET" update-grub +echo 'grub-pc grub-pc/install_devices multiselect /dev/xvda' | chroot "$TARGET" debconf-set-selections + +# execute cleanups +cleanup +trap - EXIT + +exit 0 diff --git a/roles/node/tasks/debootstrap.yml b/roles/node/tasks/debootstrap.yml index 2fdf820..e02f13b 100644 --- a/roles/node/tasks/debootstrap.yml +++ b/roles/node/tasks/debootstrap.yml @@ -10,3 +10,16 @@ src: etc-ganeti-instance-debootstrap-variants.list.j2 dest: "/etc/ganeti/instance-debootstrap/variants.list" mode: "0644" + +- name: Install hooks + ansible.builtin.copy: + src: ganeti/ + dest: /etc/ganeti + mode: "0755" + +- name: Fix hook permissions + ansible.builtin.file: + path: "/etc/ganeti/instance-debootstrap/hooks/" + state: directory + mode: "0755" + recurse: true diff --git a/roles/node/tasks/ganeti.yml b/roles/node/tasks/ganeti.yml index 9bb661d..82c6124 100644 --- a/roles/node/tasks/ganeti.yml +++ b/roles/node/tasks/ganeti.yml @@ -20,3 +20,7 @@ ansible.builtin.file: path: /etc/ganeti/vnc-cluster-password mode: "0644" + +- name: Include debootstrap + ansible.builtin.include_tasks: + file: debootstrap.yml \ No newline at end of file diff --git a/roles/node/tasks/main.yml b/roles/node/tasks/main.yml index a60546e..bdfb5a8 100644 --- a/roles/node/tasks/main.yml +++ b/roles/node/tasks/main.yml @@ -30,10 +30,6 @@ ansible.builtin.include_tasks: file: keys.yml -- name: Configure debootstrap - ansible.builtin.include_tasks: - file: debootstrap.yml - - name: Configure Ganeti ansible.builtin.include_tasks: file: ganeti.yml