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

Manage object permissions using builtin postgresql_privs module #180

Closed
wants to merge 1 commit 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
3 changes: 3 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
- include: users_privileges.yml
tags: [postgresql, postgresql-users]

- include: privs.yml
tags: [postgresql, postgresql-users]

- include: monit.yml
when: monit_protection is defined and monit_protection == true
tags: [postgresql, postgresql-monit]
29 changes: 29 additions & 0 deletions tasks/privs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# file: postgresql/tasks/privs.yml

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

# Iterate over postgresql_privileges to grant and revoke privileges
# on objects using the built in module
# http://docs.ansible.com/ansible/postgresql_privs_module.html
- name: PostgreSQL | Update the privileges
postgresql_privs:
db: "{{item.db}}"
login_host: "{{item.host | default(omit)}}"
login_user: "{{postgresql_admin_user}}"
port: "{{postgresql_port}}"

grant_option: "{{item.grant_option | default(omit)}}"
objs: "{{item.objs | default(omit)}}"
privs: "{{item.privs | default(omit)}}"
roles: "{{item.roles}}"
schema: "{{item.schema | default(omit)}}"

state: "{{item.state | default(omit)}}"
type: "{{item.type | default(omit)}}"
become: yes
become_user: "{{postgresql_admin_user}}"
with_items: "{{postgresql_privileges}}"
when: "{{postgresql_privileges|length > 0}}"