Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for postgresql_privs #134

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ postgresql_user_privileges:
db: foobar # database
priv: "ALL" # privilege string format: example: INSERT,UPDATE/table:SELECT/anothertable:ALL
role_attr_flags: "CREATEDB" # role attribute flags

# List of database privileges to be applied (optional)
postgresql_db_privileges:
- db: foobar # database
roles: baz # roles for grant or revoke privileges
objs: "ALL_IN_SCHEMA" # Comma separated list of database objects to set privileges on
grant: yes
```

There's a lot more knobs and bolts to set, which you can find in the defaults/main.yml
Expand Down
3 changes: 3 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ postgresql_users: []
# List of user privileges to be applied (optional)
postgresql_user_privileges: []

# List of database privileges to be applied (optional)
postgresql_db_priveleges: []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo

Suggested change
postgresql_db_priveleges: []
postgresql_db_privileges: []


# pg_hba.conf
postgresql_pg_hba_default:
- { type: local, database: all, user: '{{ postgresql_admin_user }}', address: '', method: '{{ postgresql_default_auth_method }}', comment: '' }
Expand Down
4 changes: 2 additions & 2 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
- include: databases.yml
tags: [postgresql, postgresql-databases]

- include: users_privileges.yml
tags: [postgresql, postgresql-users]
- include: privileges.yml
tags: [postgresql, postgresql-privileges]

- include: monit.yml
when: monit_protection is defined and monit_protection == true
Expand Down
37 changes: 37 additions & 0 deletions tasks/privileges.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# file: postgresql/tasks/privileges.yml

- name: PostgreSQL | Ensure PostgreSQL is running
service:
name: "{{ postgresql_service_name }}"
state: started

- name: PostgreSQL | Update the user privileges
postgresql_user:
name: "{{item.name}}"
db: "{{item.db | default(omit)}}"
port: "{{postgresql_port}}"
priv: "{{item.priv | default(omit)}}"
state: present
login_host: "{{item.host | default(omit)}}"
login_user: "{{postgresql_admin_user}}"
role_attr_flags: "{{item.role_attr_flags | default(omit)}}"
sudo: yes
sudo_user: "{{postgresql_admin_user}}"
with_items: postgresql_user_privileges

- name: PostgreSQL | Make sure the PostgreSQL privileges are present
postgresql_privs:
database: "{{ item.db }}"
grant_option: "{{ item.grant | default(no) }}"
host: "{{ item.host | default(\"127.0.0.1\") }}"
login: "{{ item.login | default(postgresql_admin_user) }}"
objs: "{{ item.objs | default(omit) }}"
password: "{{ item.password | default(\"\") }}"
privs: "{{ item.privs | default(\"ALL\") }}"
roles: "{{ item.roles | default(\"PUBLIC\") }}"
schema: "{{ item.schema | default(omit) }}"
state: "{{ item.state | default(\"present\") }}"
type: "{{ item.type | default(\"table\") }}"
sudo: yes
sudo_user: "{{postgresql_admin_user}}"
with_items: postgresql_db_priveleges
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo

Suggested change
with_items: postgresql_db_priveleges
with_items: postgresql_db_privileges

16 changes: 0 additions & 16 deletions tasks/users_privileges.yml

This file was deleted.

8 changes: 8 additions & 0 deletions tests/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,11 @@ postgresql_users:
postgresql_user_privileges:
- name: baz
db: foobar

postgresql_db_priveleges:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo

Suggested change
postgresql_db_priveleges:
postgresql_db_privileges:

- db: foobar
objs: "ALL_IN_SCHEMA"
schema: "public"
state: present
roles: baz
grant: yes