mirror of
https://github.com/saltstack-formulas/postgres-formula.git
synced 2025-04-16 17:50:27 +00:00
[REFACTORING] Add postgres.manage
state to provision DB objects
This commit is contained in:
parent
234a76f1e9
commit
74ddea8bdb
4 changed files with 94 additions and 79 deletions
|
@ -23,7 +23,11 @@ various DB objects in the cluster.
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
Installs the PostgreSQL client binaries and libraries.
|
Installs the PostgreSQL client binaries and libraries.
|
||||||
Allows to create such DB objects as: users, tablespaces, databases, schemas and
|
|
||||||
|
``postgres.manage``
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
Creates such DB objects as: users, tablespaces, databases, schemas and
|
||||||
extensions. See ``pillar.example`` file for details.
|
extensions. See ``pillar.example`` file for details.
|
||||||
|
|
||||||
``postgres.python``
|
``postgres.python``
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
{%- from "postgres/map.jinja" import postgres with context -%}
|
{%- from "postgres/map.jinja" import postgres with context -%}
|
||||||
{%- from "postgres/macros.jinja" import format_state with context -%}
|
|
||||||
|
|
||||||
{%- set pkgs = [] %}
|
{%- set pkgs = [] %}
|
||||||
{%- for pkg in (postgres.pkg_client, postgres.pkg_libpq_dev) %}
|
{%- for pkg in (postgres.pkg_client, postgres.pkg_libpq_dev) %}
|
||||||
{%- if pkg %}
|
{%- if pkg %}
|
||||||
{%- do pkgs.append(pkg) %}
|
{%- do pkgs.append(pkg) %}
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{%- endfor -%}
|
{%- endfor %}
|
||||||
|
|
||||||
{%- if postgres.use_upstream_repo -%}
|
{%- if postgres.use_upstream_repo %}
|
||||||
|
|
||||||
include:
|
include:
|
||||||
- postgres.upstream
|
- postgres.upstream
|
||||||
|
@ -46,78 +45,3 @@ postgresql-client-libs:
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
# Ensure that Salt is able to use postgres modules
|
|
||||||
# after installing client binaries
|
|
||||||
|
|
||||||
postgres-reload-modules:
|
|
||||||
test.nop:
|
|
||||||
- reload_modules: True
|
|
||||||
|
|
||||||
# User states
|
|
||||||
|
|
||||||
{%- for name, user in postgres.users|dictsort() %}
|
|
||||||
|
|
||||||
{{ format_state(name, 'postgres_user', user) }}
|
|
||||||
- require:
|
|
||||||
- pkg: postgresql-client-libs
|
|
||||||
|
|
||||||
{%- endfor %}
|
|
||||||
|
|
||||||
# Tablespace states
|
|
||||||
|
|
||||||
{%- for name, tblspace in postgres.tablespaces|dictsort() %}
|
|
||||||
|
|
||||||
{{ format_state(name, 'postgres_tablespace', tblspace) }}
|
|
||||||
- require:
|
|
||||||
- pkg: postgresql-client-libs
|
|
||||||
{%- if 'owner' in tblspace %}
|
|
||||||
- postgres_user: postgres_user-{{ tblspace.owner }}
|
|
||||||
{%- endif %}
|
|
||||||
|
|
||||||
{%- endfor %}
|
|
||||||
|
|
||||||
# Database states
|
|
||||||
|
|
||||||
{%- for name, db in postgres.databases|dictsort() %}
|
|
||||||
|
|
||||||
{{ format_state(name, 'postgres_database', db) }}
|
|
||||||
- require:
|
|
||||||
- pkg: postgresql-client-libs
|
|
||||||
{%- 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) }}
|
|
||||||
- require:
|
|
||||||
- pkg: postgresql-client-libs
|
|
||||||
{%- 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) }}
|
|
||||||
- require:
|
|
||||||
- pkg: postgresql-client-libs
|
|
||||||
{%- 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 %}
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
include:
|
include:
|
||||||
- postgres.server
|
- postgres.server
|
||||||
- postgres.client
|
- postgres.client
|
||||||
|
- postgres.manage
|
||||||
|
|
86
postgres/manage.sls
Normal file
86
postgres/manage.sls
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
{%- from "postgres/map.jinja" import postgres with context -%}
|
||||||
|
{%- from "postgres/macros.jinja" import format_state with context -%}
|
||||||
|
|
||||||
|
{%- if not salt.get('postgres.user_create') %}
|
||||||
|
|
||||||
|
# Salt states for managing PostgreSQL is not available,
|
||||||
|
# need to provision client binaries first
|
||||||
|
|
||||||
|
include:
|
||||||
|
- postgres.client
|
||||||
|
|
||||||
|
{%- endif %}
|
||||||
|
|
||||||
|
# Ensure that Salt is able to use postgres modules
|
||||||
|
|
||||||
|
postgres-reload-modules:
|
||||||
|
test.nop:
|
||||||
|
- reload_modules: True
|
||||||
|
|
||||||
|
# User states
|
||||||
|
|
||||||
|
{%- for name, user in postgres.users|dictsort() %}
|
||||||
|
|
||||||
|
{{ format_state(name, 'postgres_user', user) }}
|
||||||
|
- require:
|
||||||
|
- test: postgres-reload-modules
|
||||||
|
|
||||||
|
{%- endfor %}
|
||||||
|
|
||||||
|
# Tablespace states
|
||||||
|
|
||||||
|
{%- for name, tblspace in postgres.tablespaces|dictsort() %}
|
||||||
|
|
||||||
|
{{ format_state(name, 'postgres_tablespace', tblspace) }}
|
||||||
|
- require:
|
||||||
|
- test: postgres-reload-modules
|
||||||
|
{%- if 'owner' in tblspace %}
|
||||||
|
- postgres_user: postgres_user-{{ tblspace.owner }}
|
||||||
|
{%- endif %}
|
||||||
|
|
||||||
|
{%- endfor %}
|
||||||
|
|
||||||
|
# Database states
|
||||||
|
|
||||||
|
{%- for name, db in postgres.databases|dictsort() %}
|
||||||
|
|
||||||
|
{{ format_state(name, 'postgres_database', db) }}
|
||||||
|
- require:
|
||||||
|
- test: postgres-reload-modules
|
||||||
|
{%- 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) }}
|
||||||
|
- require:
|
||||||
|
- test: postgres-reload-modules
|
||||||
|
{%- 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) }}
|
||||||
|
- require:
|
||||||
|
- test: postgres-reload-modules
|
||||||
|
{%- 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 %}
|
Loading…
Add table
Reference in a new issue