Skip to content

allow setting state for postgresql_databases and postgresql_users #360

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

Merged
merged 2 commits into from
Feb 10, 2021
Merged
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ postgresql_databases:
uuid_ossp: yes # flag to install the uuid-ossp extension on this database (yes/no)
citext: yes # flag to install the citext extension on this database (yes/no)
encoding: "UTF-8" # override global {{ postgresql_encoding }} variable per database
state: "present" # optional; one of 'present', 'absent', 'dump', 'restore'
lc_collate: "en_GB.UTF-8" # override global {{ postgresql_locale }} variable per database
lc_ctype: "en_GB.UTF-8" # override global {{ postgresql_ctype }} variable per database

Expand All @@ -94,6 +95,7 @@ postgresql_users:
- name: baz
pass: pass
encrypted: yes # if password should be encrypted, postgresql >= 10 does only accepts encrypted passwords
state: "present" # optional; one of 'present', 'absent'

# List of schemas to be created (optional)
postgresql_database_schemas:
Expand Down
2 changes: 1 addition & 1 deletion tasks/databases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
lc_ctype: "{{ item.lc_ctype | default(postgresql_ctype) }}"
port: "{{postgresql_port}}"
template: "template0"
state: present
state: "{{ item.state | default('present') }}"
login_user: "{{postgresql_admin_user}}"
become: yes
become_user: "{{postgresql_admin_user}}"
Expand Down
2 changes: 1 addition & 1 deletion tasks/users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
password: "{{ item.pass | default(omit) }}"
encrypted: "{{ item.encrypted | default(omit) }}"
port: "{{postgresql_port}}"
state: present
state: "{{ item.state | default('present') }}"
login_user: "{{postgresql_admin_user}}"
no_log: true
become: yes
Expand Down
7 changes: 7 additions & 0 deletions tests/docker/group_vars/postgresql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ postgresql_databases:
- name: foobar
owner: baz

- name: qux
owner: baz
state: absent

# NOTE: postgresql >= 10 does not accept unencrypted passwords
postgresql_users:
- name: baz
Expand All @@ -17,6 +21,9 @@ postgresql_users:
pass: md51a1dc91c907325c69271ddf0c944bc72
encrypted: yes

- name: foo
state: absent

- name: zabaz

postgresql_database_schemas:
Expand Down
9 changes: 8 additions & 1 deletion tests/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ postgresql_databases:
- name: foobar
owner: baz

- name: qux
owner: baz
state: absent

postgresql_users:

# postgresql >=10 does not accept unencrypted passwords
# postgresql >=10 does not accept unencrypted passwords
- name: baz
pass: md51a1dc91c907325c69271ddf0c944bc72
encrypted: yes
Expand All @@ -17,6 +21,9 @@ postgresql_users:
pass: md51a1dc91c907325c69271ddf0c944bc72
encrypted: yes

- name: foo
state: absent

- name: zabaz

postgresql_user_privileges:
Expand Down