From d7580104f63c5e5d4f72084c7549646d0e04758a Mon Sep 17 00:00:00 2001 From: Edvinas Klovas Date: Thu, 23 Jul 2015 17:51:24 +0300 Subject: [PATCH] Add support for database extensions. This commit adds support for database extensions via salt.states.postgres_extension When configuring database pillar data all you need to do is add (optional) extension list with the extensions that you want the state to apply to specific database. Example: db1: owner: 'localUser' user: 'localUser' template: 'template0' lc_ctype: 'C.UTF-8' lc_collate: 'C.UTF-8' extensions: - uuid-ossp This will make sure `uuid-ossp` extension is enabled on `db1` database. Updated pillar.example to include (optional) extensions --- pillar.example | 8 ++++++-- postgres/init.sls | 10 ++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/pillar.example b/pillar.example index c714bb0..d817ad2 100644 --- a/pillar.example +++ b/pillar.example @@ -38,14 +38,18 @@ postgres: template: 'template0' lc_ctype: 'C.UTF-8' lc_collate: 'C.UTF-8' - + # optional extensions to enable on database + extensions: + - uuid-ossp db2: owner: 'localUser' user: 'remoteUser' template: 'template0' lc_ctype: 'C.UTF-8' lc_collate: 'C.UTF-8' - + # optional extensions to enable on database + extensions: + - postgis # This section will append your configuration to postgresql.conf. postgresconf: | listen_addresses = 'localhost,*' diff --git a/postgres/init.sls b/postgres/init.sls index 07fb35b..a8c02ef 100644 --- a/postgres/init.sls +++ b/postgres/init.sls @@ -103,6 +103,16 @@ postgres-db-{{ name }}: - require: - postgres_user: postgres-user-{{ db.get('user') }} {% endif %} + +{% if db.extensions is defined %} +{% for ext in db.extensions %} +postgres-ext-{{ ext }}-for-db-{{ name }}: + postgres_extension.present: + - name: {{ ext }} + - user: {{ db.get('runas', 'postgres') }} + - maintenance_db: {{ name }} +{% endfor %} +{% endif %} {% endfor%} {% for name, directory in postgres.tablespaces.items() %}