**Issue:**

I'm trying to use packer to create an Ubuntu Server 22.04 image and I'm running into issues when it comes to renaming the NIC using a valid netplan config and then also installing one package.

**A couple things to note on the background:**

1. I'm renaming the NIC because I'm trying to use terraform to set the NIC config on startup using proxmox with cloud-init. When cloud-init runs on the cloned image it seems to want to rename the NIC on first boot and since it cannot rename the NIC (to eth0 from ens18) on the fly it takes a second reboot before cloud-init sets the proper IP address on the VM. This is less than ideal when I want to be able to spin an ubuntu server up with terraform since it takes a manual reboot.

I've had no issues with Proxmox and cloud-init drive/config settings it provides for the following OS's:

* AlmaLinux 8 & 9
* RHEL 7, 8, & 9
* Windows Server 2012, 2016, 2019, and 2022 (Cloudbase-init)

They all just seem to accept the cloud-init config that terraform sends over to proxmox to use and all is good to go. All this to say that maybe proxmox shouldn't be renaming the NIC, but Ubuntu Server is the first OS I've had issues with this on and I'm not really looking for a solution anywhere besides Ubuntu currently.

2. I need to install `qemu-guest-agent` on the VM so that packer is able to read in the IP address from the Proxmox API so it knows who to connect to.

**Specifics:**

1. I can install `qemu-guest-agent` if I don't specify any network settings and let subiquity/netplan provide the defaults. When I do this, the final `autoinstall-user-data` located in `/var/log/installer` on a successful autoinstall shows the following network and packages config:

```
autoinstall:
<snipped>
  network:
    ethernets:
      ens18:
        dhcp4: true
    version: 2
  packages:
  - qemu-guest-agent
<snipped>

```

2. I can successfully rename the NIC using subiquity/netplan. When this is done, it fails to install qemu-guest-agent and fails the build process. Here's the config I use for that:

```
  network:
    ethernets:
      ens18:
        match:
          driver: e1000
        dhcp4: true
        set-name: eth0
    version: 2
  packages:
  - qemu-guest-agent

```

The above `network:` block does successfully rename the NIC to eth0 AND I have full networking on the broken install. I'm able to ping something such as google.com and am also able to SSH into the machine. I can see from the logs that the rename is successful and I can verify the new NIC name on the failed install when it pops me into a shell.

Below are the errors this then runs into after the NIC rename.

From `subiquity-server-debug.log.1976`:

```
2022-09-04 07:21:30,557 DEBUG root:39 start: subiquity/Install/install/postinstall/install_qemu-guest-agent: installing qemu-guest-agent
2022-09-04 07:21:30,560 DEBUG subiquitycore.utils:112 astart_command called: ['systemd-run', '--wait', '--same-dir', '--property', 'SyslogIdentifier=subiquity_log.1976', '--setenv', 'PATH=/snap/subiquity/3698/bin:/snap/subiquity/3698/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/subiquity/3698/bin', '--setenv', 'PYTHONPATH=:/snap/subiquity/3698/lib/python3.8/site-packages', '--setenv', 'PYTHON=/snap/subiquity/3698/usr/bin/python3.8', '--setenv', 'SNAP=/snap/subiquity/3698', '--', '/snap/subiquity/3698/usr/bin/python3.8', '-m', 'curtin', '--showtrace', '-vvv', '--set', 'json:reporting={"subiquity": {"type": "journald", "identifier": "curtin_event.1976.5"}}', 'system-install', '-t', '/target', '--', 'qemu-guest-agent']
2022-09-04 07:21:30,570 INFO root:39 start: subiquity/Meta/status_GET: 
2022-09-04 07:21:31,706 DEBUG root:39 start: subiquity/Install/install/postinstall/install_qemu-guest-agent/cmd-system-install: curtin command system-install
2022-09-04 07:21:31,826 ERROR root:39 finish: subiquity/Install/install/postinstall/install_qemu-guest-agent: FAIL: Command '['systemd-run', '--wait', '--same-dir', '--property', 'SyslogIdentifier=subiquity_log.1976', '--setenv', 'PATH=/snap/subiquity/3698/bin:/snap/subiquity/3698/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/subiquity/3698/bin', '--setenv', 'PYTHONPATH=:/snap/subiquity/3698/lib/python3.8/site-packages', '--setenv', 'PYTHON=/snap/subiquity/3698/usr/bin/python3.8', '--setenv', 'SNAP=/snap/subiquity/3698', '--', '/snap/subiquity/3698/usr/bin/python3.8', '-m', 'curtin', '--showtrace', '-vvv', '--set', 'json:reporting={"subiquity": {"type": "journald", "identifier": "curtin_event.1976.5"}}', 'system-install', '-t', '/target', '--', 'qemu-guest-agent']' returned non-zero exit status 100.
2022-09-04 07:21:31,833 ERROR root:39 finish: subiquity/Install/install/postinstall: FAIL: Command '['systemd-run', '--wait', '--same-dir', '--property', 'SyslogIdentifier=subiquity_log.1976', '--setenv', 'PATH=/snap/subiquity/3698/bin:/snap/subiquity/3698/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/subiquity/3698/bin', '--setenv', 'PYTHONPATH=:/snap/subiquity/3698/lib/python3.8/site-packages', '--setenv', 'PYTHON=/snap/subiquity/3698/usr/bin/python3.8', '--setenv', 'SNAP=/snap/subiquity/3698', '--', '/snap/subiquity/3698/usr/bin/python3.8', '-m', 'curtin', '--showtrace', '-vvv', '--set', 'json:reporting={"subiquity": {"type": "journald", "identifier": "curtin_event.1976.5"}}', 'system-install', '-t', '/target', '--', 'qemu-guest-agent']' returned non-zero exit status 100.
2022-09-04 07:21:31,834 DEBUG subiquitycore.common.errorreport:384 generating crash report
2022-09-04 07:21:31,872 INFO subiquitycore.common.errorreport:406 saving crash report 'install failed crashed with CalledProcessError' to /var/crash/1662276091.834314585.install_fail.crash
2022-09-04 07:21:31,873 ERROR root:39 finish: subiquity/Install/install: FAIL: Command '['systemd-run', '--wait', '--same-dir', '--property', 'SyslogIdentifier=subiquity_log.1976', '--setenv', 'PATH=/snap/subiquity/3698/bin:/snap/subiquity/3698/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/subiquity/3698/bin', '--setenv', 'PYTHONPATH=:/snap/subiquity/3698/lib/python3.8/site-packages', '--setenv', 'PYTHON=/snap/subiquity/3698/usr/bin/python3.8', '--setenv', 'SNAP=/snap/subiquity/3698', '--', '/snap/subiquity/3698/usr/bin/python3.8', '-m', 'curtin', '--showtrace', '-vvv', '--set', 'json:reporting={"subiquity": {"type": "journald", "identifier": "curtin_event.1976.5"}}', 'system-install', '-t', '/target', '--', 'qemu-guest-agent']' returned non-zero exit status 100.
2022-09-04 07:21:31,875 INFO root:39 start: subiquity/ErrorReporter/1662276091.834314585.install_fail/add_info: 
2022-09-04 07:21:31,876 ERROR subiquity.server.server:416 top level error
Traceback (most recent call last):
  File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquity/server/controllers/cmdlist.py", line 104, in _run
    await Install.install_task
  File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquitycore/context.py", line 148, in decorated_async
    return await meth(self, **kw)
  File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquity/server/controllers/install.py", line 177, in install
    await self.postinstall(context=context)
  File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquitycore/context.py", line 148, in decorated_async
    return await meth(self, **kw)
  File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquity/server/controllers/install.py", line 200, in postinstall
    await self.install_package(context=context, package=package)
  File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquitycore/context.py", line 148, in decorated_async
    return await meth(self, **kw)
  File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquity/server/controllers/install.py", line 227, in install_package
    await run_curtin_command(
  File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquity/server/curtin.py", line 181, in run_curtin_command
    return await cmd.wait()
  File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquity/server/curtin.py", line 118, in wait
    result = await self.runner.wait(self.proc)
  File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquity/server/runner.py", line 81, in wait
    raise subprocess.CalledProcessError(proc.returncode, proc.args)
subprocess.CalledProcessError: Command '['systemd-run', '--wait', '--same-dir', '--property', 'SyslogIdentifier=subiquity_log.1976', '--setenv', 'PATH=/snap/subiquity/3698/bin:/snap/subiquity/3698/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/subiquity/3698/bin', '--setenv', 'PYTHONPATH=:/snap/subiquity/3698/lib/python3.8/site-packages', '--setenv', 'PYTHON=/snap/subiquity/3698/usr/bin/python3.8', '--setenv', 'SNAP=/snap/subiquity/3698', '--', '/snap/subiquity/3698/usr/bin/python3.8', '-m', 'curtin', '--showtrace', '-vvv', '--set', 'json:reporting={"subiquity": {"type": "journald", "identifier": "curtin_event.1976.5"}}', 'system-install', '-t', '/target', '--', 'qemu-guest-agent']' returned non-zero exit status 100.
2022-09-04 07:21:31,877 ERROR subiquity.server.server:416 top level error
Traceback (most recent call last):
  File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquity/server/controllers/shutdown.py", line 77, in _wait_install
    await self.app.controllers.Install.install_task
  File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquity/server/controllers/cmdlist.py", line 104, in _run
    await Install.install_task
  File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquitycore/context.py", line 148, in decorated_async
    return await meth(self, **kw)
  File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquity/server/controllers/install.py", line 177, in install
    await self.postinstall(context=context)
  File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquitycore/context.py", line 148, in decorated_async
    return await meth(self, **kw)
  File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquity/server/controllers/install.py", line 200, in postinstall
    await self.install_package(context=context, package=package)
  File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquitycore/context.py", line 148, in decorated_async
    return await meth(self, **kw)
  File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquity/server/controllers/install.py", line 227, in install_package
    await run_curtin_command(
  File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquity/server/curtin.py", line 181, in run_curtin_command
    return await cmd.wait()
  File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquity/server/curtin.py", line 118, in wait
    result = await self.runner.wait(self.proc)
  File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquity/server/runner.py", line 81, in wait
    raise subprocess.CalledProcessError(proc.returncode, proc.args)
subprocess.CalledProcessError: Command '['systemd-run', '--wait', '--same-dir', '--property', 'SyslogIdentifier=subiquity_log.1976', '--setenv', 'PATH=/snap/subiquity/3698/bin:/snap/subiquity/3698/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/subiquity/3698/bin', '--setenv', 'PYTHONPATH=:/snap/subiquity/3698/lib/python3.8/site-packages', '--setenv', 'PYTHON=/snap/subiquity/3698/usr/bin/python3.8', '--setenv', 'SNAP=/snap/subiquity/3698', '--', '/snap/subiquity/3698/usr/bin/python3.8', '-m', 'curtin', '--showtrace', '-vvv', '--set', 'json:reporting={"subiquity": {"type": "journald", "identifier": "curtin_event.1976.5"}}', 'system-install', '-t', '/target', '--', 'qemu-guest-agent']' returned non-zero exit status 100.
2022-09-04 07:21:32,072 ERROR root:39 finish: subiquity/Install/install/postinstall/install_qemu-guest-agent/cmd-system-install: FAIL: curtin command system-install
2022-09-04 07:21:32,594 INFO root:39 finish: subiquity/ErrorReporter/1662276091.834314585.install_fail/add_info: SUCCESS: written to /var/crash/1662276091.834314585.install_fail.crash
2022-09-04 07:21:32,596 INFO root:39 finish: subiquity/Meta/status_GET: SUCCESS: 200 {"state": "ERROR", "confirming_tty": "", "error": {"state": "DONE", "base": "...
2022-09-04 07:21:32,599 INFO aiohttp.access:233  [04/Sep/2022:07:21:30 +0000] "GET /meta/status?cur=%22POST_RUNNING%22 HTTP/1.1" 200 524 "-" "Python/3.8 aiohttp/3.6.2"

```

If I run the command from the failed logs manually:
`systemd-run --wait --same-dir --property SyslogIdentifier=subiquity_log.1976 --setenv PATH=/snap/subiquity/3698/bin:/snap/subiquity/3698/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/subiquity/3698/bin --setenv PYTHONPATH=:/snap/subiquity/3698/lib/python3.8/site-packages --setenv PYTHON=/snap/subiquity/3698/usr/bin/python3.8 --setenv SNAP=/snap/subiquity/3698 -- /snap/subiquity/3698/usr/bin/python3.8 -m curtin --showtrace -vvvvvv --set json:reporting='{"subiquity": {"type": "journald", "identifier": "curtin_event.1976.5"}}' system-install -t /target -- qemu-guest-agent`

I can see the following in syslog:

```
Sep  4 07:31:18 ubuntu-server systemd[1]: Started /snap/subiquity/3698/usr/bin/python3.8 -m curtin --showtrace -vvvvvv --set json:reporting={"subiquity": {"type": "journald", "identifier": "curtin_event.1976.5"}} system-install -t /target -- qemu-guest-agent.
Sep  4 07:31:19 ubuntu-server subiquity_log.1976[16331]: start: cmd-system-install: curtin command system-install
Sep  4 07:31:19 ubuntu-server curtin_event.1976.5[16331]: start: cmd-system-install: curtin command system-install
Sep  4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Running command ['mount', '--bind', '/dev', '/target/dev'] with allowed return codes [0] (capture=False)
Sep  4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Running command ['mount', '--bind', '/proc', '/target/proc'] with allowed return codes [0] (capture=False)
Sep  4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Running command ['mount', '--bind', '/run', '/target/run'] with allowed return codes [0] (capture=False)
Sep  4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Running command ['mount', '--bind', '/sys', '/target/sys'] with allowed return codes [0] (capture=False)
Sep  4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Running command ['unshare', '--help'] with allowed return codes [0] (capture=True)
Sep  4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Running command ['unshare', '--fork', '--pid', '--', 'chroot', '/target', 'eatmydata', 'apt-get', '--quiet', '--assume-yes', '--option=Dpkg::options::=--force-unsafe-io', '--option=Dpkg::Options::=--force-confold', 'install', 'qemu-guest-agent'] with allowed return codes [0] (capture=False)
Sep  4 07:31:19 ubuntu-server subiquity_log.1976[16342]: Reading package lists...
Sep  4 07:31:19 ubuntu-server subiquity_log.1976[16342]: Building dependency tree...
Sep  4 07:31:19 ubuntu-server subiquity_log.1976[16342]: Reading state information...
Sep  4 07:31:19 ubuntu-server subiquity_log.1976[16342]: E: Unable to locate package qemu-guest-agent
Sep  4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Running command ['udevadm', 'settle'] with allowed return codes [0] (capture=False)
Sep  4 07:31:19 ubuntu-server subiquity_log.1976[16331]: TIMED subp(['udevadm', 'settle']): 0.028
Sep  4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Running command ['mount', '--make-private', '/target/sys'] with allowed return codes [0] (capture=False)
Sep  4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Running command ['umount', '/target/sys'] with allowed return codes [0] (capture=False)
Sep  4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Running command ['mount', '--make-private', '/target/run'] with allowed return codes [0] (capture=False)
Sep  4 07:31:19 ubuntu-server systemd[1]: target-sys.mount: Deactivated successfully.
Sep  4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Running command ['umount', '/target/run'] with allowed return codes [0] (capture=False)
Sep  4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Running command ['mount', '--make-private', '/target/proc'] with allowed return codes [0] (capture=False)
Sep  4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Running command ['umount', '/target/proc'] with allowed return codes [0] (capture=False)
Sep  4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Running command ['mount', '--make-private', '/target/dev'] with allowed return codes [0] (capture=False)
Sep  4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Running command ['umount', '/target/dev'] with allowed return codes [0] (capture=False)
Sep  4 07:31:19 ubuntu-server subiquity_event.1976[1976]:       subiquity/Install/install/postinstall/install_qemu-guest-agent/cmd-system-install: curtin command system-install
Sep  4 07:31:19 ubuntu-server subiquity_log.1976[16331]: system install failed for ['qemu-guest-agent']: Unexpected error while running command.
Sep  4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Command: ['unshare', '--fork', '--pid', '--', 'chroot', '/target', 'eatmydata', 'apt-get', '--quiet', '--assume-yes', '--option=Dpkg::options::=--force-unsafe-io', '--option=Dpkg::Options::=--force-confold', 'install', 'qemu-guest-agent']
Sep  4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Exit code: 100
Sep  4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Reason: -
Sep  4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Stdout: ''
Sep  4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Stderr: ''
Sep  4 07:31:19 ubuntu-server subiquity_log.1976[16331]: finish: cmd-system-install: FAIL: curtin command system-install
Sep  4 07:31:19 ubuntu-server curtin_event.1976.5[16331]: finish: cmd-system-install: FAIL: curtin command system-install
Sep  4 07:31:19 ubuntu-server systemd[1]: run-u70.service: Main process exited, code=exited, status=100/n/a
Sep  4 07:31:19 ubuntu-server systemd[1]: run-u70.service: Failed with result 'exit-code'.
Sep  4 07:31:19 ubuntu-server systemd[1]: run-u70.service: Consumed 1.595s CPU time.
Sep  4 07:31:20 ubuntu-server subiquity_event.1976[1976]:       subiquity/Install/install/postinstall/install_qemu-guest-agent/cmd-system-install: curtin command system-install
Sep  4 07:31:20 ubuntu-server systemd[1]: target-run.mount: Deactivated successfully.
Sep  4 07:31:20 ubuntu-server systemd[1]: target-proc.mount: Deactivated successfully.
Sep  4 07:31:20 ubuntu-server systemd[1]: target-dev.mount: Deactivated successfully.

```

This same step/config is successful when ran on an autoinstall without renaming the NIC:

```
2022-09-01 23:11:45,679 DEBUG root:39 start: subiquity/Install/install/postinstall/install_qemu-guest-agent: installing qemu-guest-agent
2022-09-01 23:11:45,988 DEBUG subiquitycore.utils:112 astart_command called: ['systemd-run', '--wait', '--same-dir', '--property', 'SyslogIdentifier=subiquity_log.1972', '--setenv', 'PATH=/snap/subiquity/3698/bin:/snap/subiquity/3698/usr/bin:/usr/local/s
bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/subiquity/3698/bin', '--setenv', 'PYTHONPATH=:/snap/subiquity/3698/lib/python3.8/site-packages', '--setenv', 'PYTHON=/snap/subiquity/3698/usr/bin/python3.8', '--
setenv', 'SNAP=/snap/subiquity/3698', '--', '/snap/subiquity/3698/usr/bin/python3.8', '-m', 'curtin', '--showtrace', '-vvv', '--set', 'json:reporting={"subiquity": {"type": "journald", "identifier": "curtin_event.1972.5"}}', 'system-install', '-t', '/tar
get', '--', 'qemu-guest-agent']
2022-09-01 23:11:46,031 INFO root:39 start: subiquity/Meta/status_GET:
2022-09-01 23:11:47,706 DEBUG root:39 start: subiquity/Install/install/postinstall/install_qemu-guest-agent/cmd-system-install: curtin command system-install
2022-09-01 23:11:56,394 DEBUG subiquity.server.curtin:123 waited 0.1 seconds for events to drain
2022-09-01 23:11:56,458 DEBUG root:39 finish: subiquity/Install/install/postinstall/install_qemu-guest-agent/cmd-system-install: SUCCESS: curtin command system-install
2022-09-01 23:11:56,496 DEBUG subiquity.server.curtin:123 waited 0.2 seconds for events to drain
2022-09-01 23:11:56,497 DEBUG root:39 finish: subiquity/Install/install/postinstall/install_qemu-guest-agent: SUCCESS: installing qemu-guest-agent

```

At this point I'm not too sure why it states it's not able to locate the package after the NIC is renamed. I'm a bit stumped at this point because the VM does have full internet access after I'm presented the shell.

Any sort of help/troubleshooting steps are appreciated. Happy to provide any info I can.