Skip to content

Commit

Permalink
Merge pull request #3 from antiplagiat/change-user-privileges-behaviour
Browse files Browse the repository at this point in the history
Able to set user role attributes while creating
  • Loading branch information
lazycoder-ru authored Aug 22, 2019
2 parents 090ed40 + 6e48c47 commit ee766aa
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ postgresql_database_schemas:
# List of user privileges to be applied (optional)
postgresql_user_privileges:
- name: baz # user name
db: foobar # database
priv: "ALL" # privilege string format: example: INSERT,UPDATE/table:SELECT/anothertable:ALL
role_attr_flags: "CREATEDB" # role attribute flags
schema: foobar # schema
objs: ALL_IN_SCHEMA # objects to be applied for
privs: "SELECT" # privileges
```
There's a lot more knobs and bolts to set, which you can find in the [defaults/main.yml](./defaults/main.yml)
Expand All @@ -112,6 +112,20 @@ There's a lot more knobs and bolts to set, which you can find in the [defaults/m
#### Fork additions
- Add pg_stat_statements variables, if pg_stat_statement in preload libraries;
- Add role_attr_flags to postgresql_users for create users with some attrs e.g. SUPERUSER;
- Add postgresql_all_databases_schema variable to create one schema in all databases from postgresql_databases;
- Updating user privileges now using postgresql_privs ansible module. Example:
```yaml
postgresql_user_privileges:
- name: readonly_user
type: schema
objs: dbo
privs: "USAGE"
- name: readonly_user
schema: dbo
objs: ALL_IN_SCHEMA
privs: "SELECT"
```
#### Testing
Expand Down
1 change: 1 addition & 0 deletions tasks/users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
port: "{{postgresql_port}}"
state: present
login_user: "{{postgresql_admin_user}}"
role_attr_flags: "{{ item.role_attr_flags | default(omit )}}"
no_log: true
become: yes
become_user: "{{postgresql_admin_user}}"
Expand Down
21 changes: 11 additions & 10 deletions tasks/users_privileges.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# file: postgresql/tasks/users_privileges.yml

- name: PostgreSQL | Update the user privileges
postgresql_user:
name: "{{item.name}}"
db: "{{item.db | default(omit)}}"
port: "{{postgresql_port}}"
priv: "{{item.priv | default(omit)}}"
postgresql_privs:
database: "{{item[0].name}}"
state: present
type: "{{item[1].type | default(omit)}}"
objs: "{{item[1].objs | default(omit)}}"
schema: "{{item[1].schema | default(omit)}}"
roles: "{{item[1].name}}"
privs: "{{item[1].privs}}"
port: "{{postgresql_port}}"
login_host: "{{item.host | default(omit)}}"
login_user: "{{postgresql_admin_user}}"
role_attr_flags: "{{item.role_attr_flags | default(omit)}}"
become: yes
become_user: "{{postgresql_admin_user}}"
with_items: "{{postgresql_user_privileges}}"
when: postgresql_users|length > 0
with_nested:
- "{{ postgresql_databases }}"
- "{{ postgresql_user_privileges }}"

0 comments on commit ee766aa

Please sign in to comment.