Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions postgres/server/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ postgresql-conf:
{{ postgres.postgresconf|indent(8) }}
- show_changes: True
- append_if_not_found: True
- backup: {{ postgres.config_backup }}
{#- Detect empty values (none, '') in the config_backup #}
- backup: {{ postgres.config_backup|default(false, true) }}
- require:
- file: postgresql-config-dir
- watch_in:
Expand All @@ -92,18 +93,6 @@ postgresql-conf:

{%- set pg_hba_path = salt['file.join'](postgres.conf_dir, 'pg_hba.conf') %}

postgresql-pg_hba-backup:
file.copy:
- name: {{ pg_hba_path ~ postgres.config_backup }}
- source: {{ pg_hba_path }}
- force: True
- user: {{ postgres.user }}
- group: {{ postgres.group }}
- mode: 600
- onlyif: test -f {{ pg_hba_path }}
- prereq:
- file: postgresql-pg_hba

postgresql-pg_hba:
file.managed:
- name: {{ pg_hba_path }}
Expand All @@ -115,6 +104,14 @@ postgresql-pg_hba:
- template: jinja
- defaults:
acls: {{ postgres.acls }}
{%- if postgres.config_backup %}
# Create the empty file before managing to overcome the limitation of check_cmd
- onlyif: test -f {{ pg_hba_path }} || touch {{ pg_hba_path }}
# Make a local backup before the file modification
- check_cmd: >-
salt-call --local file.copy
{{ pg_hba_path }} {{ pg_hba_path ~ postgres.config_backup }} remove_existing=true
{%- endif %}
{%- else %}
- replace: False
{%- endif %}
Expand Down