From 4a00acf26a70de6788ab5a9b9bc8871f6dc1f6fb Mon Sep 17 00:00:00 2001 From: Gilles Dartiguelongue Date: Mon, 6 Jun 2016 14:28:31 +0200 Subject: [PATCH] Split postgresql-cluster-prepared in two states, refs: #100 Previous write up lead the two pillar settings overwriting each other in the same state. We can now properly select whether to create a cluster and/or initialize a new database. Also the commands will not fail if both settings are false as found on Debian family OSes as this is taken care of by the packaging system for main cluster. --- postgres/init.sls | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/postgres/init.sls b/postgres/init.sls index 2dfe606..b0d1347 100644 --- a/postgres/init.sls +++ b/postgres/init.sls @@ -32,17 +32,30 @@ postgresql-cluster-prepared: {% if postgres.create_cluster != False %} - user: root - name: pg_createcluster {{ postgres.version }} main +{% else %} + - name: test -f {{ postgres.conf_dir }}/environment +{% endif %} - unless: - test -f {{ postgres.conf_dir }}/environment -{% endif %} + - require: + - pkg: postgresql-installed + - env: + LC_ALL: C.UTF-8 + +postgresql-db-prepared: + cmd.run: {% if postgres.init_db != False %} - user: {{ postgres.initdb_user }} - name: {{ postgres.commands.initdb }} {{ postgres.initdb_args }} -D {{ postgres.data_dir }} + +{% else %} + - name: test -f {{ postgres.data_dir }}/PG_VERSION +{% endif %} - unless: - test -f {{ postgres.data_dir }}/PG_VERSION -{% endif %} - require: - pkg: postgresql-installed + - cmd: postgresql-cluster-prepared - env: LC_ALL: C.UTF-8 @@ -54,6 +67,7 @@ postgresql-running: - reload: true - require: - cmd: postgresql-cluster-prepared + - cmd: postgresql-db-prepared {% if postgres.pkgs_extra %} postgresql-extra-pkgs-installed: