diff --git a/packer/alma/alma.pkr.hcl b/packer/alma/alma.pkr.hcl index bc7d844f..1e3b5f46 100644 --- a/packer/alma/alma.pkr.hcl +++ b/packer/alma/alma.pkr.hcl @@ -65,12 +65,12 @@ build { expect_disconnect = true } - post-processors { - post-processor "shell-local" { - inline = [ - "virt-sysprep --add ${var.output_dir}/${var.appliance_name} --selinux-relabel --root-password disabled --hostname localhost.localdomain --run-command 'truncate -s0 -c /etc/machine-id' --delete /etc/resolv.conf", - "virt-sparsify --in-place ${var.output_dir}/${var.appliance_name}" + post-processor "shell-local" { + execute_command = ["bash", "-c", "{{.Vars}} {{.Script}}"] + environment_vars = [ + "OUTPUT_DIR=${var.output_dir}", + "APPLIANCE_NAME=${var.appliance_name}", ] - } + scripts = [ "packer/postprocess.sh" ] } } diff --git a/packer/alpine/alpine.pkr.hcl b/packer/alpine/alpine.pkr.hcl index 440d14c5..a96620d5 100644 --- a/packer/alpine/alpine.pkr.hcl +++ b/packer/alpine/alpine.pkr.hcl @@ -55,12 +55,12 @@ build { expect_disconnect = true } - post-processors { - post-processor "shell-local" { - inline = [ - "virt-sysprep --add ${var.output_dir}/${var.appliance_name} --selinux-relabel --root-password disabled --hostname localhost.localdomain --run-command 'truncate -s0 -c /etc/machine-id' --delete /etc/resolv.conf", - "virt-sparsify --in-place ${var.output_dir}/${var.appliance_name}" + post-processor "shell-local" { + execute_command = ["bash", "-c", "{{.Vars}} {{.Script}}"] + environment_vars = [ + "OUTPUT_DIR=${var.output_dir}", + "APPLIANCE_NAME=${var.appliance_name}", ] - } + scripts = [ "packer/postprocess.sh" ] } } diff --git a/packer/alt/alt.pkr.hcl b/packer/alt/alt.pkr.hcl index cf16b890..a716d9f6 100644 --- a/packer/alt/alt.pkr.hcl +++ b/packer/alt/alt.pkr.hcl @@ -65,12 +65,12 @@ build { expect_disconnect = true } - post-processors { - post-processor "shell-local" { - inline = [ - "virt-sysprep --add ${var.output_dir}/${var.appliance_name} --selinux-relabel --root-password disabled --hostname localhost.localdomain --run-command 'truncate -s0 -c /etc/machine-id' --delete /etc/resolv.conf", - "virt-sparsify --in-place ${var.output_dir}/${var.appliance_name}" + post-processor "shell-local" { + execute_command = ["bash", "-c", "{{.Vars}} {{.Script}}"] + environment_vars = [ + "OUTPUT_DIR=${var.output_dir}", + "APPLIANCE_NAME=${var.appliance_name}", ] - } + scripts = [ "packer/postprocess.sh" ] } } diff --git a/packer/amazon/amazon.pkr.hcl b/packer/amazon/amazon.pkr.hcl index 19dbffa8..b97adeda 100644 --- a/packer/amazon/amazon.pkr.hcl +++ b/packer/amazon/amazon.pkr.hcl @@ -65,12 +65,12 @@ build { expect_disconnect = true } - post-processors { - post-processor "shell-local" { - inline = [ - "virt-sysprep --add ${var.output_dir}/${var.appliance_name} --selinux-relabel --root-password disabled --hostname localhost.localdomain --run-command 'truncate -s0 -c /etc/machine-id' --delete /etc/resolv.conf", - "virt-sparsify --in-place ${var.output_dir}/${var.appliance_name}" + post-processor "shell-local" { + execute_command = ["bash", "-c", "{{.Vars}} {{.Script}}"] + environment_vars = [ + "OUTPUT_DIR=${var.output_dir}", + "APPLIANCE_NAME=${var.appliance_name}", ] - } + scripts = [ "packer/postprocess.sh" ] } } diff --git a/packer/centos/centos.pkr.hcl b/packer/centos/centos.pkr.hcl index 053dacce..e1fb7557 100644 --- a/packer/centos/centos.pkr.hcl +++ b/packer/centos/centos.pkr.hcl @@ -65,12 +65,12 @@ build { expect_disconnect = true } - post-processors { - post-processor "shell-local" { - inline = [ - "virt-sysprep --add ${var.output_dir}/${var.appliance_name} --selinux-relabel --root-password disabled --hostname localhost.localdomain --run-command 'truncate -s0 -c /etc/machine-id' --delete /etc/resolv.conf", - "virt-sparsify --in-place ${var.output_dir}/${var.appliance_name}" + post-processor "shell-local" { + execute_command = ["bash", "-c", "{{.Vars}} {{.Script}}"] + environment_vars = [ + "OUTPUT_DIR=${var.output_dir}", + "APPLIANCE_NAME=${var.appliance_name}", ] - } + scripts = [ "packer/postprocess.sh" ] } } diff --git a/packer/debian/debian.pkr.hcl b/packer/debian/debian.pkr.hcl index a27419b3..0279af56 100644 --- a/packer/debian/debian.pkr.hcl +++ b/packer/debian/debian.pkr.hcl @@ -64,12 +64,12 @@ build { expect_disconnect = true } - post-processors { - post-processor "shell-local" { - inline = [ - "virt-sysprep --add ${var.output_dir}/${var.appliance_name} --selinux-relabel --root-password disabled --hostname localhost.localdomain --run-command 'truncate -s0 -c /etc/machine-id' --delete /etc/resolv.conf", - "virt-sparsify --in-place ${var.output_dir}/${var.appliance_name}" + post-processor "shell-local" { + execute_command = ["bash", "-c", "{{.Vars}} {{.Script}}"] + environment_vars = [ + "OUTPUT_DIR=${var.output_dir}", + "APPLIANCE_NAME=${var.appliance_name}", ] - } + scripts = [ "packer/postprocess.sh" ] } } diff --git a/packer/devuan/devuan.pkr.hcl b/packer/devuan/devuan.pkr.hcl index 5e029369..b4b97aca 100644 --- a/packer/devuan/devuan.pkr.hcl +++ b/packer/devuan/devuan.pkr.hcl @@ -50,12 +50,12 @@ build { expect_disconnect = true } - post-processors { - post-processor "shell-local" { - inline = [ - "virt-sysprep --add ${var.output_dir}/${var.appliance_name} --selinux-relabel --root-password disabled --hostname localhost.localdomain --run-command 'truncate -s0 -c /etc/machine-id' --delete /etc/resolv.conf", - "virt-sparsify --in-place ${var.output_dir}/${var.appliance_name}" + post-processor "shell-local" { + execute_command = ["bash", "-c", "{{.Vars}} {{.Script}}"] + environment_vars = [ + "OUTPUT_DIR=${var.output_dir}", + "APPLIANCE_NAME=${var.appliance_name}", ] - } + scripts = [ "packer/postprocess.sh" ] } } diff --git a/packer/fedora/fedora.pkr.hcl b/packer/fedora/fedora.pkr.hcl index b9b9ac6e..a5f68290 100644 --- a/packer/fedora/fedora.pkr.hcl +++ b/packer/fedora/fedora.pkr.hcl @@ -64,12 +64,12 @@ build { expect_disconnect = true } - post-processors { - post-processor "shell-local" { - inline = [ - "virt-sysprep --add ${var.output_dir}/${var.appliance_name} --selinux-relabel --root-password disabled --hostname localhost.localdomain --run-command 'truncate -s0 -c /etc/machine-id' --delete /etc/resolv.conf", - "virt-sparsify --in-place ${var.output_dir}/${var.appliance_name}" + post-processor "shell-local" { + execute_command = ["bash", "-c", "{{.Vars}} {{.Script}}"] + environment_vars = [ + "OUTPUT_DIR=${var.output_dir}", + "APPLIANCE_NAME=${var.appliance_name}", ] - } + scripts = [ "packer/postprocess.sh" ] } } diff --git a/packer/ol/ol.pkr.hcl b/packer/ol/ol.pkr.hcl index 1174da60..a74bc8dd 100644 --- a/packer/ol/ol.pkr.hcl +++ b/packer/ol/ol.pkr.hcl @@ -65,12 +65,12 @@ build { expect_disconnect = true } - post-processors { - post-processor "shell-local" { - inline = [ - "virt-sysprep --add ${var.output_dir}/${var.appliance_name} --selinux-relabel --root-password disabled --hostname localhost.localdomain --run-command 'truncate -s0 -c /etc/machine-id' --delete /etc/resolv.conf", - "virt-sparsify --in-place ${var.output_dir}/${var.appliance_name}" + post-processor "shell-local" { + execute_command = ["bash", "-c", "{{.Vars}} {{.Script}}"] + environment_vars = [ + "OUTPUT_DIR=${var.output_dir}", + "APPLIANCE_NAME=${var.appliance_name}", ] - } + scripts = [ "packer/postprocess.sh" ] } } diff --git a/packer/opensuse/opensuse.pkr.hcl b/packer/opensuse/opensuse.pkr.hcl index d263f73a..33f78647 100644 --- a/packer/opensuse/opensuse.pkr.hcl +++ b/packer/opensuse/opensuse.pkr.hcl @@ -67,12 +67,12 @@ build { expect_disconnect = true } - post-processors { - post-processor "shell-local" { - inline = [ - "virt-sysprep --add ${var.output_dir}/${var.appliance_name} --selinux-relabel --root-password disabled --hostname localhost.localdomain --run-command 'truncate -s0 -c /etc/machine-id' --delete /etc/resolv.conf", - "virt-sparsify --in-place ${var.output_dir}/${var.appliance_name}" + post-processor "shell-local" { + execute_command = ["bash", "-c", "{{.Vars}} {{.Script}}"] + environment_vars = [ + "OUTPUT_DIR=${var.output_dir}", + "APPLIANCE_NAME=${var.appliance_name}", ] - } + scripts = [ "packer/postprocess.sh" ] } } diff --git a/packer/postprocess.sh b/packer/postprocess.sh new file mode 100755 index 00000000..236283b0 --- /dev/null +++ b/packer/postprocess.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +timeout 5m virt-sysprep \ + --add ${OUTPUT_DIR}/${APPLIANCE_NAME} \ + --selinux-relabel \ + --root-password disabled \ + --hostname localhost.localdomain \ + --run-command 'truncate -s0 -c /etc/machine-id' \ + --delete /etc/resolv.conf + +# virt-sparsify was haning sometimes +for I in 1 2 3; do + timeout 5m virt-sparsify \ + --in-place ${OUTPUT_DIR}/${APPLIANCE_NAME} && break +done diff --git a/packer/rhel/rhel.pkr.hcl b/packer/rhel/rhel.pkr.hcl index 325afcf1..a617152b 100644 --- a/packer/rhel/rhel.pkr.hcl +++ b/packer/rhel/rhel.pkr.hcl @@ -71,12 +71,12 @@ build { expect_disconnect = true } - post-processors { - post-processor "shell-local" { - inline = [ - "virt-sysprep --add ${var.output_dir}/${var.appliance_name} --selinux-relabel --root-password disabled --hostname localhost.localdomain --run-command 'truncate -s0 -c /etc/machine-id' --delete /etc/resolv.conf", - "virt-sparsify --in-place ${var.output_dir}/${var.appliance_name}" + post-processor "shell-local" { + execute_command = ["bash", "-c", "{{.Vars}} {{.Script}}"] + environment_vars = [ + "OUTPUT_DIR=${var.output_dir}", + "APPLIANCE_NAME=${var.appliance_name}", ] - } + scripts = [ "packer/postprocess.sh" ] } } diff --git a/packer/rocky/rocky.pkr.hcl b/packer/rocky/rocky.pkr.hcl index 1c13ea97..ca549175 100644 --- a/packer/rocky/rocky.pkr.hcl +++ b/packer/rocky/rocky.pkr.hcl @@ -49,12 +49,12 @@ build { expect_disconnect = true } - post-processors { - post-processor "shell-local" { - inline = [ - "virt-sysprep --add ${var.output_dir}/${var.appliance_name} --selinux-relabel --root-password disabled --hostname localhost.localdomain --run-command 'truncate -s0 -c /etc/machine-id' --delete /etc/resolv.conf", - "virt-sparsify --in-place ${var.output_dir}/${var.appliance_name}" + post-processor "shell-local" { + execute_command = ["bash", "-c", "{{.Vars}} {{.Script}}"] + environment_vars = [ + "OUTPUT_DIR=${var.output_dir}", + "APPLIANCE_NAME=${var.appliance_name}", ] - } + scripts = [ "packer/postprocess.sh" ] } } diff --git a/packer/ubuntu/ubuntu.pkr.hcl b/packer/ubuntu/ubuntu.pkr.hcl index 5bfbab15..a7233204 100644 --- a/packer/ubuntu/ubuntu.pkr.hcl +++ b/packer/ubuntu/ubuntu.pkr.hcl @@ -65,12 +65,12 @@ build { expect_disconnect = true } - post-processors { - post-processor "shell-local" { - inline = [ - "virt-sysprep --add ${var.output_dir}/${var.appliance_name} --selinux-relabel --root-password disabled --hostname localhost.localdomain --run-command 'truncate -s0 -c /etc/machine-id' --delete /etc/resolv.conf", - "virt-sparsify --in-place ${var.output_dir}/${var.appliance_name}" + post-processor "shell-local" { + execute_command = ["bash", "-c", "{{.Vars}} {{.Script}}"] + environment_vars = [ + "OUTPUT_DIR=${var.output_dir}", + "APPLIANCE_NAME=${var.appliance_name}", ] - } + scripts = [ "packer/postprocess.sh" ] } }