-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
29818aa
commit a2544de
Showing
4 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
|
||
# https://bugs.launchpad.net/cloud-init/+bug/1890528 | ||
# cloud-init can return an exit status on wait other than 0 | ||
# so eat the exit status for now so it doesn't error packer | ||
cloud_init_status=0 | ||
cloud-init status --wait || cloud_init_status=$? | ||
|
||
if [ "$cloud_init_status" = "0" ]; then | ||
echo "cloud-init succeeded" | ||
else | ||
echo "cloud-init exit=${cloud_init_status}" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# CentOS Cloud Images | ||
|
||
## CentOS Stream 9 UEFI virtual firmware | ||
|
||
``` | ||
cd centos/cloud/x86_64 | ||
packer init . | ||
PACKER_LOG=1 packer build \ | ||
-var-file centos-stream-9-x86_64.pkrvars.hcl \ | ||
centos.pkr.hcl | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
efi_boot = true | ||
efi_firmware_code = "/usr/share/OVMF/OVMF_CODE.fd" | ||
efi_firmware_vars = "/usr/share/OVMF/OVMF_VARS.fd" | ||
iso_checksum = "file:https://cloud.centos.org/centos/9-stream/x86_64/images/CHECKSUM" | ||
iso_url = "https://cloud.centos.org/centos/9-stream/x86_64/images/CentOS-Stream-GenericCloud-x86_64-9-latest.x86_64.qcow2" | ||
vm_name = "centos-stream-9-x86_64" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
packer { | ||
required_plugins { | ||
qemu = { | ||
version = "~> 1" | ||
source = "github.com/hashicorp/qemu" | ||
} | ||
} | ||
} | ||
|
||
variable "efi_boot" { | ||
type = bool | ||
default = false | ||
} | ||
|
||
variable "efi_firmware_code" { | ||
type = string | ||
default = null | ||
} | ||
|
||
variable "efi_firmware_vars" { | ||
type = string | ||
default = null | ||
} | ||
|
||
variable "ssh_username" { | ||
type = string | ||
default = "packer" | ||
} | ||
|
||
variable "ssh_password" { | ||
type = string | ||
default = "packer" | ||
} | ||
|
||
variable "vm_name" { | ||
type = string | ||
default = "centos-stream-9-x86_64" | ||
} | ||
|
||
source "file" "user_data" { | ||
content = <<EOF | ||
#cloud-config | ||
user: ${var.ssh_username} | ||
password: ${var.ssh_password} | ||
chpasswd: { expire: False } | ||
ssh_pwauth: True | ||
EOF | ||
target = "boot-${var.vm_name}/user-data" | ||
} | ||
|
||
source "file" "meta_data" { | ||
content = <<EOF | ||
instance-id: centos-cloud | ||
local-hostname: centos-cloud | ||
EOF | ||
target = "boot-${var.vm_name}/meta-data" | ||
} | ||
|
||
build { | ||
sources = ["sources.file.user_data", "sources.file.meta_data"] | ||
|
||
provisioner "shell-local" { | ||
inline = ["genisoimage -output boot-${var.vm_name}/cidata.iso -input-charset utf-8 -volid cidata -joliet -r boot-${var.vm_name}/user-data boot-${var.vm_name}/meta-data"] | ||
} | ||
} | ||
|
||
variable "iso_checksum" { | ||
type = string | ||
default = "file:https://cloud.centos.org/centos/9-stream/x86_64/images/CHECKSUM" | ||
} | ||
|
||
variable "iso_url" { | ||
type = string | ||
default = "https://cloud.centos.org/centos/9-stream/x86_64/images/CentOS-Stream-GenericCloud-x86_64-9-latest.x86_64.qcow2" | ||
} | ||
|
||
source "qemu" "centos" { | ||
# RHEL9 removed support for qemu64 in their distributed qemu package, | ||
# forcing that cpu_model be defined | ||
cpu_model = "host" | ||
disk_compression = true | ||
disk_image = true | ||
disk_size = "30G" | ||
iso_checksum = var.iso_checksum | ||
iso_url = var.iso_url | ||
machine_type = "q35" | ||
qemuargs = [ | ||
["-cdrom", "boot-${var.vm_name}/cidata.iso"] | ||
] | ||
output_directory = "output-${var.vm_name}" | ||
shutdown_command = "echo '${var.ssh_password}' | sudo -S shutdown -P now" | ||
ssh_password = var.ssh_password | ||
ssh_timeout = "120s" | ||
ssh_username = var.ssh_username | ||
vm_name = "${var.vm_name}.qcow2" | ||
efi_boot = var.efi_boot | ||
efi_firmware_code = var.efi_firmware_code | ||
efi_firmware_vars = var.efi_firmware_vars | ||
} | ||
|
||
build { | ||
sources = ["source.qemu.centos"] | ||
|
||
# cloud-init may still be running when we start executing scripts | ||
# To avoid race conditions, make sure cloud-init is done first | ||
provisioner "shell" { | ||
execute_command = "echo '${var.ssh_password}' | {{ .Vars }} sudo -S -E sh -eux '{{ .Path }}'" | ||
scripts = [ | ||
"../scripts/cloud-init-wait.sh", | ||
] | ||
} | ||
} |