Templates V2
Scripts simples pour automatiser la création de templates proxmox.
Voici des scripts simples pour automatiser la création de templates Proxmox. (En utilisant CLOUD-INIT)
Debian 12
#!/bin/bash
VM_ID='8001'
VM_NAME='debian12-template'
VM_IMG='debian-12-genericcloud-amd64.qcow2'
WORKING_DIR="/root"
VM_DATASTORE="local"
VM_MOTD=""
echo -e "\033[0;31m[Téléchargement de l'Image]\033[0m"
if [ -f "$VM_IMG" ]; then
echo "L'image '$VM_IMG' est déjà présente."
else
echo "Téléchargement de l'image '$VM_IMG'."
wget -q --show-progress "https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-genericcloud-amd64.qcow2"
fi
echo -e "\033[0;31m[Modification de l'Image]\033[0m"
sleep 1
virt-customize -a $VM_IMG --update
virt-customize -a $VM_IMG --install qemu-guest-agent,htop
virt-customize -a $VM_IMG --timezone Europe/Paris
virt-customize -a $VM_IMG --run-command "sed -i 's/#PermitRootLogin\s*prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config"
virt-customize -a $VM_IMG --run-command "sed -i 's/PasswordAuthentication\s*no/PasswordAuthentication yes/g' /etc/ssh/sshd_config"
virt-customize -a $VM_IMG --run-command "sed -i 's/disable_root: true/disable_root: false/g' /etc/cloud/cloud.cfg"
virt-customize -a $VM_IMG --run-command "truncate -s 0 /etc/motd && echo '$VM_MOTD' > /etc/motd"
echo -e "\033[0;31m[Création de la Template]\033[0m"
sleep 1
qm create $VM_ID \
--name $VM_NAME \
--description "Template basé sur $VM_IMG" \
--cpu host \
--cores 2 \
--memory 4096 \
--numa 1 \
--ostype 'l26' \
--agent 1,fstrim_cloned_disks=1 \
--scsihw virtio-scsi-pci \
--scsi0 $VM_DATASTORE:0,import-from=$WORKING_DIR/$VM_IMG \
--boot c --bootdisk scsi0 \
--ide2 $VM_DATASTORE:cloudinit \
--serial0 socket \
--vga serial0 \
--net0 model=virtio,bridge=vmbr0
qm template $VM_ID
Ubuntu 22.04
#!/bin/bash
VM_ID='8002'
VM_NAME='ubuntu2204-template'
VM_IMG='jammy-server-cloudimg-amd64.img'
WORKING_DIR="/root"
VM_DATASTORE="local"
echo -e "\033[0;31m[Téléchargement de l'Image]\033[0m"
if [ -f "$VM_IMG" ]; then
echo "L'image '$VM_IMG' est déjà présente."
else
echo "Téléchargement de l'image '$VM_IMG'."
wget -q --show-progress "https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img"
fi
echo -e "\033[0;31m[Modification de l'Image]\033[0m"
sleep 1
virt-customize -a $VM_IMG --update
virt-customize -a $VM_IMG --install qemu-guest-agent,htop
virt-customize -a $VM_IMG --timezone Europe/Paris
virt-customize -a $VM_IMG --run-command "sed -i 's/#PermitRootLogin\s*prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config"
virt-customize -a $VM_IMG --run-command "sed -i 's/#PasswordAuthentication\s*yes/PasswordAuthentication yes/g' /etc/ssh/sshd_config"
virt-customize -a $VM_IMG --run-command "sed -i 's/disable_root: true/disable_root: false/' /etc/cloud/cloud.cfg"
echo -e "\033[0;31m[Création de la Template]\033[0m"
sleep 1
qm create $VM_ID \
--name $VM_NAME \
--description "Template basé sur $VM_IMG" \
--cpu host \
--cores 2 \
--memory 4096 \
--numa 1 \
--ostype 'l26' \
--agent 1,fstrim_cloned_disks=1 \
--scsihw virtio-scsi-pci \
--scsi0 $VM_DATASTORE:0,import-from=$WORKING_DIR/$VM_IMG \
--boot c --bootdisk scsi0 \
--ide2 $VM_DATASTORE:cloudinit \
--serial0 socket \
--vga serial0 \
--net0 model=virtio,bridge=vmbr0
qm template $VM_ID
Ubuntu 24.04
#!/bin/bash
VM_ID='8003'
VM_NAME='ubuntu2404-template'
VM_IMG='noble-server-cloudimg-amd64.img'
WORKING_DIR="/root"
VM_DATASTORE="local"
echo -e "\033[0;31m[Téléchargement de l'Image]\033[0m"
if [ -f "$VM_IMG" ]; then
echo "L'image '$VM_IMG' est déjà présente."
else
echo "Téléchargement de l'image '$VM_IMG'."
wget -q --show-progress "https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img"
fi
echo -e "\033[0;31m[Modification de l'Image]\033[0m"
sleep 1
virt-customize -a $VM_IMG --update
virt-customize -a $VM_IMG --install qemu-guest-agent,htop
virt-customize -a $VM_IMG --timezone Europe/Paris
virt-customize -a $VM_IMG --run-command "sed -i 's/disable_root: true/disable_root: false/' /etc/cloud/cloud.cfg"
echo -e "\033[0;31m[Création de la Template]\033[0m"
sleep 1
qm create $VM_ID \
--name $VM_NAME \
--description "Template basé sur $VM_IMG" \
--cpu host \
--cores 2 \
--memory 4096 \
--numa 1 \
--ostype 'l26' \
--agent 1,fstrim_cloned_disks=1 \
--scsihw virtio-scsi-pci \
--scsi0 $VM_DATASTORE:0,import-from=$WORKING_DIR/$VM_IMG \
--boot c --bootdisk scsi0 \
--ide2 $VM_DATASTORE:cloudinit \
--serial0 socket \
--vga serial0 \
--net0 model=virtio,bridge=vmbr0
qm template $VM_ID
Last update : nov2024
Dernière mise à jour
Cet article vous a-t-il été utile ?