Skip to content

Commit

Permalink
Merge pull request #360 from mchitten/master
Browse files Browse the repository at this point in the history
allow setting state for postgresql_databases and postgresql_users
  • Loading branch information
gclough authored Feb 10, 2021
2 parents d8fc0d3 + 1d85e97 commit ffda21c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
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
7 changes: 7 additions & 0 deletions tests/vars.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

postgresql_users:

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

- name: foo
state: absent

- name: zabaz

postgresql_user_privileges:
Expand Down

0 comments on commit ffda21c

Please sign in to comment.