mirror of
https://github.com/saltstack-formulas/postgres-formula.git
synced 2025-04-16 01:30:25 +00:00
Introduce osmajorreleasemap
for RedHat release specific commands
This commit is contained in:
parent
a6c4185b85
commit
c285f1006c
7 changed files with 122 additions and 75 deletions
|
@ -78,6 +78,7 @@ postgres:
|
||||||
# optional extensions to enable on database
|
# optional extensions to enable on database
|
||||||
# extensions:
|
# extensions:
|
||||||
# postgis:
|
# postgis:
|
||||||
|
|
||||||
# backup extension defaults to .bak if postgresconf_backup is True.
|
# backup extension defaults to .bak if postgresconf_backup is True.
|
||||||
# Set to False to stop creation of backup on postgresql.conf changes.
|
# Set to False to stop creation of backup on postgresql.conf changes.
|
||||||
postgresconf_backup: True
|
postgresconf_backup: True
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
{%- macro ubuntu_block(name, version) %}
|
{% macro ubuntu_block(name, version) %}
|
||||||
|
|
||||||
{%- if salt['pillar.get']('postgres:use_upstream_repo', False) %}
|
{% if salt['pillar.get']('postgres:use_upstream_repo', False) %}
|
||||||
|
{% set version = salt['pillar.get']('postgres:version', '9.5') %}
|
||||||
{%- set version = salt['pillar.get']('postgres:version', '9.5') %}
|
{% endif %}
|
||||||
|
|
||||||
{%- endif -%}
|
|
||||||
|
|
||||||
{{ name }}:
|
{{ name }}:
|
||||||
pkg_repo: deb http://apt.postgresql.org/pub/repos/apt/ {{ name }}-pgdg main
|
pkg_repo: deb http://apt.postgresql.org/pub/repos/apt/ {{ name }}-pgdg main
|
||||||
|
@ -17,16 +15,18 @@
|
||||||
user: root
|
user: root
|
||||||
env: {}
|
env: {}
|
||||||
|
|
||||||
{%- endmacro -%}
|
{% endmacro %}
|
||||||
|
|
||||||
|
# Debian GNU/Linux
|
||||||
{{ ubuntu_block('wheezy', 9.1) }}
|
{{ ubuntu_block('wheezy', 9.1) }}
|
||||||
|
|
||||||
{{ ubuntu_block('trusty', 9.3) }}
|
|
||||||
|
|
||||||
{{ ubuntu_block('precise', 9.4) }}
|
|
||||||
{{ ubuntu_block('jessie', 9.4) }}
|
{{ ubuntu_block('jessie', 9.4) }}
|
||||||
|
|
||||||
|
# Ubuntu
|
||||||
|
{{ ubuntu_block('trusty', 9.3) }}
|
||||||
|
{{ ubuntu_block('precise', 9.4) }}
|
||||||
{{ ubuntu_block('utopic', 9.4) }}
|
{{ ubuntu_block('utopic', 9.4) }}
|
||||||
{{ ubuntu_block('vivid', 9.4) }}
|
{{ ubuntu_block('vivid', 9.4) }}
|
||||||
{{ ubuntu_block('wily', 9.4) }}
|
{{ ubuntu_block('wily', 9.4) }}
|
||||||
|
|
||||||
{{ ubuntu_block('xenial', 9.5) }}
|
{{ ubuntu_block('xenial', 9.5) }}
|
||||||
|
|
||||||
|
# vim: ft=sls
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
# -*- mode: yaml -*-
|
# -*- mode: yaml -*-
|
||||||
|
|
||||||
{% from "postgres/map.jinja" import postgres with context %}
|
{%- from "postgres/map.jinja" import postgres with context %}
|
||||||
|
|
||||||
|
{%- if postgres.use_upstream_repo %}
|
||||||
|
|
||||||
{% if postgres.use_upstream_repo %}
|
|
||||||
include:
|
include:
|
||||||
- postgres.upstream
|
- postgres.upstream
|
||||||
{% endif %}
|
|
||||||
|
{%- endif %}
|
||||||
|
|
||||||
postgresql-installed:
|
postgresql-installed:
|
||||||
pkg.installed:
|
pkg.installed:
|
||||||
|
@ -15,17 +17,14 @@ postgresql-installed:
|
||||||
# make sure the data directory and contents have been initialized
|
# make sure the data directory and contents have been initialized
|
||||||
postgresql-cluster-prepared:
|
postgresql-cluster-prepared:
|
||||||
cmd.run:
|
cmd.run:
|
||||||
- cwd: /
|
|
||||||
- name: {{ postgres.prepare_cluster.command }}
|
- name: {{ postgres.prepare_cluster.command }}
|
||||||
- user: {{ postgres.prepare_cluster.user }}
|
- cwd: /
|
||||||
|
- runas: {{ postgres.prepare_cluster.user }}
|
||||||
|
- env: {{ postgres.prepare_cluster.env|default({}) }}
|
||||||
- unless:
|
- unless:
|
||||||
- {{ postgres.prepare_cluster.test }}
|
- {{ postgres.prepare_cluster.test }}
|
||||||
- require:
|
- require:
|
||||||
- pkg: postgresql-installed
|
- pkg: postgresql-installed
|
||||||
- env:
|
|
||||||
{% for name, value in postgres.prepare_cluster.env.items() %}
|
|
||||||
{{ name }}: {{ value }}
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
postgresql-config-dir:
|
postgresql-config-dir:
|
||||||
file.directory:
|
file.directory:
|
||||||
|
@ -34,23 +33,10 @@ postgresql-config-dir:
|
||||||
- group: {{ postgres.group }}
|
- group: {{ postgres.group }}
|
||||||
- makedirs: True
|
- makedirs: True
|
||||||
- require:
|
- require:
|
||||||
- pkg: postgresql-installed
|
|
||||||
- cmd: postgresql-cluster-prepared
|
- cmd: postgresql-cluster-prepared
|
||||||
|
|
||||||
postgresql-running:
|
{%- if postgres.postgresconf %}
|
||||||
service.running:
|
|
||||||
- enable: True
|
|
||||||
- reload: True
|
|
||||||
- name: {{ postgres.service }}
|
|
||||||
- reload: true
|
|
||||||
- require:
|
|
||||||
- cmd: postgresql-cluster-prepared
|
|
||||||
|
|
||||||
postgresql-extra-pkgs-installed:
|
|
||||||
pkg.installed:
|
|
||||||
- pkgs: {{ postgres.pkgs_extra|default([], True) }}
|
|
||||||
|
|
||||||
{% if postgres.postgresconf %}
|
|
||||||
postgresql-conf:
|
postgresql-conf:
|
||||||
file.blockreplace:
|
file.blockreplace:
|
||||||
- name: {{ postgres.conf_dir }}/postgresql.conf
|
- name: {{ postgres.conf_dir }}/postgresql.conf
|
||||||
|
@ -67,7 +53,8 @@ postgresql-conf:
|
||||||
- service: postgresql-running
|
- service: postgresql-running
|
||||||
- require:
|
- require:
|
||||||
- file: postgresql-config-dir
|
- file: postgresql-config-dir
|
||||||
{% endif %}
|
|
||||||
|
{%- endif %}
|
||||||
|
|
||||||
postgresql-pg_hba:
|
postgresql-pg_hba:
|
||||||
file.managed:
|
file.managed:
|
||||||
|
@ -79,8 +66,18 @@ postgresql-pg_hba:
|
||||||
- mode: 644
|
- mode: 644
|
||||||
- require:
|
- require:
|
||||||
- file: postgresql-config-dir
|
- file: postgresql-config-dir
|
||||||
- watch_in:
|
|
||||||
- service: postgresql-running
|
postgresql-running:
|
||||||
|
service.running:
|
||||||
|
- name: {{ postgres.service }}
|
||||||
|
- enable: True
|
||||||
|
- reload: True
|
||||||
|
- watch:
|
||||||
|
- file: postgresql-pg_hba
|
||||||
|
|
||||||
|
postgresql-extra-pkgs-installed:
|
||||||
|
pkg.installed:
|
||||||
|
- pkgs: {{ postgres.pkgs_extra|default([], True) }}
|
||||||
|
|
||||||
{% for name, user in postgres.users.items() %}
|
{% for name, user in postgres.users.items() %}
|
||||||
postgresql-user-{{ name }}:
|
postgresql-user-{{ name }}:
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
{% import_yaml "postgres/defaults.yaml" as defaults %}
|
{% import_yaml "postgres/defaults.yaml" as defaults %}
|
||||||
{% import_yaml "postgres/osmap.yaml" as osmap %}
|
{% import_yaml "postgres/osmap.yaml" as osmap %}
|
||||||
{% import_yaml "postgres/codenamemap.yaml" as oscodenamemap %}
|
{% import_yaml "postgres/codenamemap.yaml" as oscodenamemap %}
|
||||||
{% import_yaml "postgres/osfingermap.yaml" as osfingermap %}
|
{% import_yaml "postgres/osmajorreleasemap.yaml" as osmajorreleasemap %}
|
||||||
|
|
||||||
{% set _postgres = salt['grains.filter_by'](
|
{% set postgres = salt['grains.filter_by'](
|
||||||
osmap,
|
defaults,
|
||||||
grain='os_family',
|
|
||||||
merge=salt['grains.filter_by'](
|
merge=salt['grains.filter_by'](
|
||||||
oscodenamemap,
|
osmap,
|
||||||
grain='oscodename',
|
grain='os_family',
|
||||||
merge=salt['grains.filter_by'](
|
merge=salt['grains.filter_by'](
|
||||||
osfingermap,
|
oscodenamemap,
|
||||||
grain='osfinger',
|
grain='oscodename',
|
||||||
merge=salt['pillar.get']('postgres', {})
|
merge=salt['grains.filter_by'](
|
||||||
)
|
osmajorreleasemap,
|
||||||
)
|
grain='osmajorrelease',
|
||||||
|
merge=salt['pillar.get']('postgres', {}),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
base='postgres',
|
||||||
) %}
|
) %}
|
||||||
|
|
||||||
{% do defaults.postgres.update(_postgres) %}
|
|
||||||
|
|
||||||
{% set postgres = defaults.postgres %}
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
{}
|
|
64
postgres/osmajorreleasemap.yaml
Normal file
64
postgres/osmajorreleasemap.yaml
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
{% if grains['os_family'] == 'RedHat' %}
|
||||||
|
|
||||||
|
### RedHat releases
|
||||||
|
|
||||||
|
{% if salt['pillar.get']('postgres:use_upstream_repo', False) %}
|
||||||
|
{% set version = salt['pillar.get']('postgres:version', '9.5') %}
|
||||||
|
{% set data_dir = '/var/lib/pgsql/' ~ version ~ '/data' %}
|
||||||
|
|
||||||
|
# PostgreSQL from upstream repository
|
||||||
|
|
||||||
|
default:
|
||||||
|
prepare_cluster:
|
||||||
|
user: postgres
|
||||||
|
command: /usr/pgsql-{{ version }}/bin/initdb -D {{ data_dir }}
|
||||||
|
test: test -f {{ data_dir }}/PG_VERSION
|
||||||
|
env: {}
|
||||||
|
'6':
|
||||||
|
prepare_cluster:
|
||||||
|
user: root
|
||||||
|
command: service postgresql-{{ version }} initdb
|
||||||
|
test: test -f {{ data_dir }}/PG_VERSION
|
||||||
|
env: {}
|
||||||
|
'7':
|
||||||
|
prepare_cluster:
|
||||||
|
user: root
|
||||||
|
command: /usr/pgsql-{{ version }}/bin/postgresql95-setup initdb
|
||||||
|
test: test -f {{ data_dir }}/PG_VERSION
|
||||||
|
env: {}
|
||||||
|
|
||||||
|
{% else %}
|
||||||
|
{% set data_dir = '/var/lib/pgsql/data' %}
|
||||||
|
|
||||||
|
# PostgreSQL from OS repositories
|
||||||
|
|
||||||
|
default:
|
||||||
|
prepare_cluster:
|
||||||
|
user: postgres
|
||||||
|
command: initdb -D {{ data_dir }}
|
||||||
|
test: test -f {{ data_dir }}/PG_VERSION
|
||||||
|
env: {}
|
||||||
|
'6':
|
||||||
|
prepare_cluster:
|
||||||
|
user: root
|
||||||
|
command: service postgresql initdb
|
||||||
|
test: test -f {{ data_dir }}/PG_VERSION
|
||||||
|
env: {}
|
||||||
|
'7':
|
||||||
|
prepare_cluster:
|
||||||
|
user: root
|
||||||
|
command: postgresql-setup initdb
|
||||||
|
test: test -f {{ data_dir }}/PG_VERSION
|
||||||
|
env: {}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% else %}
|
||||||
|
|
||||||
|
### Empty YAML, no settings for other OS
|
||||||
|
|
||||||
|
{}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
# vim: ft=sls
|
|
@ -20,10 +20,9 @@ OpenBSD:
|
||||||
user: _postgresql
|
user: _postgresql
|
||||||
|
|
||||||
RedHat:
|
RedHat:
|
||||||
{%- if salt['pillar.get']('postgres:use_upstream_repo', False) %}
|
{% if salt['pillar.get']('postgres:use_upstream_repo', False) %}
|
||||||
|
{% set version = salt['pillar.get']('postgres:version', '9.5') %}
|
||||||
{%- set version = salt['pillar.get']('postgres:version', '9.5') %}
|
{% set release = version|replace('.', '') %}
|
||||||
{%- set release = version|replace('.', '') %}
|
|
||||||
|
|
||||||
version: {{ version }}
|
version: {{ version }}
|
||||||
pkg_repo: pgdg{{ release }}
|
pkg_repo: pgdg{{ release }}
|
||||||
|
@ -31,29 +30,16 @@ RedHat:
|
||||||
pkg_client: postgresql{{ release }}
|
pkg_client: postgresql{{ release }}
|
||||||
conf_dir: /var/lib/pgsql/{{ version }}/data
|
conf_dir: /var/lib/pgsql/{{ version }}/data
|
||||||
service: postgresql-{{ version }}
|
service: postgresql-{{ version }}
|
||||||
prepare_cluster:
|
|
||||||
user: postgres
|
|
||||||
command: /usr/pgsql-{{ version }}/bin/initdb -D /var/lib/pgsql/{{ version }}/data
|
|
||||||
test: test -f /var/lib/pgsql/{{ version }}/data/PG_VERSION
|
|
||||||
env: {}
|
|
||||||
|
|
||||||
{%- else %}
|
{% else %}
|
||||||
|
|
||||||
pkg: postgresql-server
|
pkg: postgresql-server
|
||||||
pkg_client: postgresql
|
pkg_client: postgresql
|
||||||
prepare_cluster:
|
|
||||||
{%- if grains['osmajorrelease'] >= 7 %}
|
|
||||||
user: root
|
|
||||||
command: postgresql-setup initdb
|
|
||||||
{%- else %}
|
|
||||||
user: postgres
|
|
||||||
command: initdb -D /var/lib/pgsql/data
|
|
||||||
{%- endif %}
|
|
||||||
test: test -f /var/lib/pgsql/data/PG_VERSION
|
|
||||||
env: {}
|
|
||||||
|
|
||||||
{%- endif %}
|
{% endif %}
|
||||||
|
|
||||||
Suse:
|
Suse:
|
||||||
pkg: postgresql-server
|
pkg: postgresql-server
|
||||||
pkg_client: postgresql
|
pkg_client: postgresql
|
||||||
|
|
||||||
|
# vim: ft=sls
|
||||||
|
|
Loading…
Add table
Reference in a new issue