install debootstrap hooks

This commit is contained in:
BENEDEK László 2025-02-25 16:57:40 +01:00
parent ba9b005829
commit e9ef837381
6 changed files with 96 additions and 5 deletions

View File

@ -54,7 +54,7 @@ instance_debootstrap:
- name: default - name: default
arch: amd64 arch: amd64
suite: bookworm suite: bookworm
extra_pkgs: "acpi-support-base,udev,linux-image-amd64,sudo,vim,grub-pc,openssh-server" extra_pkgs: "linux-image-amd64"
rapi: rapi:
- name: admin - name: admin

View File

@ -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

View File

@ -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

View File

@ -10,3 +10,16 @@
src: etc-ganeti-instance-debootstrap-variants.list.j2 src: etc-ganeti-instance-debootstrap-variants.list.j2
dest: "/etc/ganeti/instance-debootstrap/variants.list" dest: "/etc/ganeti/instance-debootstrap/variants.list"
mode: "0644" 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

View File

@ -20,3 +20,7 @@
ansible.builtin.file: ansible.builtin.file:
path: /etc/ganeti/vnc-cluster-password path: /etc/ganeti/vnc-cluster-password
mode: "0644" mode: "0644"
- name: Include debootstrap
ansible.builtin.include_tasks:
file: debootstrap.yml

View File

@ -30,10 +30,6 @@
ansible.builtin.include_tasks: ansible.builtin.include_tasks:
file: keys.yml file: keys.yml
- name: Configure debootstrap
ansible.builtin.include_tasks:
file: debootstrap.yml
- name: Configure Ganeti - name: Configure Ganeti
ansible.builtin.include_tasks: ansible.builtin.include_tasks:
file: ganeti.yml file: ganeti.yml