Score:0

how to give permissions to postgres_exporter user with ansible?

ru flag

I need to give some rights to my user postgres_exporter to scrape metrics from postgres to grafana

I can do that on each server by

sudo -iu postgres psql -c 'GRANT pg_read_all_settings TO postgres_exporter;'
sudo -iu postgres psql -c  'GRANT EXECUTE ON FUNCTION pg_ls_logdir() TO postgres_exporter;'
sudo -iu postgres psql -c  'GRANT EXECUTE ON FUNCTION pg_ls_waldir() TO postgres_exporter;'
sudo -iu postgres psql -c 'GRANT CREATE ON TABLESPACE pg_global TO postgres_exporter;'

But i want to use ansible for that, but without module postgresql_query, because its not supporting check diff mode

How to add user to default roles such as pg_read_all_settings, without creating a user?

For the last three commands i did, but im not sure about that.

- name: GRANT EXECUTE ON FUNCTION pg_ls_logdir() TO postgres_exporter
  community.postgresql.postgresql_privs:
    db: "{{ db_name }}"
    port: "{{ pg_port }}"
    privs: EXECUTE
    type: function
    obj: pg_ls_logdir()
    roles: "{{ postgres_exporter_user }}"

- name: GRANT EXECUTE ON FUNCTION pg_ls_waldir() TO postgres_exporter
  community.postgresql.postgresql_privs:
    db: "{{ db_name }}"
    port: "{{ pg_port }}"
    privs: EXECUTE
    type: function
    obj: pg_ls_waldir()
    roles: "{{ postgres_exporter_user }}"

- name: GRANT CREATE ON TABLESPACE pg_global TO postgres_exporter
  community.postgresql.postgresql_privs:
    db: "{{ db_name }}"
    port: "{{ pg_port }}"
    privs: CREATE
    type: tablespace
    objs: pg_global
    roles: "{{ postgres_exporter_user }}"
Sergei Cherevko avatar
ru flag
I think i can use only **pg_monitor** role instead first 3 commands
Score:0
ru flag

role pg_monitor resolve all problems with scraping metrics

- name: Grant role pg_monitor to postgres_exporter user
  become: true
  become_user: postgres
  community.postgresql.postgresql_membership:
    group: pg_monitor
    target_roles: "{{ postgres_exporter_user }}"
    state: present
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.