---
- name: Install Prometheus postgres-exporter
  apt:
    update_cache: true
    name: prometheus-postgres-exporter
  register: apt_result
  retries: 3
  until: apt_result is succeeded

- name: Make Prometheus postgres-exporter listen on adm only
  lineinfile:
    path: /etc/default/prometheus-postgres-exporter
    regexp: ^ARGS=
    line: |
      ARGS="--web.listen-address={{ prometheus_postgres_exporter.listen_addr }}:9187"
  notify: Restart prometheus-postgres-exporter

# You need to create the prometheus account, RTFM.
- name: Configure PostgreSQL connection
  lineinfile:
    path: /etc/default/prometheus-postgres-exporter
    regexp: ^DATA_SOURCE_NAME=
    line: DATA_SOURCE_NAME='user=prometheus host=/run/postgresql dbname=postgres'
  notify: Restart prometheus-postgres-exporter