- name: Install prerequisite packages
  become: yes
  apt:
    name: ['acl', 'apt-transport-https', 'locales', 'python3-psycopg2']
    state: present
    update_cache: yes

- name: Ensure UTF-8 locale exists
  become: yes
  locale_gen:
    name: en_US.UTF-8
    state: present

- name: Import PostgreSQL repository key
  become: yes
  apt_key:
    url: "{{ postgres_apt_key_url }}"
    id: "{{ postgres_apt_key_id }}"
    state: present

- name: Register PostgreSQL repository
  become: yes
  apt_repository:
    repo: "{{ postgres_apt_repository_repo }}"
    state: present
    filename: pgdg

- name: Install postgres packages
  become: yes
  apt:
    name:
      - postgresql-{{ postgres_version }}
      - postgresql-contrib-{{ postgres_version }}
    state: present
    update_cache: yes
    cache_valid_time: 3600
