postgres: is not a valid data directory
OK, i figured it out:


initialise the db as user postgres

name: "Create a new PostgreSQL database cluster"
become: postgres
command: "/usr/pgsql-{{ postgres_version.major }}/bin/pg_ctl initdb --pgdata={{ postgres_data }}"
ignore_errors: yes

override PGDATA env variable through systemd

name: "Override PGDATA pathname (1/3)"
become: yes
file: path="/etc/systemd/system/postgresql-{{ postgres_version.major }}.service" state=touch owner=root group=root mode=0644
when: dev.platform == "baremetal"


name: "Override PGDATA pathname (2/3)"
become: yes
lineinfile: path="/etc/systemd/system/postgresql-{{ postgres_version.major }}.service" line=".include /lib/systemd/system/postgresql-{{ postgres_version.major }}.service" state=present
when: dev.platform == "baremetal"


name: "Override PGDATA pathname (3/3)"
become: yes
blockinfile:
  path: "/etc/systemd/system/postgresql-{{ postgres_version.major }}.service"
  state: present
  block: |
    [Service]
    Environment=PGDATA={{ postgres_data }}
  when: dev.platform == "baremetal"
  notify:
    reload-systemd