Merge pull request #57 from ddelnano/ddelnano/add-dynamic-ubuntu-example
Update ubuntu example to be resilient to upstream minor releases
This commit is contained in:
commit
8c58db3504
@ -1,12 +1,43 @@
|
|||||||
packer {
|
packer {
|
||||||
required_plugins {
|
required_plugins {
|
||||||
xenserver= {
|
xenserver= {
|
||||||
version = ">= v0.3.2"
|
version = ">= v0.5.2"
|
||||||
source = "github.com/ddelnano/xenserver"
|
source = "github.com/ddelnano/xenserver"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# The ubuntu_version value determines what Ubuntu iso URL and sha256 hash we lookup. Updating
|
||||||
|
# this will allow a new version to be pulled in.
|
||||||
|
data "null" "ubuntu_version" {
|
||||||
|
input = "20.04"
|
||||||
|
}
|
||||||
|
|
||||||
|
locals {
|
||||||
|
timestamp = regex_replace(timestamp(), "[- TZ:]", "")
|
||||||
|
ubuntu_version = data.null.ubuntu_version.output
|
||||||
|
|
||||||
|
# Update this map to support future releases. At this time, the Ubuntu
|
||||||
|
# jammy template is not available yet.
|
||||||
|
ubuntu_template_name = {
|
||||||
|
20.04 = "Ubuntu Focal Fossa 20.04"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# TODO(ddelnano): Update this to use a local once https://github.com/hashicorp/packer/issues/11011
|
||||||
|
# is fixed.
|
||||||
|
data "http" "ubuntu_sha_and_release" {
|
||||||
|
url = "https://releases.ubuntu.com/${data.null.ubuntu_version.output}/SHA256SUMS"
|
||||||
|
}
|
||||||
|
|
||||||
|
local "ubuntu_sha256" {
|
||||||
|
expression = regex("([A-Za-z0-9]+)[\\s\\*]+ubuntu-.*server", data.http.ubuntu_sha_and_release.body)
|
||||||
|
}
|
||||||
|
|
||||||
|
local "ubuntu_url_path" {
|
||||||
|
expression = regex("[A-Za-z0-9]+[\\s\\*]+ubuntu-${local.ubuntu_version}.(\\d+)-live-server-amd64.iso", data.http.ubuntu_sha_and_release.body)
|
||||||
|
}
|
||||||
|
|
||||||
variable "remote_host" {
|
variable "remote_host" {
|
||||||
type = string
|
type = string
|
||||||
description = "The ip or fqdn of your XenServer. This will be pulled from the env var 'PKR_VAR_XAPI_HOST'"
|
description = "The ip or fqdn of your XenServer. This will be pulled from the env var 'PKR_VAR_XAPI_HOST'"
|
||||||
@ -42,15 +73,10 @@ variable "sr_name" {
|
|||||||
description = "The name of the SR to packer will use"
|
description = "The name of the SR to packer will use"
|
||||||
}
|
}
|
||||||
|
|
||||||
locals {
|
|
||||||
timestamp = regex_replace(timestamp(), "[- TZ:]", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
source "xenserver-iso" "ubuntu-2004" {
|
source "xenserver-iso" "ubuntu-2004" {
|
||||||
iso_checksum = "5035be37a7e9abbdc09f0d257f3e33416c1a0fb322ba860d42d74aa75c3468d4"
|
iso_checksum = local.ubuntu_sha256.0
|
||||||
iso_checksum_type = "sha256"
|
iso_checksum_type = "sha256"
|
||||||
iso_url = "http://releases.ubuntu.com/20.04/ubuntu-20.04.5-live-server-amd64.iso"
|
iso_url = "https://releases.ubuntu.com/${local.ubuntu_version}/ubuntu-${local.ubuntu_version}.${local.ubuntu_url_path.0}-live-server-amd64.iso"
|
||||||
|
|
||||||
sr_iso_name = var.sr_iso_name
|
sr_iso_name = var.sr_iso_name
|
||||||
sr_name = var.sr_name
|
sr_name = var.sr_name
|
||||||
@ -61,11 +87,11 @@ source "xenserver-iso" "ubuntu-2004" {
|
|||||||
remote_username = var.remote_username
|
remote_username = var.remote_username
|
||||||
|
|
||||||
# Change this to match the ISO of ubuntu you are using in the iso_url variable
|
# Change this to match the ISO of ubuntu you are using in the iso_url variable
|
||||||
clone_template = "Ubuntu Focal Fossa 20.04"
|
clone_template = local.ubuntu_template_name[data.null.ubuntu_version.output]
|
||||||
vm_name = "packer-ubuntu-2004-${local.timestamp}"
|
vm_name = "packer-ubuntu-${data.null.ubuntu_version.output}-${local.timestamp}"
|
||||||
vm_description = "Build started: ${local.timestamp}"
|
vm_description = "Build started: ${local.timestamp}"
|
||||||
vm_memory = 4096
|
vm_memory = 4096
|
||||||
disk_size = 20000
|
disk_size = 30720
|
||||||
|
|
||||||
floppy_files = [
|
floppy_files = [
|
||||||
"examples/http/ubuntu-2004/meta-data",
|
"examples/http/ubuntu-2004/meta-data",
|
||||||
|
Loading…
Reference in New Issue
Block a user