From 8d355b9517a0dedd74759e779a9ded6ec8bbb826 Mon Sep 17 00:00:00 2001 From: Mike Chittenden Date: Mon, 21 May 2018 17:26:59 -0400 Subject: [PATCH] allow setting state for postgresql_databases and postgresql_users --- README.md | 2 ++ tasks/databases.yml | 2 +- tasks/users.yml | 2 +- tests/docker/group_vars/postgresql.yml | 7 +++++++ tests/vars.yml | 11 +++++++++-- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a19a3d1c..87eabdd8 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,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 @@ -83,6 +84,7 @@ postgresql_users: - name: baz pass: pass encrypted: no # denotes if the password is already encrypted. + state: "present" # optional; one of 'present', 'absent' # List of schemas to be created (optional) postgresql_schemas: diff --git a/tasks/databases.yml b/tasks/databases.yml index 8e412236..f1459b8f 100644 --- a/tasks/databases.yml +++ b/tasks/databases.yml @@ -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}}" diff --git a/tasks/users.yml b/tasks/users.yml index 12e2c9f2..dafe16cb 100644 --- a/tasks/users.yml +++ b/tasks/users.yml @@ -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 diff --git a/tests/docker/group_vars/postgresql.yml b/tests/docker/group_vars/postgresql.yml index 2949e5cb..d623c72c 100644 --- a/tests/docker/group_vars/postgresql.yml +++ b/tests/docker/group_vars/postgresql.yml @@ -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 @@ -17,6 +21,9 @@ postgresql_users: pass: md51a1dc91c907325c69271ddf0c944bc72 encrypted: yes + - name: foo + state: absent + - name: zabaz postgresql_database_schemas: diff --git a/tests/vars.yml b/tests/vars.yml index c3163964..171b58d8 100644 --- a/tests/vars.yml +++ b/tests/vars.yml @@ -1,14 +1,18 @@ --- -postgresql_version: 10 +postgresql_version: 10 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 @@ -18,6 +22,9 @@ postgresql_users: pass: md51a1dc91c907325c69271ddf0c944bc72 encrypted: yes + - name: foo + state: absent + - name: zabaz postgresql_user_privileges: