Skip to content

Commit

Permalink
[packer] Handle VBox versions requiring --nat-localhostreachableN
Browse files Browse the repository at this point in the history
  • Loading branch information
binary-manu committed Mar 10, 2024
1 parent 07ab81f commit ac0206c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packer/packer-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
"cmd_ansible" : "/tmp/ansible_venv/bin/ansible-playbook",
"memory" : "2048",
"disk_size" : "65536",
"off_cmd" : "poweroff"
"off_cmd" : "poweroff",
"nat_key" : "{{env `ARCH_ANSIBLE_PACKER_VBOX_NAT_LOCALHOST_KEY`}}",
"nat_val" : "{{env `ARCH_ANSIBLE_PACKER_VBOX_NAT_LOCALHOST_VAL`}}"
},


"builders": [
{
"name" : "virtualbox-uefi",
Expand All @@ -38,6 +39,7 @@
"iso_interface" : "sata",
"vboxmanage": [
["modifyvm", "{{.Name}}", "--nictype1", "virtio"],
["modifyvm", "{{.Name}}", "{{user `nat_key`}}", "{{user `nat_val`}}"],
["modifyvm", "{{.Name}}", "--vram", "16"],
["modifyvm", "{{.Name}}", "--rtcuseutc", "on"],
["modifyvm", "{{.Name}}", "--graphicscontroller", "vmsvga"],
Expand Down Expand Up @@ -65,6 +67,7 @@
"iso_interface" : "sata",
"vboxmanage": [
["modifyvm", "{{.Name}}", "--nictype1", "virtio"],
["modifyvm", "{{.Name}}", "{{user `nat_key`}}", "{{user `nat_val`}}"],
["modifyvm", "{{.Name}}", "--vram", "16"],
["modifyvm", "{{.Name}}", "--rtcuseutc", "on"],
["modifyvm", "{{.Name}}", "--graphicscontroller", "vmsvga"],
Expand Down
15 changes: 15 additions & 0 deletions packer/packer-wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

set -ex

if VBoxManage modifyvm --help 2>&1 | grep -q -- --nat-localhostreachableN; then
export ARCH_ANSIBLE_PACKER_VBOX_NAT_LOCALHOST_KEY="--nat-localhostreachable1"
export ARCH_ANSIBLE_PACKER_VBOX_NAT_LOCALHOST_VAL="on"
else
# Since the JSON is static, we must pass something valid into these vars
# but it also has to be idempotent. Just restate that the first NIC is NAT.
export ARCH_ANSIBLE_PACKER_VBOX_NAT_LOCALHOST_KEY="--nic1"
export ARCH_ANSIBLE_PACKER_VBOX_NAT_LOCALHOST_VAL="nat"
fi

packer "$@"

0 comments on commit ac0206c

Please sign in to comment.