---

- name: Become postgres system user
  become: true
  become_user: postgres
  block:
    - name: Create postgres user
      community.postgresql.postgresql_user:
        name: grafana
        state: present

    - name: Create database
      community.postgresql.postgresql_db:
        name: grafana
        owner: grafana
        state: present

    - name: Grant database privileges
      community.postgresql.postgresql_privs:
        database: grafana
        privs: ALL
        state: present
        type: database
        roles: grafana
