two-images/packer/scripts/rocky.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

86 lines
2.8 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
die () { echo "!! ${1}" >&2; exit 1; }
unit_exists () {
[ -e "/mnt/usr/lib/systemd/system/${1}" ] || [ -e "/mnt/etc/systemd/system/${1}" ]
}
echo "The default user for Syonad VMs is 'syonad'." > /mnt/etc/banner
augtool -r /mnt -s <<'EOF'
set /files/etc/ssh/sshd_config/X11Forwarding no
set /files/etc/ssh/sshd_config/PermitTunnel no
set /files/etc/ssh/sshd_config/PermitRootLogin no
set /files/etc/ssh/sshd_config/RSAAuthentication yes
set /files/etc/ssh/sshd_config/PubkeyAuthentication yes
set /files/etc/ssh/sshd_config/PasswordAuthentication no
set /files/etc/ssh/sshd_config/UseDNS no
set /files/etc/ssh/sshd_config/ChallengeResponseAuthentication no
set /files/etc/ssh/sshd_config/GSSAPIAuthentication no
set /files/etc/ssh/sshd_config/Match[1]/Condition/User "root,centos,ubuntu,debian,ec2-user"
set /files/etc/ssh/sshd_config/Match[1]/Settings/Banner "/etc/banner"
EOF
cat > /mnt/etc/cloud/cloud.cfg.d/20_user.cfg <<'EOF'
system_info:
default_user:
name: syonad
EOF
install -m 0600 /dev/stdin /mnt/etc/NetworkManager/system-connections/90-all-en.nmconnection <<'EOF'
[connection]
id=two-all-en
type=ethernet
autoconnect-priority=-100
multi-connect=3
[match]
interface-name=en*
[ipv4]
method=auto
[ipv6]
method=ignore
EOF
chroot /mnt systemctl enable fstrim.timer
for unit in rpcbind.service rpcbind.socket; do
if unit_exists "${unit}"; then
chroot /mnt systemctl disable "${unit}"
fi
done
CLOUDINIT=$(chroot /mnt python3 -c 'import cloudinit, os; print(os.path.dirname(cloudinit.__file__))')
[ -n "${CLOUDINIT}" ] || die "module cloudinit introuvable dans la cible"
patch -d "/mnt${CLOUDINIT}" -p1 --forward --fuzz=0 --no-backup-if-mismatch <<'EOF'
--- a/net/network_manager.py
+++ b/net/network_manager.py
@@ -594,10 +594,11 @@
conn.render_interface(iface, network_state, self)
# And finally write the files
- for con_id, conn in self.connections.items():
+ for iface in network_state.iter_interfaces():
+ conn = self.connections[iface.get("config_id") or iface["name"]]
if not conn.valid():
continue
- name = nm_conn_filename(con_id, target)
+ name = nm_conn_filename(iface["name"], target)
util.write_file(name, conn.dump(), 0o600)
# Select EUI64 to be used by default by NM for creating the address
EOF
chroot /mnt python3 -m py_compile "${CLOUDINIT}/net/network_manager.py"
augtool -r /mnt -s set /files/etc/selinux/config/SELINUX disabled
augtool -r /mnt -s rm /files/etc/chrony.conf/pool
mapfile -t cockpit < <(chroot /mnt rpm -qa 'cockpit*')
if [ "${#cockpit[@]}" -gt 0 ]; then
chroot /mnt dnf -y -q --disablerepo='*' remove "${cockpit[@]}"
fi
[ -z "$(chroot /mnt rpm -qa 'cockpit*')" ] || die "cockpit toujours installé"
rm -rf /mnt/run/cockpit