apt-repository adds wrong repo for ppa

Hello Community,

I’m working on Ubuntu 22.04 where apt-key is deprecated, with ansible ansible [core 2.13.4]

After adding “ppa:ondrej/php” via “apt_repository” module and then execute “apt update” it throw the following error:
W: http://ppa.launchpad.net/ondrej/php/ubuntu/dists/jammy/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.

When adding the repo on the server via “add-apt-repository -y ppa:ondrej/php” it adds the correct repo and no error occurs

That’s what ansible runs

  • name: add php ppa
    apt_repository:
    repo: ppa:ondrej/php
    update_cache: yes

Any ideas?

Thank you

Are you sure it is really not working?
Looks like it’s only emitting a deprecation warning

Yes, you’re right, but the deprecation warning is the problem. And this only occurs when the repo is added via Ansible, if it is added via a simple “add-apt-repository” command then this warning does not come.
The real problem is that ansible breaks off with an error message when you “apt update”, because this deprecation warning comes up

The better place to report this is in the ansible apt module’s git repo as an issue so it can be addressed. The apt-key module itself says to refer to the Debian wiki where they recommend managing key files directly in the trusted.gpg.d directory.

https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/apt_key.py

The apt-key command has been deprecated and suggests to ‘manage keyring files in trusted.gpg.d instead’. See the Debian wiki for details. This module is kept for backwards compatiblity for systems that still use apt-key as the main way to manage apt repository keys.

Walter

We updated apt_repository to prefer the new standards, it still falls
back to the other directories and/or apt-key as needed
https://github.com/ansible/ansible/pull/78735

I'm considering reworking the module and/or just creating a role that
does this properly for all possible environments.