I am creating postgres user using below code. and it is working fine.
- name: create database user
become_user: postgres
postgresql_user: db={{ db_name }} name=username password=userpassword priv=CONNECT encrypted=yes state=present
However i would like this user to give only readonly access. I want to grant only select operation on tables in public schema. I can do this using below queries
CREATE USER rouser WITH PASSWORD 'pass';
GRANT CONNECT ON DATABASE mydb TO rouser;
GRANT USAGE ON SCHEMA public TO rouser;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO rouser;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO rouser;
I am able to create such user using
- name: modify user role
become_user: postgres
postgresql_privs:
db: mydb
role: qarouser
objs: ALL_IN_SCHEMA
privs: SELECT
However when i create a new table using different user in the same db. this user do not have select access to such table created by different user, How can i fix this?
postgresql_usermodule you may also have a look into Community.Postgresql.