The third field of an apt repository in the list file should be the codename of your distribution, not the distribution itself:
The sources.list man page specifies this package source format:
deb uri distribution [component1] [component2] [...]
and gives an example:
deb https://deb.debian.org/debian stable main contrib non-free
The distribution part (stable in this case) specifies a subdirectory in $ARCHIVE_ROOT/dists. It can contain additional slashes to specify subdirectories nested deeper, eg. stable/updates. distribution typically corresponds to Suite or Codename specified in the Release files.
Source: https://wiki.debian.org/DebianRepository/Format#Overview
Example of the Release file, containing the codename:
$ head -n 5 /etc/os-release
PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
If you don't want to hardcode it, this can be easily achieved with the help of Ansible facts:
- name: Add Postgres repo to sources list
apt_repository:
repo: >-
deb http://apt.postgresql.org/pub/repos/apt/
{{ ansible_distribution_release }}-pgdg main
state: present
become: true
Which presuppose that you, at least, gather the minimal facts, e.g.:
- hosts: localhost
gather_subset:
- min
Or that you gather everything, i.e.: that you have no gather_facts: false, at the play level.
ubuntu-pgdg. Shouldn't it be something like{{ YOUR_DISTRO }}-pgdg?jammy-pgdg?