From fdfe5f100b0e8708b7ecf75cb8316134b1438765 Mon Sep 17 00:00:00 2001 From: Danny Bessems Date: Wed, 25 Jan 2023 14:16:50 +0100 Subject: [PATCH] Attempt to properly match build w/ source --- packer/build.pkr.hcl | 51 ++++++++++++++++++---- packer/{sources.pkr.hcl => source.pkr.hcl} | 0 2 files changed, 42 insertions(+), 9 deletions(-) rename packer/{sources.pkr.hcl => source.pkr.hcl} (100%) diff --git a/packer/build.pkr.hcl b/packer/build.pkr.hcl index 228fcb5..6b05668 100644 --- a/packer/build.pkr.hcl +++ b/packer/build.pkr.hcl @@ -6,12 +6,7 @@ packer { build { source "vsphere-iso.ubuntu" { name = "bootstrap" - vm_name = "${var.vm_name}-bootstrap" - } - - source "vsphere-iso.ubuntu" { - name = "upgrade" - vm_name = "${var.vm_name}-upgrade" + vm_name = "${var.vm_name}-${build.PackerRunUUID}" } provisioner "ansible" { @@ -36,11 +31,49 @@ build { inline = [ "pwsh -command \"& scripts/Update-OvfConfiguration.ps1 \\", " -ApplianceType '${source.name}' \\", - " -OVFFile '/scratch/airgapped-k8s/${var.vm_name}-${source.name}.ovf' \"", + " -OVFFile '/scratch/airgapped-k8s/${var.vm_name}-${build.PackerRunUUID}.ovf' \"", "pwsh -file scripts/Update-Manifest.ps1 \\", - " -ManifestFileName '/scratch/airgapped-k8s/${var.vm_name}-${source.name}.mf'", + " -ManifestFileName '/scratch/airgapped-k8s/${var.vm_name}-${build.PackerRunUUID}.mf'", "ovftool --acceptAllEulas --allowExtraConfig --overwrite \\", - " '/scratch/airgapped-k8s/${var.vm_name}-${source.name}.ovf' \\", + " '/scratch/airgapped-k8s/${var.vm_name}-${build.PackerRunUUID}.ovf' \\", + " /output/airgapped-k8s.${source.name}.ova" + ] + } +} + +build { + source "vsphere-iso.ubuntu" { + name = "upgrade" + vm_name = "${var.vm_name}-${build.PackerRunUUID}" + } + + provisioner "ansible" { + pause_before = "2m30s" + + playbook_file = "ansible/playbook.yml" + user = "ubuntu" + ansible_env_vars = [ + "ANSIBLE_CONFIG=ansible/ansible.cfg", + "PYTHONUNBUFFERED=1" + ] + use_proxy = "false" + extra_arguments = [ + "--extra-vars", "appliancetype=${source.name}", + "--extra-vars", "ansible_ssh_pass=${var.ssh_password}"//, + // "--extra-vars", "repo_username=${var.repo_username}", + // "--extra-vars", "repo_password=${var.repo_password}" + ] + } + + post-processor "shell-local" { + inline = [ + "pwsh -command \"& scripts/Update-OvfConfiguration.ps1 \\", + " -ApplianceType '${source.name}' \\", + " -OVFFile '/scratch/airgapped-k8s/${var.vm_name}-${build.PackerRunUUID}.ovf' \"", + "pwsh -file scripts/Update-Manifest.ps1 \\", + " -ManifestFileName '/scratch/airgapped-k8s/${var.vm_name}-${build.PackerRunUUID}.mf'", + "ovftool --acceptAllEulas --allowExtraConfig --overwrite \\", + " '/scratch/airgapped-k8s/${var.vm_name}-${build.PackerRunUUID}.ovf' \\", " /output/airgapped-k8s.${source.name}.ova" ] } diff --git a/packer/sources.pkr.hcl b/packer/source.pkr.hcl similarity index 100% rename from packer/sources.pkr.hcl rename to packer/source.pkr.hcl