fastrabbit/packer/linux/debian-12-x64/debian-12-x64.pkr.hcl

96 lines
2.6 KiB
HCL

packer {
required_version = ">= 1.11.0"
required_plugins {
vsphere = {
source = "github.com/hashicorp/vsphere"
version = ">= 1.4.0"
}
ansible = {
source = "github.com/hashicorp/ansible"
version = ">= 1.1.1"
}
git = {
source = "github.com/ethanmdavidson/git"
version = ">= 0.6.2"
}
}
}
// Defines the local variables.
//locals {
// var1 = "var1"
//}
source "vsphere-iso" "debian-12-x64" {
vcenter_server = var.vcenter_server
username = var.vcenter_username
password = var.vcenter_password
insecure_connection = true
datacenter = var.vcenter_datacenter
cluster = var.vcenter_cluster
host = var.vcenter_host
datastore = var.vcenter_datastore
folder = var.vcenter_folder
convert_to_template = true
// ****************
vm_name = var.vm_name
CPUs = var.vm_num_cpu
RAM = var.vm_ram
vm_version = var.vm_hardware_version
guest_os_type = var.vm_guest_os_type
disk_controller_type = ["pvscsi"]
storage {
disk_size = var.vm_disk_size
disk_thin_provisioned = true
}
network_adapters {
network = var.vm_network
network_card = var.vm_network_nic_type
}
remove_cdrom = true
// ****************
ssh_username = var.connection_username
//ssh_password = var.connection_password
ssh_private_key_file = var.connection_ssh_private_key_file
ssh_port = "22"
ip_wait_timeout = "25m"
ssh_timeout = "10m"
ssh_handshake_attempts = "20"
shutdown_timeout = "10m"
// ****************
iso_checksum = var.iso_checksum
// iso_url = var.os_iso_url
iso_paths = [var.os_iso_paths]
// ****************
boot_wait = "8s"
boot_command = [var.boot_command]
}
build {
name = "template"
sources = ["source.vsphere-iso.debian-12-x64"]
provisioner "file" {
destination = "/tmp/prep-script.sh"
source = "${path.root}data/prep-script.sh"
}
provisioner "shell" {
inline = [
"sudo chmod 755 /tmp/prep-script.sh",
"sudo /tmp/prep-script.sh",
]
}
provisioner "shell-local" {
inline = [
"ansible-playbook ~/ansible/playbooks/os-linux-prep-templ.yml -l packer-templ-debian-12-x64 -e hosts_target=packer-templ-debian-12-x64 -e ansible_host=${build.Host} -e connection_username=${var.connection_username} -e connection_ssh_private_key_file=${var.connection_ssh_private_key_file}"
]
}
}