feat: add database owner

This commit is contained in:
Adrien Waksberg 2022-07-20 10:35:39 +02:00
parent 186894b7c1
commit 0c2cb81ea1
5 changed files with 31 additions and 25 deletions

View file

@ -11,6 +11,7 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)
### Added
- add database owner
- add variable postrgresql_primary
- add user attributes

View file

@ -45,6 +45,7 @@ Example:
| Name | Type | Required | Default | Comment |
|------------|------|----------|-----------|-----------------------------------------------------|
| name | str | yes | | the database name |
| owner | str | yes | | the owner's database name |
| encoding | str | no | UTF-8 | encoding to use |
| lc_collate | str | no | C.UTF-8 | lc_collate to use |
| lc_ctype | str | no | C.UTF-8 | lc_ctype to use |
@ -56,6 +57,7 @@ Example:
```
- name: test
owner: user
encoding: UTF-8
state: present
```

View file

@ -34,4 +34,4 @@ postgresql_config_default:
lc_time: C.UTF-8
default_text_search_config: pg_catalog.english
include_dir: conf.d
postgresql_config_full: '{{ postgresql_config_default|combine(postgresql_config) }}'
postgresql_config_full: '{{ postgresql_config_default | combine(postgresql_config) }}'

View file

@ -17,7 +17,9 @@
method: md5
postgresql_databases:
- name: myappli
owner: test
- name: myappli2
owner: test
postgresql_users:
test:
password: secret

View file

@ -40,29 +40,30 @@
port: 5432
tags: postgresql
- name: manage databases
community.general.postgresql_db:
name: '{{ item.name }}'
encoding: '{{ item.encoding|default("UTF-8") }}'
state: '{{ item.state|default("present") }}'
lc_collate: '{{ item.lc_collate|default("C.UTF-8") }}'
lc_ctype: '{{ item.lc_ctype|default("C.UTF-8") }}'
template: '{{ item.template|default("template0") }}'
loop: '{{ postgresql_databases }}'
- name: manage users
community.general.postgresql_user:
name: '{{ item.key }}'
password: '{{ item.value.password }}'
role_attr_flags: '{{ item.value.attributes | default([]) | join(",") }}'
state: '{{ item.value.state | default("present") }}'
loop: '{{ postgresql_users | dict2items }}'
loop_control:
label: '{{ item.key }}'
become: true
become_user: postgres
when: postgresql_primary
tags: postgresql
- name: manage users
community.general.postgresql_user:
name: '{{ item.key }}'
password: '{{ item.value.password }}'
role_attr_flags: '{{ item.value.attributes|default([])|join(",") }}'
state: '{{ item.value.state|default("present") }}'
loop: '{{ postgresql_users|dict2items }}'
loop_control:
label: '{{ item.key }}'
- name: manage databases
community.general.postgresql_db:
name: '{{ item.name }}'
encoding: '{{ item.encoding | default("UTF-8") }}'
state: '{{ item.state | default("present") }}'
lc_collate: '{{ item.lc_collate | default("C.UTF-8") }}'
lc_ctype: '{{ item.lc_ctype | default("C.UTF-8") }}'
template: '{{ item.template | default("template0") }}'
owner: '{{ item.owner }}'
loop: '{{ postgresql_databases }}'
become: true
become_user: postgres
when: postgresql_primary
@ -72,10 +73,10 @@
community.postgresql.postgresql_privs:
db: '{{ item.database }}'
roles: '{{ item.role }}'
type: '{{ item.type|default("table") }}'
objs: '{{ item.objets|default(["ALL_IN_SCHEMA"])|join(",") }}'
privs: '{{ item.privileges|join(",") }}'
state: '{{ item.state|default("present") }}'
type: '{{ item.type | default("table") }}'
objs: '{{ item.objets | default(["ALL_IN_SCHEMA"]) | join(",") }}'
privs: '{{ item.privileges | join(",") }}'
state: '{{ item.state | default("present") }}'
loop: '{{ postgresql_privileges }}'
loop_control:
label: '{{ item.role }}/{{ item.database }}'
@ -88,8 +89,8 @@
community.postgresql.postgresql_membership:
groups: '{{ item.key }}'
target_roles: '{{ item.value.roles }}'
state: '{{ item.value.state|default("present") }}'
loop: '{{ postgresql_role_memberships|dict2items }}'
state: '{{ item.value.state | default("present") }}'
loop: '{{ postgresql_role_memberships | dict2items }}'
loop_control:
label: '{{ item.key }}'
become: true