Apt-get under apt-cacher-ng with a missing GPG public key

Here’s a common error to run into:


TASK [essential : Run the equivilent of apt-get update] **************************************************************
fatal: [ansibledest.local]: FAILED! => {“changed”: false, “msg”: “Failed to update apt cache: W:Updating from such a repository can’t be done securely, and is therefore disabled by default., W:See apt-secure(8) manpage for repository creation and user configuration details., W:GPG error: http://hostname.local:3142/raspbian.raspberrypi.org/raspbian bookworm InRelease: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY 9165938D90FDDD2E, E:The repository ‘http://hostname.local:3142/raspbian.raspberrypi.org/raspbian bookworm InRelease’ is not signed.”}

This can be solved by adding the following to your ansible playbooks:


– name: Add raspbian public signing key
apt_key:
keyserver: keyserver.ubuntu.com
id: 9165938D90FDDD2E
state: present

– name: Update apt cache
apt:
update_cache: yes