Skip to content

Instantly share code, notes, and snippets.

@olivierlambert
Last active April 4, 2024 15:55
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olivierlambert/0eff6d8c10dfb11e1f28efe66d37ce6f to your computer and use it in GitHub Desktop.
Save olivierlambert/0eff6d8c10dfb11e1f28efe66d37ce6f to your computer and use it in GitHub Desktop.
Debian 12 generator for Packer on XCP-ng
packer {
required_plugins {
xenserver= {
version = "= v0.7.0"
source = "github.com/ddelnano/xenserver"
}
}
}
variable "remote_host" {
type = string
description = "The ip or fqdn of your XCP-ng. It must be the master"
sensitive = true
default = "10.10.1.66"
}
variable "remote_username" {
type = string
description = "The username used to interact with your XCP-ng"
sensitive = true
default = "root"
}
variable "remote_password" {
type = string
description = "The password used to interact with your XCP-ng"
sensitive = true
default = "P@ssw0rd"
}
variable "sr_iso_name" {
type = string
description = "The ISO-SR to packer will use"
default = "ISO Repository"
}
variable "sr_name" {
type = string
description = "The name of the SR to packer will use"
default = "Local storage"
}
source "xenserver-iso" "debian12" {
iso_checksum = "013f5b44670d81280b5b1bc02455842b250df2f0c6763398feb69af1a805a14f"
iso_url = "https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-12.5.0-amd64-netinst.iso"
sr_iso_name = var.sr_iso_name
sr_name = var.sr_name
tools_iso_name = ""
remote_host = var.remote_host
remote_password = var.remote_password
remote_username = var.remote_username
http_directory = "http"
ip_getter = "tools"
boot_command = [
"<wait><wait><wait><esc><wait><wait><wait>",
"/install.amd/vmlinuz ",
"initrd=/install.amd/initrd.gz ",
"auto=true ",
"domain= ",
"url=http://{{.HTTPIP}}:{{.HTTPPort}}/preseed.cfg ",
"hostname=debian ",
"interface=auto ",
"vga=788 noprompt quiet--- <enter>"
]
# Change this to match the ISO of ubuntu you are using in the iso_url variable
clone_template = "Debian Bookworm 12"
vm_name = "Debian 12 template"
vm_description = "My first template with packer"
vcpus_max = 2
vcpus_atstartup = 2
vm_memory = 2048 #MB
network_names = ["Private Lab"]
disk_size = 20480 #MB
disk_name = "debian disk"
vm_tags = ["Generated by Packer"]
ssh_username = "debian"
ssh_password = "debian"
ssh_wait_timeout = "60000s"
ssh_handshake_attempts = 10000
output_directory = "packer-debian-12"
keep_vm = "never"
format = "xva_compressed"
}
build {
sources = ["xenserver-iso.debian12"]
}
@tbalthazar
Copy link

Thanks for this.
Debian Bookwork 12 should be Debian Bookworm 12 (worm not work 🙂)

@olivierlambert
Copy link
Author

haha thanks, fixing it now!

@nullstream
Copy link

nullstream commented Mar 2, 2024

In the boot command, I was thrown off by the IP of the web server and stood one up for this but then found there is a
built in variable that can be used. Specifically:
"http://{{ .HTTPIP }}:{{.HTTPPort}}/preseed.cfg"

You will then need to set the http_directoryvariable accordingly.

Here is how I did it:

  # serve files from the current working directory 
  http_directory = "."
  boot_command = [
    "<wait><wait><wait><esc><wait><wait><wait>",
    "/install.amd/vmlinuz ",
    "initrd=/install.amd/initrd.gz ",
    "auto=true ",
    "domain= ",
    "url=http://{{.HTTPIP}}:{{.HTTPPort}}/preseed.cfg ",
    "hostname={{`var.name`}} ",
    "interface=auto ",
    "vga=788 noprompt quiet--- <enter>"
  ]

@olivierlambert
Copy link
Author

Thanks @nullstream, it's updated here and we are updating the blog post to take it into account too 👍

@Arsal-Zeb
Copy link

Thanks @olivierlambert for posting this. I'm using the same script to create a template through Packer and then through Terraform I want to create multiple VMs on xen-server. But I want to use two different disks (one for OS, one for APP data), so how can I define that? and should be defined in Packer script or Terraform script? Thanks

@chrispro-21
Copy link

Is there support for a pre downloaded ISO already in a ISO SR?

@olivierlambert
Copy link
Author

@chrispro-21 yes!

First, check that you have the SR name is defined:

variable "sr_iso_name" {
  type        = string
  default     = "ISO Repository"
  description = "The ISO-SR to packer will use"
}

Then, you can use iso_name = "debian-12.5.0-amd64-netinst.iso" directly instead of the URL of the ISO.

@chrispro-21
Copy link

chrispro-21 commented Apr 4, 2024

Awesome! That works! Thank you very much!

@olivierlambert
Copy link
Author

Thanks to @AtaxyaNetwork for the tip 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment