diff --git a/examples/http/ubuntu-2404/meta-data b/examples/http/ubuntu-2404/meta-data new file mode 100644 index 0000000..e69de29 diff --git a/examples/http/ubuntu-2404/user-data b/examples/http/ubuntu-2404/user-data new file mode 100644 index 0000000..324876f --- /dev/null +++ b/examples/http/ubuntu-2404/user-data @@ -0,0 +1,49 @@ +#cloud-config +autoinstall: + version: 1 + identity: + hostname: ubuntu-server + # This is the crypted pass of 'ubuntu' + password: "$6$exDY1mhS4KUYCE/2$zmn9ToZwTKLhCw.b4/b.ZRTIZM30JZ4QrOQ2aOXJ8yk96xpcCof0kxKwuX1kqLG/ygbJ1f8wxED22bTL4F46P0" + username: testuser + ssh: + install-server: true + allow-pw: true + + packages: + - apt-transport-https + - ca-certificates + - curl + - software-properties-common + package_upgrade: false + + # late-commands are run at the very end of the *installer*, before the first + # reboot. However users are actually created by cloud-init after the first + # reboot. So these commands can't affect anything that requires a user to + # actually exist. + late-commands: + # Add xen-guest-agent - this is impossible (!) on Ubuntu 24.04 using + # the normal apt/packages autoinstall configuration, because (a) the + # xen-guest-agent apt repository does not use the "components" field + # (odd, but legal); (b) curtin's apt-config process hard requires + # deb822 .sources to have a "Components:" key, and (c) even if we + # try to configure it with a .list entry rather than .source entry + # under "apt:", on Ubuntu 24 curtin force-converts "deb" lines to + # deb822 format. I wasted days on this. Have to just do it the + # old-fashioned way here. + - 'echo "deb [trusted=yes] https://gitlab.com/api/v4/projects/xen-project%252Fxen-guest-agent/packages/generic/deb-amd64/ release/" > /target/etc/apt/sources.list.d/xen.list' + - curtin in-target --target /target -- apt-get update + - curtin in-target --target /target -- apt-get install -y xen-guest-agent + + # If you want to do anything custom with files from "cd_files", + # uncomment these lines + #- mount /dev/sr1 /mnt + #- cp /mnt/my-cool.conf /target/etc/path/cool.conf + #- umount /mnt + + # User-data is passed to the "real" cloud-init, which runs after the first + # reboot after the installer has finished. So you can run commands which + # modify users here, such as added 'testuser' to a new group. + #user-data: + # runcmd: + # - [ 'usermod', '-a', '-G', 'backup', 'testuser' ] diff --git a/examples/ubuntu/ubuntu-2404.pkr.hcl b/examples/ubuntu/ubuntu-2404.pkr.hcl new file mode 100644 index 0000000..e2e9fd9 --- /dev/null +++ b/examples/ubuntu/ubuntu-2404.pkr.hcl @@ -0,0 +1,125 @@ +packer { + required_plugins { + xenserver= { + version = ">= v0.6.0" + 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 = "24.04" +} + +locals { + timestamp = regex_replace(timestamp(), "[- TZ:]", "") + ubuntu_version = data.null.ubuntu_version.output + + # Update this map depending on what templates are available on your Xen server. + ubuntu_template_name = { + 24.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) +} + +variable "remote_host" { + type = string + description = "The ip or fqdn of your XenServer. This will be pulled from the env var 'PKR_VAR_remote_host'" + sensitive = true + default = null +} + +variable "remote_password" { + type = string + description = "The password used to interact with your XenServer. This will be pulled from the env var 'PKR_VAR_remote_password'" + sensitive = true + default = null +} + +variable "remote_username" { + type = string + description = "The username used to interact with your XenServer. This will be pulled from the env var 'PKR_VAR_remote_username'" + sensitive = true + default = null +} + +variable "sr_iso_name" { + type = string + description = "The name of the SR packer will use to store the installation ISO" + default = "" +} + +variable "sr_name" { + type = string + description = "The name of the SR packer will use to create the VM" + default = "" +} + +source "xenserver-iso" "ubuntu-2404" { + iso_checksum = "sha256:${local.ubuntu_sha256.0}" + iso_url = "https://releases.ubuntu.com/${local.ubuntu_version}/ubuntu-${local.ubuntu_version}-live-server-amd64.iso" + + sr_name = var.sr_name + sr_iso_name = var.sr_iso_name + remote_host = var.remote_host + remote_password = var.remote_password + remote_username = var.remote_username + + clone_template = local.ubuntu_template_name[data.null.ubuntu_version.output] + vm_name = "ubuntu-${data.null.ubuntu_version.output}-gold" + vm_description = "Built at ${local.timestamp}" + vm_memory = 8192 + disk_size = 10240 + vcpus_max = 4 + vcpus_atstartup = 4 + + boot_command = [ + "c", + "set gfxpayload=keep", + "linux /casper/vmlinuz autoinstall ---", + "initrd /casper/initrd", + "boot" + ] + cd_files = [ + "examples/http/ubuntu-2404/meta-data", + "examples/http/ubuntu-2404/user-data" + ] + + # The xenserver plugin needs to SSH in to the new VM, so we give it + # the information to do so + ssh_username = "testuser" + ssh_password = "ubuntu" + ssh_wait_timeout = "60000s" + ssh_handshake_attempts = 10000 + + + output_directory = null + keep_vm = "always" +} + +build { + sources = ["xenserver-iso.ubuntu-2404"] + + # Things to do on the new VM once it's past first reboot: + + # Wait for cloud-init to finish everything. We need to do this as a + # packer provisioner to prevent packer-plugin-xenserver from shutting + # the VM down before all cloud-init processing is complete. + provisioner "shell" { + inline = [ + "echo ubuntu | sudo -S cloud-init status --wait" + ] + valid_exit_codes = [0, 2] + } +}