assign ip to ubuntu 20.04 during installation (packer/cloud-init context)

I was able to solve it by adding the ip= directive in the kernel command line. This is what boot_command looks like now:

      "boot_command": [
        "<esc><enter><f6><esc><wait> ",
        "<bs><bs><bs><bs><bs>",
        "ip={{ user `vm_ip` }}::{{ user `vm_gateway` }}:{{ user `vm_netmask` }}::::{{ user `vm_dns` }} ",
        "autoinstall ds=nocloud-net;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ ",
        "--- <enter>"
      ]

This is the syntax:

client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf>:
   <dns0-ip>:<dns1-ip>:<ntp0-ip>:...

Reference: https://git.kernel.org/pub/scm/libs/klibc/klibc.git/tree/usr/kinit/ipconfig/README.ipconfig

So I skipped server-ip (which is for nfs - not needed), then the hostname, device (which is the network interface - don't need it, it only led to more confusion on my part) and autoconf, and I added dns0 after the netmask. For example:

ip=192.168.0.20::192.168.0.1:255.255.255.0::::8.8.8.8

So for anyone interested out there, the full command would be (dummy IPs):

initrd=/casper/initrd quiet ip=192.168.0.20::192.168.0.1:255.255.255.0::::8.8.8.8 autoinstall ds=nocloud-net;s=http://192.168.0.50:80 ---

--- is important in that whatever is written afterwards persists in the proc cmdline (/proc/cmdline), so it means it will be run over and over at boot time. You probably don't want to do that with autoinstall and the network configuration (which is going to be copied into cloud-init automatically, anyway, so that persists anyhow).

Maybe this is going to help someone. There's much I still need to understand myself :)