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 2 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 privileges to be applied (optional)
postgresql_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 privileges to be applied (optional)
postgresql_privileges: []
Copy link

Choose a reason for hiding this comment

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

as to avoid being misleading perhaps this should be postgresql_db_priveleges?


# pg_hba.conf
postgresql_pg_hba_default:
- { type: local, database: all, user: '{{ postgresql_admin_user }}', address: '', method: '{{ postgresql_default_auth_method }}', comment: '' }
Expand Down
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
Copy link

Choose a reason for hiding this comment

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

these two can be merged together into priveleges.yml...

tags: [postgresql, postgresql-users]

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

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

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

- 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_privileges
when: postgresql_privileges | length > 0
Copy link

Choose a reason for hiding this comment

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

I don't think this line is needed :)