mirror of
https://github.com/saltstack-formulas/postgres-formula.git
synced 2025-04-16 09:40:26 +00:00
Merge pull request #232 from myii/PR_cluster
Allow configuration of cluster `name`, `locale` & `encoding`
This commit is contained in:
commit
332fe7b2b5
6 changed files with 31 additions and 7 deletions
|
@ -26,6 +26,13 @@ postgres:
|
|||
- postgresql-contrib
|
||||
- postgresql-plpython
|
||||
|
||||
# CLUSTER
|
||||
# The default `encoding` is derived from the `locale` so not recommended
|
||||
# to provide a value for it unless necessary
|
||||
cluster:
|
||||
locale: en_GB.UTF-8
|
||||
# encoding: UTF8
|
||||
|
||||
#'Alternatives system' priority incremental. 0 disables feature.
|
||||
linux:
|
||||
altpriority: 30
|
||||
|
|
|
@ -16,8 +16,9 @@
|
|||
{% else %}
|
||||
{% set fromrepo = name %}
|
||||
{% endif %}
|
||||
{% set conf_dir = '/etc/postgresql/' ~ version ~ '/main' %}
|
||||
{% set data_dir = '/var/lib/postgresql/' ~ version ~ '/main' %}
|
||||
{% set cluster_name = repo.cluster_name %}
|
||||
{% set conf_dir = '/etc/postgresql/{0}/{1}'.format(version, cluster_name) %}
|
||||
{% set data_dir = '/var/lib/postgresql/{0}/{1}'.format(version, cluster_name) %}
|
||||
|
||||
{{ codename|default(name, true) }}:
|
||||
# PostgreSQL packages are mostly downloaded from `main` repo component
|
||||
|
@ -25,11 +26,11 @@
|
|||
data_dir: {{ data_dir }}
|
||||
fromrepo: {{ fromrepo }}
|
||||
pkg_repo:
|
||||
name: 'deb http://apt.postgresql.org/pub/repos/apt/ {{ name }}-pgdg main'
|
||||
name: 'deb http://apt.postgresql.org/pub/repos/apt {{ name }}-pgdg main'
|
||||
pkg: postgresql-{{ version }}
|
||||
pkg_client: postgresql-client-{{ version }}
|
||||
prepare_cluster:
|
||||
pgcommand: pg_createcluster {{ version }} main -d
|
||||
pgcommand: pg_createcluster {{ version }} {{ cluster_name }} -d
|
||||
user: root
|
||||
|
||||
{% endmacro %}
|
||||
|
|
|
@ -21,6 +21,11 @@ postgres:
|
|||
user: postgres
|
||||
env: []
|
||||
|
||||
cluster:
|
||||
name: main # Debian-based only
|
||||
locale: '' # Defaults to `C`
|
||||
encoding: '' # Defaults to `SQL_ASCII` if `locale` not provided
|
||||
|
||||
conf_dir: /var/lib/pgsql/data
|
||||
data_dir: /var/lib/pgsql/data
|
||||
conf_dir_mode: '0700'
|
||||
|
|
|
@ -20,3 +20,13 @@
|
|||
),
|
||||
base='postgres',
|
||||
) %}
|
||||
|
||||
{# Concatenate the cluster preparation command and then append it to the `postgres` dict #}
|
||||
{% set pc_cmd = '{0} {1}'.format(postgres.prepare_cluster.pgcommand, postgres.data_dir) %}
|
||||
{% if postgres.cluster.locale %}
|
||||
{% set pc_cmd = '{0} --locale={1}'.format(pc_cmd, postgres.cluster.locale) %}
|
||||
{% endif %}
|
||||
{% if postgres.cluster.encoding %}
|
||||
{% set pc_cmd = '{0} --encoding={1}'.format(pc_cmd, postgres.cluster.encoding) %}
|
||||
{% endif %}
|
||||
{% do postgres.update({'prepare_cluster_cmd': pc_cmd}) %}
|
||||
|
|
|
@ -6,11 +6,12 @@
|
|||
use_upstream_repo: {{ salt['pillar.get']('postgres:use_upstream_repo', defaults.postgres.use_upstream_repo) }}
|
||||
version: {{ salt['pillar.get']('postgres:version', defaults.postgres.version) }}
|
||||
fromrepo: {{ salt['pillar.get']('postgres:fromrepo', defaults.postgres.fromrepo) }}
|
||||
cluster_name: {{ salt['pillar.get']('postgres:cluster:name', defaults.postgres.cluster.name) }}
|
||||
|
||||
#Early lookup for system user on MacOS
|
||||
{% if grains.os == 'MacOS' %}
|
||||
{% set sysuser = salt['pillar.get']('postgres.user', salt['cmd.run']("stat -f '%Su' /dev/console")) %}
|
||||
{% set sysgroup = salt['pillar.get']('postgres.group', salt['cmd.run']("stat -f '%Sg' /dev/console")) %}
|
||||
{% set sysuser = salt['pillar.get']('postgres:user', salt['cmd.run']("stat -f '%Su' /dev/console")) %}
|
||||
{% set sysgroup = salt['pillar.get']('postgres:group', salt['cmd.run']("stat -f '%Sg' /dev/console")) %}
|
||||
user: {{ sysuser }}
|
||||
group: {{ sysgroup }}
|
||||
{% endif %}
|
||||
|
|
|
@ -75,7 +75,7 @@ postgresql-cluster-prepared:
|
|||
- name: {{ postgres.prepare_cluster.command }}
|
||||
- unless: {{ postgres.prepare_cluster.test }}
|
||||
{%- else %}
|
||||
- name: {{ postgres.prepare_cluster.pgcommand }} {{ postgres.data_dir }}
|
||||
- name: {{ postgres.prepare_cluster_cmd }}
|
||||
- unless: test -f {{ postgres.data_dir }}/{{ postgres.prepare_cluster.pgtestfile }}
|
||||
{%- endif %}
|
||||
- cwd: /
|
||||
|
|
Loading…
Add table
Reference in a new issue