mirror of
https://github.com/saltstack-formulas/postgres-formula.git
synced 2025-04-17 10:10:31 +00:00
Switch to new style map.jinja
Move this formula to the new style map.jinja. Still need to sort out RedHat handling, but it's not any worse than it was before (i.e. horribly broken)
This commit is contained in:
parent
98bb44df47
commit
967fa6504b
8 changed files with 81 additions and 83 deletions
|
@ -1,7 +1,7 @@
|
||||||
postgres:
|
postgres:
|
||||||
pg_hba.conf: salt://postgres/pg_hba.conf
|
pg_hba.conf: salt://postgres/pg_hba.conf
|
||||||
|
|
||||||
use_upstream_repo: True
|
use_upstream_repo: False
|
||||||
|
|
||||||
lookup:
|
lookup:
|
||||||
pkg: 'postgresql-9.3'
|
pkg: 'postgresql-9.3'
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{% from "postgres/map.jinja" import postgres with context %}
|
{% from "postgres/map.jinja" import postgres with context %}
|
||||||
|
|
||||||
{% if salt['pillar.get']('postgres:use_upstream_repo') %}
|
{% if postgres.use_upstream_repo %}
|
||||||
include:
|
include:
|
||||||
- postgres.upstream
|
- postgres.upstream
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -8,7 +8,7 @@ include:
|
||||||
install-postgresql-client:
|
install-postgresql-client:
|
||||||
pkg.installed:
|
pkg.installed:
|
||||||
- name: {{ postgres.pkg_client }}
|
- name: {{ postgres.pkg_client }}
|
||||||
- refresh: {{ salt['pillar.get']('postgres:use_upstream_repo', False) }}
|
- refresh: {{ postgres.use_upstream_repo }}
|
||||||
|
|
||||||
{% if postgres.pkg_libpq_dev != False %}
|
{% if postgres.pkg_libpq_dev != False %}
|
||||||
install-postgres-libpq-dev:
|
install-postgres-libpq-dev:
|
||||||
|
|
9
postgres/codenamemap.yaml
Normal file
9
postgres/codenamemap.yaml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
wheezy:
|
||||||
|
pkg_repo: deb http://apt.postgresql.org/pub/repos/apt/ wheezy-pgdg main
|
||||||
|
jessie:
|
||||||
|
version: 9.4
|
||||||
|
pkg_repo: deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main
|
||||||
|
trusty:
|
||||||
|
version: 9.3
|
||||||
|
utopic:
|
||||||
|
version: 9.4
|
18
postgres/defaults.yaml
Normal file
18
postgres/defaults.yaml
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
postgres:
|
||||||
|
pkg: postgresql
|
||||||
|
pkg_dev: postgresql-devel
|
||||||
|
pkg_libpq_dev: postgresql-libs
|
||||||
|
pkg_client: postgresql-client
|
||||||
|
pkg_contrib: postgresql-contrib
|
||||||
|
python: python-psycopg2
|
||||||
|
service: postgresql
|
||||||
|
conf_dir: /var/lib/pgsql/data
|
||||||
|
create_cluster: False
|
||||||
|
init_db: False
|
||||||
|
version: 9.1
|
||||||
|
use_upstream_repo: False
|
||||||
|
users: {}
|
||||||
|
acls: []
|
||||||
|
databases: {}
|
||||||
|
postgresconf: ""
|
||||||
|
pg_hba.conf: salt://postgres/pg_hba.conf
|
|
@ -1,6 +1,6 @@
|
||||||
{% from "postgres/map.jinja" import postgres with context %}
|
{% from "postgres/map.jinja" import postgres with context %}
|
||||||
|
|
||||||
{% if salt['pillar.get']('postgres:use_upstream_repo') %}
|
{% if postgres.use_upstream_repo %}
|
||||||
include:
|
include:
|
||||||
- postgres.upstream
|
- postgres.upstream
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -8,7 +8,7 @@ include:
|
||||||
install-postgresql:
|
install-postgresql:
|
||||||
pkg.installed:
|
pkg.installed:
|
||||||
- name: {{ postgres.pkg }}
|
- name: {{ postgres.pkg }}
|
||||||
- refresh: {{ salt['pillar.get']('postgres:use_upstream_repo', False) }}
|
- refresh: {{ postgres.use_upstream_repo }}
|
||||||
|
|
||||||
{% if postgres.create_cluster != False %}
|
{% if postgres.create_cluster != False %}
|
||||||
create-postgresql-cluster:
|
create-postgresql-cluster:
|
||||||
|
@ -57,25 +57,24 @@ install-postgres-contrib:
|
||||||
- name: {{ postgres.pkg_contrib }}
|
- name: {{ postgres.pkg_contrib }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if 'postgresconf' in pillar.get('postgres', {}) %}
|
{% if postgres.postgresconf %}
|
||||||
postgresql-conf:
|
postgresql-conf:
|
||||||
file.blockreplace:
|
file.blockreplace:
|
||||||
- name: {{ postgres.conf_dir }}/postgresql.conf
|
- name: {{ postgres.conf_dir }}/postgresql.conf
|
||||||
- marker_start: "# Managed by SaltStack: listen_addresses: please do not edit"
|
- marker_start: "# Managed by SaltStack: listen_addresses: please do not edit"
|
||||||
- marker_end: "# Managed by SaltStack: end of salt managed zone --"
|
- marker_end: "# Managed by SaltStack: end of salt managed zone --"
|
||||||
- content: |
|
- content: |
|
||||||
{{ salt['pillar.get']('postgres:postgresconf') | indent(8) }}
|
{{ postgres.postgresconf|indent(8) }}
|
||||||
- show_changes: True
|
- show_changes: True
|
||||||
- append_if_not_found: True
|
- append_if_not_found: True
|
||||||
- watch_in:
|
- watch_in:
|
||||||
- service: postgresql
|
- service: postgresql
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if 'pg_hba.conf' in pillar.get('postgres', {}) %}
|
|
||||||
pg_hba.conf:
|
pg_hba.conf:
|
||||||
file.managed:
|
file.managed:
|
||||||
- name: {{ postgres.conf_dir }}/pg_hba.conf
|
- name: {{ postgres.conf_dir }}/pg_hba.conf
|
||||||
- source: {{ salt['pillar.get']('postgres:pg_hba.conf', 'salt://postgres/pg_hba.conf') }}
|
- source: {{ postgres['pg_hba.conf'] }}
|
||||||
- template: jinja
|
- template: jinja
|
||||||
- user: postgres
|
- user: postgres
|
||||||
- group: postgres
|
- group: postgres
|
||||||
|
@ -84,37 +83,32 @@ pg_hba.conf:
|
||||||
- pkg: {{ postgres.pkg }}
|
- pkg: {{ postgres.pkg }}
|
||||||
- watch_in:
|
- watch_in:
|
||||||
- service: postgresql
|
- service: postgresql
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if 'users' in pillar.get('postgres', {}) %}
|
{% for name, user in postgres.users.items() %}
|
||||||
{% for name, user in salt['pillar.get']('postgres:users').items() %}
|
|
||||||
postgres-user-{{ name }}:
|
postgres-user-{{ name }}:
|
||||||
postgres_user.present:
|
postgres_user.present:
|
||||||
- name: {{ name }}
|
- name: {{ name }}
|
||||||
- createdb: {{ salt['pillar.get']('postgres:users:' + name + ':createdb', False) }}
|
- createdb: {{ user.get('createdb', False) }}
|
||||||
- password: {{ salt['pillar.get']('postgres:users:' + name + ':password', 'changethis') }}
|
- password: {{ user.get('password', 'changethis') }}
|
||||||
- runas: postgres
|
- user: {{ user.get('runas', 'postgres') }}
|
||||||
- require:
|
- require:
|
||||||
- service: {{ postgres.service }}
|
- service: {{ postgres.service }}
|
||||||
{% endfor%}
|
{% endfor%}
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if 'databases' in pillar.get('postgres', {}) %}
|
{% for name, db in postgres.databases.items() %}
|
||||||
{% for name, db in salt['pillar.get']('postgres:databases').items() %}
|
|
||||||
postgres-db-{{ name }}:
|
postgres-db-{{ name }}:
|
||||||
postgres_database.present:
|
postgres_database.present:
|
||||||
- name: {{ name }}
|
- name: {{ name }}
|
||||||
- encoding: {{ salt['pillar.get']('postgres:databases:'+ name +':encoding', 'UTF8') }}
|
- encoding: {{ db.get('encoding', 'UTF8') }}
|
||||||
- lc_ctype: {{ salt['pillar.get']('postgres:databases:'+ name +':lc_ctype', 'en_US.UTF8') }}
|
- lc_ctype: {{ db.get('lc_ctype', 'en_US.UTF8') }}
|
||||||
- lc_collate: {{ salt['pillar.get']('postgres:databases:'+ name +':lc_collate', 'en_US.UTF8') }}
|
- lc_collate: {{ db.get('lc_collate', 'en_US.UTF8') }}
|
||||||
- template: {{ salt['pillar.get']('postgres:databases:'+ name +':template', 'template0') }}
|
- template: {{ db.get('template', 'template0') }}
|
||||||
{% if salt['pillar.get']('postgres:databases:'+ name +':owner') %}
|
{% if db.get('owner') %}
|
||||||
- owner: {{ salt['pillar.get']('postgres:databases:'+ name +':owner') }}
|
- owner: {{ db.get('owner') }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
- runas: {{ salt['pillar.get']('postgres:databases:'+ name +':runas', 'postgres') }}
|
- user: {{ db.get('runas', 'postgres') }}
|
||||||
{% if salt['pillar.get']('postgres:databases:'+ name +':user') %}
|
{% if db.get('user') %}
|
||||||
- require:
|
- require:
|
||||||
- postgres_user: postgres-user-{{ salt['pillar.get']('postgres:databases:'+ name +':user') }}
|
- postgres_user: postgres-user-{{ db.get('user') }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor%}
|
{% endfor%}
|
||||||
{% endif %}
|
|
||||||
|
|
|
@ -1,54 +1,22 @@
|
||||||
{% set pg_version = salt['grains.filter_by']({
|
{% import_yaml "postgres/defaults.yaml" as defaults %}
|
||||||
'RedHat' : { 'id': '9.1' },
|
{% import_yaml "postgres/osmap.yaml" as osmap %}
|
||||||
'Arch' : { 'id': '9.1' },
|
{% import_yaml "postgres/codenamemap.yaml" as codemap %}
|
||||||
'Debian' : { 'id': '9.3' },
|
|
||||||
}, merge=salt['grains.filter_by']({
|
|
||||||
'14.04' : { 'id': '9.3' },
|
|
||||||
'14.10' : { 'id': '9.4' },
|
|
||||||
}, grain='lsb_distrib_release', merge=salt['grains.filter_by']({
|
|
||||||
'jessie' : { 'id': '9.4' },
|
|
||||||
'wheezy' : { 'id': '9.1' },
|
|
||||||
}, grain='lsb_distrib_codename', merge=salt['pillar.get']('postgres:lookup')))) %}
|
|
||||||
|
|
||||||
{% set postgres = salt['grains.filter_by']({
|
{# get the settings for the os_family grain #}
|
||||||
'RedHat': {
|
{% set osfam = salt['grains.filter_by'](osmap) or {} %}
|
||||||
'pkg' : 'postgresql-server',
|
{# get the settings for the oscodename grain, os_family data will override
|
||||||
'pkg_dev' : 'postgresql-devel',
|
oscodename data #}
|
||||||
'pkg_libpq_dev' : 'postgresql-libs',
|
{% set oscode = salt['grains.filter_by'](codemap,
|
||||||
'pkg_client' : 'postgresql-client',
|
grain='oscodename',
|
||||||
'python' : 'python-psycopg2',
|
merge=osfam) or {} %}
|
||||||
'service' : 'postgresql',
|
|
||||||
'conf_dir' : '/var/lib/pgsql/data',
|
{# merge the os family/codename specific data over the defaults #}
|
||||||
'create_cluster' : False,
|
{% do defaults.postgres.update(oscode) %}
|
||||||
'init_db' : True,
|
|
||||||
'version' : pg_version.id,
|
{# merge the pillar:lookup dict into the defaults/os specific dict #}
|
||||||
},
|
{% set lookup = salt['pillar.get']('postgres:lookup',
|
||||||
'Arch': {
|
default=defaults.postgres,
|
||||||
'pkg' : 'postgresql',
|
merge=True) %}
|
||||||
'pkg_dev' : 'postgresql-devel',
|
|
||||||
'pkg_libpq_dev' : 'postgresql-libs',
|
{# merge the actual postgres pillar into the above combined dict #}
|
||||||
'pkg_client' : 'postgresql-client',
|
{% set postgres = salt['pillar.get']('postgres', default=lookup, merge=True) %}
|
||||||
'python' : 'python-psycopg2',
|
|
||||||
'service' : 'postgresql',
|
|
||||||
'conf_dir' : '/var/lib/pgsql/data',
|
|
||||||
'create_cluster' : False,
|
|
||||||
'init_db' : True,
|
|
||||||
'version' : pg_version.id,
|
|
||||||
},
|
|
||||||
'Debian': {
|
|
||||||
'pkg' : 'postgresql-' + pg_version.id,
|
|
||||||
'pkg_dev' : 'postgresql-server-dev-' + pg_version.id,
|
|
||||||
'pkg_libpq_dev' : 'libpq-dev',
|
|
||||||
'pkg_client' : 'postgresql-client-'+ pg_version.id,
|
|
||||||
'pkg_contrib' : 'postgresql-contrib-' + pg_version.id,
|
|
||||||
'pkg_repo' : 'deb http://apt.postgresql.org/pub/repos/apt/ ' + grains['lsb_distrib_codename'] + '-pgdg main',
|
|
||||||
'pkg_repo_file' : '/etc/apt/sources.list.d/pgdg.list',
|
|
||||||
'python' : 'python-pygresql',
|
|
||||||
'service' : 'postgresql',
|
|
||||||
'pg_hba' : '/etc/postgresql/' + pg_version.id + '/main/pg_hba.conf',
|
|
||||||
'conf_dir' : '/etc/postgresql/' + pg_version.id + '/main',
|
|
||||||
'create_cluster' : False,
|
|
||||||
'init_db' : False,
|
|
||||||
'version' : pg_version.id,
|
|
||||||
},
|
|
||||||
}, merge=salt['pillar.get']('postgres:lookup')) %}
|
|
||||||
|
|
6
postgres/osmap.yaml
Normal file
6
postgres/osmap.yaml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
RedHat:
|
||||||
|
pkg_repo: pgdg94
|
||||||
|
repo_baseurl: http://yum.postgresql.org/9.4/redhat/rhel-$releasever-$basearch
|
||||||
|
Arch: {}
|
||||||
|
Debian:
|
||||||
|
pkg_repo_file: /etc/apt/sources.list.d/pgdg.list
|
|
@ -1,11 +1,14 @@
|
||||||
{% from "postgres/map.jinja" import postgres with context %}
|
{% from "postgres/map.jinja" import postgres with context %}
|
||||||
|
|
||||||
{% if grains['os'] == 'Ubuntu' %} # Other distro support should be added here
|
{% if grains['os_family'] == 'Debian' %}
|
||||||
install-postgresql-repo:
|
install-postgresql-repo:
|
||||||
pkgrepo.managed:
|
pkgrepo.managed:
|
||||||
- humanname: PostgreSQL Official Repository
|
- humanname: PostgreSQL Official Repository
|
||||||
- name: {{ postgres.pkg_repo }}
|
- name: {{ postgres.pkg_repo }} {{ postgres.version }}
|
||||||
- keyid: B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
|
- keyid: B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
|
||||||
- keyserver: keyserver.ubuntu.com
|
- keyserver: keyserver.ubuntu.com
|
||||||
- file: {{ postgres.pkg_repo_file }}
|
- file: {{ postgres.pkg_repo_file }}
|
||||||
|
- require_in:
|
||||||
|
- pkg: {{ postgres.pkg }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue