Added packer Debian 12 build

This commit is contained in:
Sergei Bobkov 2024-09-19 22:10:53 +03:00
parent 0e83384b9d
commit f3a6462b36
7 changed files with 202 additions and 0 deletions

2
packer/README.md Normal file
View File

@ -0,0 +1,2 @@
# Packer scripts

0
packer/build.sh Executable file
View File

8
packer/linux/README.md Normal file
View File

@ -0,0 +1,8 @@
# Packer builds files and scripts
For secrets and cred vars create $HOME/.secret/.packer/vcsrv-creds.pkrvars.hcl<br/>
`vcenter_server = "vcs8srv01.lab.loc"`<br/>
`vcenter_username = "administrator@vsphere.local"`<br/>
`vcenter_password = "XXXXXXXXX"`<br/>
<br/>

View File

@ -0,0 +1,18 @@
#!/bin/bash
# => For logs:
#export PACKER_LOG_PATH=./build-debian-12-amd64.log
export PACKER_LOG=1
packer="/usr/bin/packer"
creds_vars_file="$HOME/.secret/.packer/vcsrv-creds.pkrvars.hcl"
build_file="$HOME/packer/linux/debian"
$packer init $HOME/packer/linux/debian-12-x64/
$packer build -force \
-var-file="$creds_vars_file" \
-var-file="$HOME/packer/linux/debian-12-x64/conf.pkrvars.hcl" \
/root/packer/linux/debian-12-x64/

View File

@ -0,0 +1,26 @@
vcenter_datacenter = "DC01"
vcenter_cluster = "Cluster01"
vcenter_host = "esxi8-01.lab.loc"
vcenter_folder = "VLAN-0221"
vcenter_datastore = "Cluster01-LUN02"
vm_name = "zzzzzzz"
vm_num_cpu = 1
vm_ram = 1024
vm_hardware_version = "21"
vm_guest_os_type = "debian12_64Guest"
vm_disk_size = "4096"
vm_network = "VLAN-0221"
vm_network_nic_type = "vmxnet3"
iso_checksum = "none"
os_iso_paths = "[Cluster01-LUN01] ISO/debian-12.7.0-amd64-netinst.iso"
os_iso_url = "https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-12.7.0-amd64-netinst.iso"
connection_username = "user"
connection_password = "user"

View File

@ -0,0 +1,84 @@
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"
}
}
}
// BLOCK: locals
// Defines the local variables.
//locals {
// bbbbb = "aaaa"
//}
source "vsphere-iso" "debian-12" {
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
}
// ****************
ip_wait_timeout = "45m"
ssh_username = var.connection_username
ssh_password = var.connection_password
ssh_timeout = "12h"
ssh_port = "22"
ssh_handshake_attempts = "20"
shutdown_timeout = "15m"
// ****************
iso_checksum = var.iso_checksum
// iso_url = var.os_iso_url
iso_paths = [var.os_iso_paths]
// ****************
boot_wait = "5s"
boot_command = [
"<esc><wait>",
"<esc><wait>",
"/install.amd/vmlinuz <wait>",
"ipv6.disable=1 <wait>",
"auto=true <wait>",
"netcfg/dhcp_timeout=30 <wait>",
"priority=critical locale=en_US <wait>",
"preseed/url=http://aassdd.ru/.my-preseed/debian/preseed.cfg <wait>",
"--- <wait>",
"initrd=/install.amd/initrd.gz<wait><enter>"
]
}
build {
name = "template"
sources = ["source.vsphere-iso.debian-12"]
}

View File

@ -0,0 +1,64 @@
variable "vcenter_server" {
default = ""
sensitive = true
}
variable "vcenter_username" {
default = ""
sensitive = true
}
variable "vcenter_password" {
default = ""
sensitive = true
}
variable "vcenter_datacenter" {
default = ""
sensitive = true
}
variable "vcenter_cluster" {
default = ""
sensitive = true
}
variable "vcenter_host" {
default = ""
sensitive = true
}
variable "vcenter_datastore" {
default = ""
sensitive = true
}
variable "vcenter_folder" {
default = ""
sensitive = true
}
// ************************************
variable "vm_name" { default = "" }
variable "vm_num_cpu" { default = "" }
variable "vm_ram" { default = "" }
variable "vm_hardware_version" { default = "" }
variable "vm_guest_os_type" { default = "" }
variable "vm_disk_size" { default = "" }
variable "vm_network" { default = "" }
variable "vm_network_nic_type" { default = "" }
variable "os_version" { default = "" }
variable "os_family" { default = "" }
variable "os_iso_url" { default = "" }
// ************************************
variable "connection_username" { default = "" }
variable "connection_password" { default = "" }
// ************************************
variable "iso_checksum" { default = "" }
variable "os_iso_paths" { default = "" }
variable "iso_url" { default = "" }
variable "boot_command" { default = "" }