Configuring a Host-Only network adapter with Ubuntu running on a VM

For work I sometimes need to test or debug deployments on virtual machines. To do this I like to spin up a local vm in Virtualbox. Since I need to be able to ssh into it, it requires a host-only network adapter.

Whenever I provision a fresh machine of this kind, I have forgotten how to get the host-only adapter to work and it's hard to find the right instructions online since the process has changed so much during the various Ubuntu version.

So here it goes: How to set up a host-only adapter with Ubuntu 22.04 running in a Virtualbox:

network:
  ethernets:
    enp0s3:
      dhcp4: true
    enp0s8: # This is the network device I identified earlier
      dhcp4: no
      addresses:
        - 192.168.56.104/24
  version: 2