Aller au contenu principal

Packer - template Alma Linux

1. Création d'un fichier Packer pour Alma Linux 9.5​

  • Créer le fichier packer/almalinux9/alma-linux-9.5.pkr.hcl
packer/almalinux9-qemu.pkr.hcl
# Packer for Alma Linux 0
# docs
# - https://github.com/marcinbojko/proxmox-kvm-packer

# bug : https://github.com/hashicorp/packer-plugin-proxmox/issues/307
# Packer plugins
packer {
required_plugins {
proxmox = {
version = "1.2.1"
source = "github.com/hashicorp/proxmox"
}
ansible = {
version = "1.1.3"
source = "github.com/hashicorp/ansible"
}
}
}

variable "proxmox_api_url" {
type = string
default = "https://pve1:8006/api2/json"
}

variable "proxmox_api_token_id" {
type = string
default = "packer@pve!packer"
}

variable "proxmox_api_token_secret" {
type = string
sensitive = true
}

variable "ssh_username" {
type = string
default = "bootstrap"
}

variable "ssh_password" {
type = string
default = "changeme!"
}

# doc : https://developer.hashicorp.com/packer/integrations/hashicorp/proxmox/latest/components/builder/iso
source "proxmox-iso" "pkr-alma-linux-9" {
# Proxmox Connection Settings
proxmox_url = "${var.proxmox_api_url}"
username = "${var.proxmox_api_token_id}"
token = "${var.proxmox_api_token_secret}"
insecure_skip_tls_verify = false

# Proxmox node
node = "pve2"
pool = "BOOTSTRAP"

# VM Options
vm_name = "pkr-alma-linux-9.5"
onboot = "false"
os = "l26"
vm_id = "10001"
tags = "template"
template_name = "AlmaLinux-9.5"
template_description = "Alma Linux 9.5 by Packer"
qemu_agent = true

# VM Hardware
memory = "2048"
sockets = "1"
cores = "2"
cpu_type = "host"
#cpu_type = "x86-64-v2-AES"
#cpu_type = "x86-64-v3"
bios = "seabios"
scsi_controller = "virtio-scsi-single"

disable_kvm = false

# VM Boot ISO
# https://developer.hashicorp.com/packer/integrations/hashicorp/proxmox/latest/components/builder/iso#isos
boot_iso {
iso_file = "gv0:iso/AlmaLinux-9.5-x86_64-dvd.iso"
iso_checksum = "sha256:3947accd140a2a1833b1ef2c811f8c0d48cd27624cad343992f86cfabd2474c9"
iso_storage_pool = "gv0"
unmount = true
}

# VM Disks
# https://developer.hashicorp.com/packer/integrations/hashicorp/proxmox/latest/components/builder/iso#disks
disks {
type = "virtio"
storage_pool = "gv0"
disk_size = "10G"
format = "raw"
cache_mode = "none"
io_thread = true
discard = true
}

# VM Network Adapters
# https://developer.hashicorp.com/packer/integrations/hashicorp/proxmox/latest/components/builder/iso#network-adapters
network_adapters {
model = "virtio"
bridge = "vmbr0"
firewall = false
}

# Packer Autoinstall Settings
http_directory = "./http"
http_port_min = 8080
http_port_max = 8080

# Boot Settings
boot = "c"
boot_wait = "5s"
# https://developer.hashicorp.com/packer/integrations/hashicorp/proxmox/latest/components/builder/iso#boot-command
boot_command = [
"<tab> inst.text inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/almalinux/9/ks.cfg<enter>",
]

# SSH Settings
communicator = "ssh"
ssh_username = "${var.ssh_username}"
ssh_password = "${var.ssh_password}"
ssh_port = "22"
ssh_timeout = "30m"
ssh_pty = true
ssh_handshake_attempts = 10

}

build {
name = "pkr-alma-linux-9.5"
sources = [
"source.proxmox-iso.pkr-alma-linux-9"
]

}