2016-09-03 15:15:56 +03:00
|
|
|
# -*- mode: yaml -*-
|
2016-06-05 12:55:00 +01:00
|
|
|
|
2016-09-06 12:34:17 +03:00
|
|
|
{%- from "postgres/map.jinja" import postgres with context -%}
|
2016-09-09 11:36:26 +03:00
|
|
|
{%- from "postgres/macros.jinja" import format_state with context -%}
|
2016-09-05 13:49:33 +03:00
|
|
|
|
|
|
|
{%- if postgres.use_upstream_repo %}
|
2014-01-26 04:06:22 +00:00
|
|
|
|
2015-04-21 15:13:42 -07:00
|
|
|
include:
|
|
|
|
- postgres.upstream
|
2016-09-05 13:49:33 +03:00
|
|
|
|
|
|
|
{%- endif %}
|
2015-02-01 14:40:45 +00:00
|
|
|
|
2016-09-09 11:36:26 +03:00
|
|
|
### Installation states
|
|
|
|
|
2016-05-25 12:12:48 -04:00
|
|
|
postgresql-installed:
|
2014-10-01 16:55:01 +02:00
|
|
|
pkg.installed:
|
2014-01-26 04:06:22 +00:00
|
|
|
- name: {{ postgres.pkg }}
|
2015-04-22 17:47:02 -05:00
|
|
|
- refresh: {{ postgres.use_upstream_repo }}
|
2014-07-27 22:04:57 -04:00
|
|
|
|
2016-05-25 12:12:48 -04:00
|
|
|
# make sure the data directory and contents have been initialized
|
|
|
|
postgresql-cluster-prepared:
|
2014-10-01 16:55:01 +02:00
|
|
|
cmd.run:
|
2016-07-08 15:34:45 -05:00
|
|
|
- name: {{ postgres.prepare_cluster.command }}
|
2016-09-05 13:49:33 +03:00
|
|
|
- cwd: /
|
|
|
|
- runas: {{ postgres.prepare_cluster.user }}
|
|
|
|
- env: {{ postgres.prepare_cluster.env|default({}) }}
|
2016-05-25 12:12:48 -04:00
|
|
|
- unless:
|
2016-07-08 15:34:45 -05:00
|
|
|
- {{ postgres.prepare_cluster.test }}
|
2016-05-25 12:12:48 -04:00
|
|
|
- require:
|
|
|
|
- pkg: postgresql-installed
|
2014-10-06 10:14:34 +02:00
|
|
|
|
2016-09-03 15:15:56 +03:00
|
|
|
postgresql-config-dir:
|
|
|
|
file.directory:
|
|
|
|
- name: {{ postgres.conf_dir }}
|
|
|
|
- user: {{ postgres.user }}
|
|
|
|
- group: {{ postgres.group }}
|
|
|
|
- makedirs: True
|
|
|
|
- require:
|
|
|
|
- cmd: postgresql-cluster-prepared
|
|
|
|
|
2016-09-05 13:49:33 +03:00
|
|
|
{%- if postgres.postgresconf %}
|
2015-02-14 17:30:12 +00:00
|
|
|
|
2014-10-06 11:34:43 +02:00
|
|
|
postgresql-conf:
|
|
|
|
file.blockreplace:
|
|
|
|
- name: {{ postgres.conf_dir }}/postgresql.conf
|
|
|
|
- marker_start: "# Managed by SaltStack: listen_addresses: please do not edit"
|
|
|
|
- marker_end: "# Managed by SaltStack: end of salt managed zone --"
|
2015-03-12 16:14:34 -07:00
|
|
|
- content: |
|
2015-04-22 17:47:02 -05:00
|
|
|
{{ postgres.postgresconf|indent(8) }}
|
2014-10-06 11:34:43 +02:00
|
|
|
- show_changes: True
|
|
|
|
- append_if_not_found: True
|
2016-09-06 12:34:17 +03:00
|
|
|
- backup: {{ postgres.postgresconf_backup }}
|
2014-10-06 11:34:43 +02:00
|
|
|
- watch_in:
|
2016-05-25 12:12:48 -04:00
|
|
|
- service: postgresql-running
|
|
|
|
- require:
|
|
|
|
- file: postgresql-config-dir
|
2016-09-05 13:49:33 +03:00
|
|
|
|
|
|
|
{%- endif %}
|
2014-10-06 11:34:43 +02:00
|
|
|
|
2016-05-25 12:12:48 -04:00
|
|
|
postgresql-pg_hba:
|
2014-05-15 14:44:39 -07:00
|
|
|
file.managed:
|
2014-10-01 16:55:01 +02:00
|
|
|
- name: {{ postgres.conf_dir }}/pg_hba.conf
|
2015-04-22 17:47:02 -05:00
|
|
|
- source: {{ postgres['pg_hba.conf'] }}
|
2014-05-15 15:31:42 -07:00
|
|
|
- template: jinja
|
2016-05-23 12:19:32 -05:00
|
|
|
- user: {{ postgres.user }}
|
|
|
|
- group: {{ postgres.group }}
|
2016-09-06 12:34:17 +03:00
|
|
|
- mode: 600
|
2014-05-15 14:44:39 -07:00
|
|
|
- require:
|
2016-05-25 12:12:48 -04:00
|
|
|
- file: postgresql-config-dir
|
2016-09-05 13:49:33 +03:00
|
|
|
|
|
|
|
postgresql-running:
|
|
|
|
service.running:
|
|
|
|
- name: {{ postgres.service }}
|
|
|
|
- enable: True
|
|
|
|
- reload: True
|
|
|
|
- watch:
|
|
|
|
- file: postgresql-pg_hba
|
|
|
|
|
|
|
|
postgresql-extra-pkgs-installed:
|
|
|
|
pkg.installed:
|
2016-09-06 12:34:17 +03:00
|
|
|
- pkgs: {{ postgres.pkgs_extra }}
|
2014-05-15 15:06:04 -07:00
|
|
|
|
2016-09-09 11:36:26 +03:00
|
|
|
### User states
|
|
|
|
|
|
|
|
{%- for name, user in postgres.users|dictsort() %}
|
|
|
|
|
|
|
|
{{ format_state(name, 'postgres_user', user) }}
|
2016-05-25 12:12:48 -04:00
|
|
|
- require:
|
|
|
|
- service: postgresql-running
|
2016-09-09 11:36:26 +03:00
|
|
|
{%- if 'db_user' in user %}
|
|
|
|
- postgres_user: postgres_user-{{ user.db_user }}
|
|
|
|
{%- endif %}
|
|
|
|
|
|
|
|
{%- endfor %}
|
|
|
|
|
|
|
|
### Tablespace states
|
|
|
|
|
|
|
|
{%- for name, tblspace in postgres.tablespaces|dictsort() %}
|
2014-05-15 15:06:04 -07:00
|
|
|
|
2016-09-09 11:36:26 +03:00
|
|
|
postgres_tablespace-dir-{{ tblspace.directory}}:
|
2016-06-08 07:36:28 -03:00
|
|
|
file.directory:
|
2016-07-11 13:18:17 -05:00
|
|
|
- name: {{ tblspace.directory }}
|
|
|
|
- user: {{ postgres.user }}
|
|
|
|
- group: {{ postgres.group }}
|
2016-09-09 11:36:26 +03:00
|
|
|
- mode: 700
|
2016-06-08 07:36:28 -03:00
|
|
|
- makedirs: True
|
|
|
|
- recurse:
|
|
|
|
- user
|
|
|
|
- group
|
|
|
|
|
2016-09-09 11:36:26 +03:00
|
|
|
{{ format_state(name, 'postgres_tablespace', tblspace) }}
|
2016-07-11 13:18:17 -05:00
|
|
|
- require:
|
2016-09-09 11:36:26 +03:00
|
|
|
- file: postgres_tablespace-dir-{{ tblspace.directory }}
|
|
|
|
{%- if 'owner' in tblspace %}
|
|
|
|
- postgres_user: postgres_user-{{ tblspace.owner }}
|
|
|
|
{%- endif %}
|
2016-07-11 13:18:17 -05:00
|
|
|
- service: postgresql-running
|
2016-09-09 11:36:26 +03:00
|
|
|
|
|
|
|
{%- endfor %}
|
|
|
|
|
|
|
|
### Database states
|
|
|
|
|
|
|
|
{%- for name, db in postgres.databases|dictsort() %}
|
|
|
|
|
|
|
|
{{ format_state(name, 'postgres_database', db) }}
|
2016-05-25 12:12:48 -04:00
|
|
|
- require:
|
|
|
|
- service: postgresql-running
|
2016-09-09 11:36:26 +03:00
|
|
|
{%- if 'db_user' in db %}
|
|
|
|
- postgres_user: postgres_user-{{ db.db_user }}
|
|
|
|
{%- endif %}
|
|
|
|
{%- if 'owner' in db %}
|
|
|
|
- postgres_user: postgres_user-{{ db.owner }}
|
|
|
|
{%- endif %}
|
|
|
|
{%- if 'tablespace' in db %}
|
|
|
|
- postgres_tablespace: postgres_tablespace-{{ db.tablespace }}
|
|
|
|
{%- endif %}
|
|
|
|
|
|
|
|
{%- endfor %}
|
|
|
|
|
|
|
|
### Schema states
|
|
|
|
|
|
|
|
{%- for name, schema in postgres.schemas|dictsort() %}
|
|
|
|
|
|
|
|
{{ format_state(name, 'postgres_schema', schema) }}
|
2016-07-11 13:18:17 -05:00
|
|
|
- require:
|
|
|
|
- service: postgresql-running
|
2016-09-09 11:36:26 +03:00
|
|
|
{%- if 'db_user' in schema %}
|
|
|
|
- postgres_user: postgres_user-{{ schema.db_user }}
|
|
|
|
{%- endif %}
|
|
|
|
{%- if 'dbname' in schema %}
|
|
|
|
- postgres_database: postgres_database-{{ schema.dbname }}
|
|
|
|
{%- endif %}
|
|
|
|
{%- if 'owner' in schema %}
|
|
|
|
- postgres_user: postgres_user-{{ schema.owner }}
|
|
|
|
{%- endif %}
|
|
|
|
|
|
|
|
{%- endfor %}
|
|
|
|
|
|
|
|
### Extension states
|
|
|
|
|
|
|
|
{%- for name, extension in postgres.extensions|dictsort() %}
|
|
|
|
|
|
|
|
{{ format_state(name, 'postgres_extension', extension) }}
|
2016-05-25 12:12:48 -04:00
|
|
|
- require:
|
|
|
|
- service: postgresql-running
|
2016-09-09 11:36:26 +03:00
|
|
|
- pkg: postgresql-extra-pkgs-installed
|
|
|
|
{%- if 'db_user' in extension %}
|
|
|
|
- postgres_user: postgres_user-{{ extension.db_user }}
|
|
|
|
{%- endif %}
|
|
|
|
{%- if 'maintenance_db' in extension %}
|
|
|
|
- postgres_database: postgres_database-{{ extension.maintenance_db }}
|
|
|
|
{%- endif %}
|
|
|
|
{%- if 'schema' in extension %}
|
|
|
|
- postgres_schema: postgres_schema-{{ extension.schema }}
|
|
|
|
{%- endif %}
|
|
|
|
|
|
|
|
{%- endfor %}
|