mirror of
https://github.com/saltstack-formulas/postgres-formula.git
synced 2025-04-17 10:10:31 +00:00
Convert hard-coded postgres user and group to variables, enforce ownership of conf dir, don't create pg_hba.conf unless initdb has succeeded
This commit is contained in:
parent
aba8414809
commit
e36478bcd6
2 changed files with 11 additions and 6 deletions
|
@ -20,3 +20,5 @@ postgres:
|
|||
pg_hba.conf: salt://postgres/pg_hba.conf
|
||||
commands:
|
||||
initdb: service postgresql initdb
|
||||
postgres_user: postgres
|
||||
postgres_group: postgres
|
||||
|
|
|
@ -7,6 +7,8 @@ include:
|
|||
|
||||
{{ postgres.conf_dir }}:
|
||||
file.directory:
|
||||
- user: {{ postgres.postgres_user }}
|
||||
- group: {{ postgres.postgres_group }}
|
||||
- makedirs: True
|
||||
|
||||
install-postgresql:
|
||||
|
@ -71,11 +73,12 @@ pg_hba.conf:
|
|||
- name: {{ postgres.conf_dir }}/pg_hba.conf
|
||||
- source: {{ postgres['pg_hba.conf'] }}
|
||||
- template: jinja
|
||||
- user: postgres
|
||||
- group: postgres
|
||||
- user: {{ postgres.postgres_user }}
|
||||
- group: {{ postgres.postgres_group }}
|
||||
- mode: 644
|
||||
- require:
|
||||
- pkg: install-postgresql
|
||||
- onlyif: test -f {{ postgres.conf_dir }}/postgresql.conf
|
||||
- watch_in:
|
||||
- service: run-postgresql
|
||||
|
||||
|
@ -90,14 +93,14 @@ postgres-user-{{ name }}:
|
|||
- inherit: {{ user.get('inherit', True) }}
|
||||
- replication: {{ user.get('replication', False) }}
|
||||
- password: {{ user.get('password', 'changethis') }}
|
||||
- user: {{ user.get('runas', 'postgres') }}
|
||||
- user: {{ user.get('runas', postgres.postgres_user) }}
|
||||
- superuser: {{ user.get('superuser', False) }}
|
||||
- require:
|
||||
- service: run-postgresql
|
||||
{% else %}
|
||||
postgres_user.absent:
|
||||
- name: {{ name }}
|
||||
- user: {{ user.get('runas', 'postgres') }}
|
||||
- user: {{ user.get('runas', postgres.postgres_user) }}
|
||||
- require:
|
||||
- service: run-postgresql
|
||||
{% endif %}
|
||||
|
@ -114,7 +117,7 @@ postgres-db-{{ name }}:
|
|||
{% if db.get('owner') %}
|
||||
- owner: {{ db.get('owner') }}
|
||||
{% endif %}
|
||||
- user: {{ db.get('runas', 'postgres') }}
|
||||
- user: {{ db.get('runas', postgres.postgres_user) }}
|
||||
- require:
|
||||
- service: run-postgresql
|
||||
{% if db.get('user') %}
|
||||
|
@ -140,7 +143,7 @@ postgres-schema-{{ schema }}-for-db-{{ name }}:
|
|||
postgres-ext-{{ ext }}-for-db-{{ name }}:
|
||||
postgres_extension.present:
|
||||
- name: {{ ext }}
|
||||
- user: {{ db.get('runas', 'postgres') }}
|
||||
- user: {{ db.get('runas', postgres.postgres_user) }}
|
||||
- maintenance_db: {{ name }}
|
||||
{% if ext_args is not none %}
|
||||
{% for arg, value in ext_args.items() %}
|
||||
|
|
Loading…
Add table
Reference in a new issue