two-images/packer/scripts/check.sh
GnomeZworc 344363d49c
All checks were successful
Tests / check (push) Successful in 38s
two-images: rocky10, profils NM de cloud-init nommés par interface #1
cloud-init 24.4 nomme le profil NetworkManager d'après la clé du
network-config (eth0) et le cherche d'après l'interface (ens3) : la
2e interface n'est jamais activée, et au redémarrage le profil de
repli porte le même UUID, nmcli up échoue (degraded done).

Correctif dans l'image : fichier nommé par interface, contrôlé par
check.sh. test.sh sert un network-config au format de two (2 NIC
décrites, 1 sans entrée) et vérifie cloud-init après redémarrage.

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2026-11-06 00:32:01 +01:00

73 lines
2.6 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
FAILED=0
check () {
local desc="${1}"
shift
if "$@"; then
echo "RÉUSSI: ${desc}"
else
echo "ÉCHOUÉ: ${desc}"
FAILED=1
fi
}
empty_or_absent () {
[ ! -e "${1}" ] || [ -z "$(find "${1}" -mindepth 1 -print -quit)" ]
}
no_match () {
local dir="${1}"
shift
[ ! -d "${dir}" ] || [ -z "$(find "${dir}" "$@" -print -quit)" ]
}
has_line () {
grep -qxF -- "${2}" "${1}"
}
no_build_user () {
! grep -q '^build:' /mnt/etc/passwd
}
machine_id_blank () {
[ ! -s /mnt/etc/machine-id ]
}
no_fixed_ntp () {
! grep -qE '^[[:space:]]*(pool|server|peer)[[:space:]]' /mnt/etc/chrony.conf
}
nm_files_by_device () {
local dir
dir=$(chroot /mnt python3 -c 'import cloudinit, os; print(os.path.dirname(cloudinit.__file__))') || return 1
has_line "/mnt${dir}/net/network_manager.py" ' name = nm_conn_filename(iface["name"], target)'
}
check "/var/lib/cloud vide" empty_or_absent /mnt/var/lib/cloud
check "aucune clé d'hôte SSH" no_match /mnt/etc/ssh -maxdepth 1 -name 'ssh_host_*'
check "aucun authorized_keys sous /root" no_match /mnt/root -name authorized_keys
check "aucun authorized_keys sous /home" no_match /mnt/home -name authorized_keys
check "machine-id vide" machine_id_blank
check "utilisateur de construction absent" no_build_user
check "aucun journal" no_match /mnt/var/log ! -type d
check "source NoCloud vers 169.254.169.254" has_line /mnt/etc/cloud/cloud.cfg.d/99_metadata.cfg " seedfrom: 'http://169.254.169.254:80/'"
check "network-config réappliqué à chaque démarrage" has_line /mnt/etc/cloud/cloud.cfg.d/98_network_updates.cfg " when: [boot-new-instance, boot, boot-legacy]"
check "règle udev xvd" test -s /mnt/etc/udev/rules.d/90-two-xvd.rules
case "${FAMILY}" in
debian)
check "DHCP sur toutes les interfaces (networkd)" has_line /mnt/etc/systemd/network/90-all-en.network "Name=en*"
;;
rocky)
check "DHCP sur toutes les interfaces (NetworkManager)" has_line /mnt/etc/NetworkManager/system-connections/90-all-en.nmconnection "interface-name=en*"
check "SELinux désactivé" has_line /mnt/etc/selinux/config "SELINUX=disabled"
check "utilisateur par défaut syonad" has_line /mnt/etc/cloud/cloud.cfg.d/20_user.cfg " name: syonad"
check "chrony sans serveur NTP fixe" no_fixed_ntp
check "chrony sur les serveurs NTP du DHCP" has_line /mnt/etc/chrony.conf "sourcedir /run/chrony-dhcp"
check "profils NetworkManager de cloud-init nommés par interface" nm_files_by_device
;;
esac
[ "${FAILED}" -eq 0 ] || { echo "!! image refusée" >&2; exit 1; }