mirror of
https://github.com/saltstack-formulas/postgres-formula.git
synced 2025-04-17 10:10:31 +00:00
- re-arrange cluster initialization to a set of variables in a dictionary
which control three things: 1. should we initialize? 2. if so, how? 3. what environment variables and user to use The approach taken is very similar to what the Apache formula uses, namely: a default dictionary which is over-ridden by: os-specific defaults, then os codename defaults, then os finger defaults, and finally user-specified pillar values - this also adds support for grains['osfinger']
This commit is contained in:
parent
783d78bde7
commit
0220b67a85
7 changed files with 78 additions and 60 deletions
|
@ -1,17 +1,19 @@
|
|||
postgres:
|
||||
pg_hba.conf: salt://postgres/pg_hba.conf
|
||||
commands:
|
||||
initdb: service postgresql initdb
|
||||
prepare_cluster:
|
||||
user: root
|
||||
command: service postgresql initdb
|
||||
test: test -f /path/to/some/file
|
||||
env:
|
||||
LC_ALL: C.UTF-8
|
||||
|
||||
use_upstream_repo: False
|
||||
|
||||
lookup:
|
||||
pkg: 'postgresql-9.3'
|
||||
pkg_client: 'postgresql-client-9.3'
|
||||
pkgs_extra:
|
||||
- postgresql-contrib
|
||||
- postgresql-plpython
|
||||
pg_hba: '/etc/postgresql/9.3/main/pg_hba.conf'
|
||||
pkg: 'postgresql-9.3'
|
||||
pkg_client: 'postgresql-client-9.3'
|
||||
pkgs_extra:
|
||||
- postgresql-contrib
|
||||
- postgresql-plpython
|
||||
|
||||
users:
|
||||
localUser:
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
{%- macro ubuntu_block(name, version) %}
|
||||
{{ name }}:
|
||||
version: {{ version }}
|
||||
pkg_repo: deb http://apt.postgresql.org/pub/repos/apt/ {{ name }}-pgdg main
|
||||
conf_dir: /etc/postgresql/{{ version }}/main
|
||||
data_dir: /var/lib/postgresql/{{ version }}/main
|
||||
prepare_cluster:
|
||||
command: pg_createcluster {{ version }} main
|
||||
test: test -f /var/lib/postgresql/{{ version }}/main/PG_VERSION && test -f /etc/postgresql/{{ version }}/main/postgresql.conf
|
||||
user: root
|
||||
env:
|
||||
LC_ALL: C.UTF-8
|
||||
{%- endmacro %}
|
||||
|
||||
{{ ubuntu_block('wheezy', 9.1) }}
|
||||
|
|
|
@ -7,8 +7,6 @@ postgres:
|
|||
python: python-psycopg2
|
||||
service: postgresql
|
||||
conf_dir: /var/lib/pgsql/data
|
||||
data_dir: /var/lib/pgsql/data
|
||||
version: 9.1
|
||||
use_upstream_repo: False
|
||||
users: {}
|
||||
acls: []
|
||||
|
@ -17,10 +15,17 @@ postgres:
|
|||
postgresconf_backup: True
|
||||
postgresconf: ""
|
||||
pg_hba.conf: salt://postgres/pg_hba.conf
|
||||
initdb: True
|
||||
initdb_user: root
|
||||
initdb_args: --data-checksum
|
||||
commands:
|
||||
initdb: service postgresql initdb
|
||||
user: postgres
|
||||
group: postgres
|
||||
# if prepare_cluster is over-ridden in any of:
|
||||
# - osmap.yaml
|
||||
# - oscodenamemap.yaml
|
||||
# - osfingermap.yaml
|
||||
# you will have to specify a complete dictionary.
|
||||
prepare_cluster:
|
||||
user: root
|
||||
command: service postgresql initdb
|
||||
test: test -f /var/lib/pgsql/data/PG_VERSION
|
||||
env:
|
||||
LC_ALL: C.UTF-8
|
||||
|
||||
|
|
|
@ -16,9 +16,7 @@ postgresql-config-dir:
|
|||
- makedirs: True
|
||||
- require:
|
||||
- pkg: postgresql-installed
|
||||
{% if postgres.conf_dir == postgres.data_dir %}
|
||||
- cmd: postgresql-cluster-prepared
|
||||
{% endif %}
|
||||
|
||||
postgresql-installed:
|
||||
pkg.installed:
|
||||
|
@ -28,20 +26,17 @@ postgresql-installed:
|
|||
# make sure the data directory and contents have been initialized
|
||||
postgresql-cluster-prepared:
|
||||
cmd.run:
|
||||
{% if postgres.initdb %}
|
||||
- name: {{ postgres.commands.initdb }} {{ postgres.initdb_args }} -D {{ postgres.data_dir }}
|
||||
{% elif grains.os_family == 'Debian' %}
|
||||
- name: pg_createcluster {{ postgres.version }} main
|
||||
{# else: TODO #}
|
||||
{% endif %}
|
||||
- cwd: /
|
||||
- user: {{ postgres.initdb_user }}
|
||||
- name: {{ postgres.prepare_cluster.command }}
|
||||
- user: {{ postgres.prepare_cluster.user }}
|
||||
- unless:
|
||||
- test -f {{ postgres.data_dir }}/PG_VERSION
|
||||
- {{ postgres.prepare_cluster.test }}
|
||||
- require:
|
||||
- pkg: postgresql-installed
|
||||
- env:
|
||||
LC_ALL: C.UTF-8
|
||||
{% for name, value in postgres.prepare_cluster.env.items() %}
|
||||
{{ name }}: {{ value }}
|
||||
{% endfor %}
|
||||
|
||||
postgresql-running:
|
||||
service.running:
|
||||
|
@ -154,8 +149,11 @@ postgresql-db-{{ name }}:
|
|||
- user: {{ db.get('runas', postgres.user) }}
|
||||
- require:
|
||||
- service: postgresql-running
|
||||
{% if db.get('user') %}
|
||||
- postgres_user: postgresql-user-{{ db.get('user') }}
|
||||
{% if db.get('tablespace') %}
|
||||
- postgres_tablespace: postgresql-tablespace-{{ name }}
|
||||
{% endif %}
|
||||
{% if db.get('owner') %}
|
||||
- postgres_user: postgresql-user-{{ db.get('owner') }}
|
||||
{% endif %}
|
||||
|
||||
{% if db.schemas is defined %}
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
{% import_yaml "postgres/defaults.yaml" as defaults %}
|
||||
{% import_yaml "postgres/osmap.yaml" as osmap %}
|
||||
{% import_yaml "postgres/codenamemap.yaml" as codemap %}
|
||||
{% import_yaml "postgres/codenamemap.yaml" as oscodenamemap %}
|
||||
{% import_yaml "postgres/osfingermap.yaml" as osfingermap %}
|
||||
|
||||
{# get the settings for the os_family grain #}
|
||||
{% set osfam = salt['grains.filter_by'](osmap, grain='os_family') or {} %}
|
||||
{# get the settings for the oscodename grain, os_family data will override
|
||||
oscodename data #}
|
||||
{% set oscode = salt['grains.filter_by'](codemap,
|
||||
grain='oscodename',
|
||||
merge=osfam) or {} %}
|
||||
{% set _postgres = salt['grains.filter_by'](
|
||||
osmap,
|
||||
grain='os_family',
|
||||
merge=salt['grains.filter_by'](
|
||||
oscodenamemap,
|
||||
grain='oscodename',
|
||||
merge=salt['grains.filter_by'](
|
||||
osfingermap,
|
||||
grain='osfinger',
|
||||
merge=salt['pillar.get']('postgres', {})
|
||||
)
|
||||
)
|
||||
) %}
|
||||
|
||||
{# merge the os family/codename specific data over the defaults #}
|
||||
{% do defaults.postgres.update(oscode) %}
|
||||
{% do defaults.postgres.update(_postgres) %}
|
||||
|
||||
{# merge the pillar:lookup dict into the defaults/os specific dict #}
|
||||
{% set lookup = salt['pillar.get']('postgres:lookup',
|
||||
default=defaults.postgres,
|
||||
merge=True) %}
|
||||
|
||||
{# merge the actual postgres pillar into the above combined dict #}
|
||||
{% set postgres = salt['pillar.get']('postgres', default=lookup, merge=True) %}
|
||||
{% set postgres = defaults.postgres %}
|
||||
|
|
1
postgres/osfingermap.yaml
Normal file
1
postgres/osfingermap.yaml
Normal file
|
@ -0,0 +1 @@
|
|||
{}
|
|
@ -1,29 +1,37 @@
|
|||
RedHat:
|
||||
initdb_user: postgres
|
||||
commands:
|
||||
initdb: initdb
|
||||
pkg: postgresql-server
|
||||
pkg_client: postgresql
|
||||
pkg_repo: pgdg94
|
||||
repo_baseurl: http://yum.postgresql.org/9.4/redhat/rhel-$releasever-$basearch
|
||||
prepare_cluster:
|
||||
test: test -f /var/lib/pgsql/data/PG_VERSION
|
||||
env:
|
||||
LC_ALL: C.UTF-8
|
||||
{% if grains['os_family'] == 'RedHat' %}
|
||||
{% if grains['osmajorrelease'] >= 7 %}
|
||||
PGSETUP_INITDB_OPTIONS:
|
||||
user: root
|
||||
command: postgresql-setup initdb
|
||||
{% else %}
|
||||
user: postgres
|
||||
command: initdb -D /var/lib/pgsql/data
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
Arch:
|
||||
conf_dir: /var/lib/postgres/data
|
||||
data_dir: /var/lib/postgres/data
|
||||
initdb_user: postgres
|
||||
initdb_args: --locale en_US.UTF8 -E UTF8
|
||||
commands:
|
||||
initdb: initdb
|
||||
prepare_cluster:
|
||||
user: postgres
|
||||
command: initdb -D /var/lib/postgresql/data
|
||||
test: test -f /var/lib/postgres/data/PG_VERSION
|
||||
env:
|
||||
LC_ALL: C.UTF-8
|
||||
pkg_client: postgresql
|
||||
pkg_dev: postgresql
|
||||
Debian:
|
||||
pkg_repo_file: /etc/apt/sources.list.d/pgdg.list
|
||||
pkg_dev: postgresql-server-dev-all
|
||||
pkg_libpq_dev: libpq-dev
|
||||
initdb: False
|
||||
Suse:
|
||||
initdb_user: postgres
|
||||
commands:
|
||||
initdb: initdb
|
||||
pkg: postgresql-server
|
||||
pkg_client: postgresql
|
||||
FreeBSD:
|
||||
|
|
Loading…
Add table
Reference in a new issue