Installer Proxmox VE de manière silencieuse avec Ventoy et Ansible

Sommaire

L'objectif est d'utiliser notre clef USB multiboot Ventoy, afin d'installer un noeud Proxmox VE de manière silencieuse, avec le Secure Boot d'activé.

Le seul moyen documenté par Proxmox pour installer un noeud PVE de manière silencieuse est de s'appuyer sur l'installation de Proxmox sur Debian.

Pour la post-installation nous allons utiliser un role Ansible.

1. Prérequis

2. Déposer l'image ISO Debian 12 sur la clef USB Ventoy

Monter la première partition de votre clef USB Ventoy (remplacer /dev/sdX par le chemin de votre clef USB) :

1sudo mount /dev/sdX1 /mnt

Se diriger dans le répertoire du point de montage :

1cd `mount -l -t exfat |awk '{print $3}'`

On télécharger l'image ISO de Debian 12 dans le répertoire "ISO" :

1cd ISO
2wget https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-12.5.0-amd64-netinst.iso

Important: Veiller à vérifier la somme de contrôle de l'image téléchargée.

3. Configurer Ventoy pour l'auto installation

Se diriger dans le répertoire de configuration de Ventoy et de ses plugins :

1cd `mount -l -t exfat |awk '{print $3}'`
2cd ventoy

Editer le fichier "ventoy.json" afin de définir les paramètres globaux de contrôle de Ventoy. Les paramètres sont documentés ici : ventoy_plugin_control.

Dans notre exemple, nous allons configurer le menu et le clavier en Français, et le démarrage automatique de l'installation de Debian pour Proxmox VE :

 1{
 2    "control": [
 3        { "VTOY_MENU_LANGUAGE": "fr_FR" },
 4        { "VTOY_DEFAULT_SEARCH_ROOT": "/ISO" },
 5        { "VTOY_MENU_TIMEOUT": "1" },
 6        { "VTOY_DEFAULT_IMAGE": "/ISO/debian-12.5.0-amd64-netinst.iso" },
 7        { "VTOY_DEFAULT_KBD_LAYOUT": "FRENCH" },
 8        { "VTOY_SECONDARY_TIMEOUT": "1" }
 9    ],
10    "auto_install":[
11        {
12            "image": "/ISO/debian-12.5.0-amd64-netinst.iso",
13            "template":"/ventoy/scripts/proxmox.seed",
14            "autosel": 1
15        }
16    ]
17}

4. Déposer le fichier de réponse Debian sur la clef USB

Se diriger dans le répertoire de configuration de Ventoy et de ses plugins :

1cd `mount -l -t exfat |awk '{print $3}'`
2cd ventoy

Créer le répertoire "scripts:"

1mkdir "scripts"
2cd scripts

Créer le fichier "proxmox.seed" (à adapter en fonction de vos besoins) :

  1### Auto install
  2d-i auto-installer/enable boolean true
  3d-i debconf/priority select critical
  4
  5### Localization
  6d-i debian-installer/language string fr
  7d-i debian-installer/country string FR
  8d-i debian-installer/locale string fr_FR.UTF-8
  9d-i debian-installer/fallbacklocale select fr_FR.UTF-8
 10d-i debian-installer/locale select fr_FR.UTF-8
 11d-i base-installer/kernel/override-image string linux-server
 12d-i debian-installer/keymap string fr-latin9
 13d-i console-keymaps-at/keymap select fr-latin9
 14d-i keyboard-configuration/xkb-keymap select fr
 15d-i console-setup/ask_detect boolean false
 16d-i console-setup/modelcode pc105
 17d-i console-setup/layoutcode string fr
 18d-i console-setup/variant select 
 19
 20### Network configuration
 21d-i netcfg/choose_interface select auto
 22d-i netcfg/get_domain string unassigned-domain
 23
 24### Mirror settings
 25d-i mirror/country string manual
 26d-i mirror/http/hostname string ftp.fr.debian.org
 27d-i mirror/http/directory string /debian
 28d-i mirror/http/proxy string
 29
 30# Always Retry
 31d-i retriever/net/error select Retry
 32
 33### Account setup
 34d-i passwd/root-login boolean true
 35d-i passwd/make-user boolean false
 36d-i passwd/root-password-crypted password CHANGEME
 37
 38### Clock and time zone setup
 39d-i clock-setup/utc boolean true
 40d-i time/zone string Europe/Paris
 41
 42### Partitioning
 43d-i partman-auto-lvm/guided_size string max
 44d-i partman-auto/choose_recipe select atomic
 45d-i partman-auto/method string lvm
 46d-i partman-lvm/confirm boolean true
 47d-i partman-lvm/confirm_nooverwrite boolean true
 48d-i partman-lvm/device_remove_lvm boolean true
 49d-i partman/choose_partition select finish
 50d-i partman/confirm boolean true
 51d-i partman/confirm_nooverwrite boolean true
 52d-i partman/confirm_write_new_label boolean true
 53d-i partman-efi/non_efi_system boolean true
 54d-i partman-partitioning/choose_label string gpt
 55d-i partman-partitioning/default_label string gpt
 56
 57### Package selection
 58tasksel tasksel/first multiselect standard, ssh-server
 59d-i pkgsel/include string ansible
 60d-i pkgsel/update-policy select unattended-upgrades
 61d-i pkgsel/upgrade select full-upgrade
 62d-i pkgsel/install-language-support boolean false
 63popularity-contest popularity-contest/participate boolean false
 64
 65### Boot loader installation
 66d-i grub-installer/only_debian boolean true
 67d-i grub-installer/with_other_os boolean false
 68
 69### Finishing up the installation
 70d-i finish-install/reboot_in_progress note
 71apt-cdrom-setup apt-setup/cdrom/set-first boolean false
 72apt-mirror-setup apt-setup/use_mirror boolean true
 73d-i preseed/late_command string \
 74
 75# Create the post installation script
 76in-target sh -c 'echo "#!/bin/bash" > /root/post_install_script.sh'; \
 77
 78# Identify the Ventoy USB device and assign it to a variable
 79in-target sh -c 'echo "USBDEV=$(blkid -L Ventoy)" >> /root/post_install_script.sh'; \
 80
 81# Create a directory to mount the USB device
 82in-target sh -c 'echo "mkdir -p /mnt/usb" >> /root/post_install_script.sh'; \
 83
 84# Mount the Ventoy USB device
 85in-target sh -c 'echo "mount \$USBDEV /mnt/usb" >> /root/post_install_script.sh'; \
 86
 87# Copy files from the USB to the /mnt/ansible directory
 88in-target sh -c 'echo "cp -R /mnt/usb/ventoy/scripts/ansible/ /mnt/" >> /root/post_install_script.sh'; \
 89
 90# Unmount the USB device
 91in-target sh -c 'echo "umount /mnt/usb" >> /root/post_install_script.sh'; \
 92
 93# Run the Ansible playbook and log its output
 94in-target sh -c 'echo "ansible-playbook /mnt/ansible/proxmox.yaml 2>&1 | tee /dev/tty1 /mnt/ansible/proxmox.log" >> /root/post_install_script.sh'; \
 95
 96# Make the script executable
 97in-target chmod +x /root/post_install_script.sh; \
 98
 99# Create and enable a systemd service to run the script
100# Define a new systemd service
101in-target sh -c 'printf "[Unit]\nDescription=One Time Post Install Script\n\n[Service]\nType=oneshot\nExecStart=/root/post_install_script.sh\nRemainAfterExit=yes\n\n[Install]\nWantedBy=multi-user.target" > /etc/systemd/system/post-install.service'; \
102
103# Enable the newly created systemd service
104in-target systemctl enable post-install.service

Générez un hash de votre mot de passe pour l'utilisateur "root" et placez le à la place de CHANGEME dans le fichier de réponse (remplacer "PASSWORD" par votre mot de passe) :

A noter que la commande "mkpasswd" se trouve dans le paquetage "whois" sur Debian.

1mkpasswd  -m sha-512 -S saltsalt -s <<< PASSWORD

Ce fichier de réponse "proxmox.seed" réalise les actions suivantes :

  1. Configuration de la langue du système, du clavier et de la console en Français
  2. Configuration réseau via DHCP
  3. Configuration des miroirs Debian
  4. Configuration du mot de passe pour l'utilisateur "root" (à changer)
  5. Configuration du fuseau horaire sur Paris
  6. Partitionnement automatique pour un disque (ou sélection manuelle si plusieurs disques)
  7. Installation des paquetages recommandés par Proxmox pour une Debian
  8. Installation du paquetage Ansible
  9. Préparation de la post-installation via Ansible en créant un service Systemd dédié

4. Configurer le rôle Ansible et ses variables sur la clef USB Ventoy

Pendant l'installation, un rôle Ansible sera utilisé : https://gitlab.com/kartzone/ansible-role-proxmox.

Pour ce rôle, j'ai suivi la documentation de création d'un rôle Ansible de Stéphane ROBERT et adapté le code proposé dans cet article "Installer Proxmox VE avec Ansible"

Récupérer le rôle Ansible https://gitlab.com/kartzone/kartzone-proxmox et le déposer dans le répertoire "ventoy/scripts/ansible" :

1cd `mount -l -t exfat |awk '{print $3}'`
2cd ventoy/scripts/ansible
3git clone https://gitlab.com/kartzone/ansible-role-proxmox kartzone.proxmox

Créer un fichier playbook dans le répertoire "ventoy/scripts/ansible" nommé "proxmox.yml" :

1---
2- name: Install Proxmox
3  hosts: local
4  roles:
5    - role: kartzone.proxmox

Personnaliser la configuration réseau du noeud Proxmox VE via le fichier "ventoy/scripts/ansible/vars/main.yml" :

 1---
 2# defaults file for kartzone.proxmox
 3node_name: pve10
 4domain_name: kartzone.fr
 5proxmox_interfaces : |
 6  source /etc/network/interfaces.d/*
 7
 8  auto lo
 9  iface lo inet loopback
10
11  iface eno1 inet manual
12
13  auto vmbr0
14  iface vmbr0 inet static
15          address 192.168.1.10/24
16          bridge-ports eno1
17          bridge-stp off
18          bridge-fd 0  

5. Vérifier l'arborescence des fichiers sur la clef USB Ventoy

1├── Clef USB Ventoy
2│   ├── ISO
3│   │   └── debian-12.5.0-amd64-netinst.iso
4│   ├── ventoy
5│   │   ├── scripts
6│   │   │   └── proxmox.seed
7│   │   │   └── ansible
8│   │   │   │   └── proxmox.yml
9│   │   │   │   └── kartzone.proxmox

6. Démarrage de l'installation du noeud Proxmox VE

  1. Brancher la clef USB sur votre machine dédiée à l'installation de Proxmox VE et booter sur cette dernière.
  2. Lancer l'installation de Debian en sélectionnant l'interface graphique de votre choix "Graphical Install" ou "Install"
  3. Patienter quelques minutes et attendre le second redémarrage de la machine
  4. Enfin, connectez vous en HTTP sur l'adresse IP configurée dans le fichier "ventoy/scripts/ansible/vars/main.yml" via les identifiants du compte "root" du noeud Proxmox VE renseignés dans le fichier "proxmox.seed"

7. Annexes