Background
My main dev environment is windows convenient WSL2, however the WSL2 instance is isolated from the host machines IP, leading to some issues when it comes to accessing ports WSL ports on my LAN. Specifically the issue I ran into was when building packer and automating my Ubuntu 20.04 install. After some research I found that restricting the subiquity port and port forwarding vis netsh successfully allows packers http server to be reached on my host machines LAN.
Code and Commands
First you need to edit your packer file to restrict the http ports to a single port so you can port forward.
I have included a sample .pkc.hcl file below, the static port configuration is achieved on code lines 30 and 31 by defining http_port_max and http_port_min
source “vsphere-iso” “this” { | |
vcenter_server = var.vsphere_server | |
username = var.vsphere_user | |
password = var.vsphere_password | |
datacenter = var.datacenter | |
cluster = var.cluster | |
insecure_connection = true | |
vm_name = “tf-ubuntu-server-20.04” | |
guest_os_type = “ubuntu64Guest” | |
ssh_username = “ubuntu” | |
ssh_password = “ubuntu” | |
ssh_timeout = “20m” | |
ssh_handshake_attempts = “50” | |
CPUs = 8 | |
RAM = 4128 | |
RAM_reserve_all = true | |
disk_controller_type = [“pvscsi”] | |
datastore = var.datastore | |
storage { | |
disk_size = 16384 | |
disk_thin_provisioned = true | |
} | |
iso_paths = [“[iSCSI Raid-10] OS/ubuntu-20.04.2-live-server-amd64.iso”] | |
iso_checksum = “sha256:b23488689e16cad7a269eb2d3a3bf725d3457ee6b0868e00c8762d3816e25848” | |
http_directory = “subiquity/http” | |
http_port_max = 8336 | |
http_port_min = 8336 | |
network_adapters { | |
network = var.network_name | |
network_card = “vmxnet3” | |
} | |
boot_wait = “5s” | |
boot_command = [ | |
” “, | |
“autoinstall net.ifnames=0 biosdevname=0 ip=dhcp ipv6.disable=1 ds=nocloud-net;seedfrom=http://192.168.0.168:{{ .HTTPPort }}/”, | |
“” | |
] | |
} | |
build { | |
sources = [ | |
“source.vsphere-iso.this” | |
] | |
provisioner “shell” { | |
inline = [ | |
“while [ ! -f /var/lib/cloud/instance/boot-finished ]; do sleep 5; done”, | |
“sudo rm /etc/netplan/*”, | |
“sudo sed -i ‘s/ip=dhcp//g’ /etc/default/grub”, | |
“sudo update-grub”, | |
“sudo apt -y purge cloud-init” | |
] | |
} | |
} |
Next you will port forward the WLS2 port to your windows host machine with the below command in command prompt (as admin)
netsh interface portproxy add v4tov4 listenport=8336 listenaddress=0.0.0.0 connectport=8336 connectaddress=