mirror of
https://github.com/saltstack-formulas/postgres-formula.git
synced 2025-04-16 09:40:26 +00:00
Make local backup of pg_hba.conf
file before modification
This commit is contained in:
parent
98d39f296e
commit
79b83fe414
3 changed files with 26 additions and 11 deletions
|
@ -19,12 +19,6 @@ postgres:
|
||||||
postgresconf: |
|
postgresconf: |
|
||||||
listen_addresses = '*' # listen on all interfaces
|
listen_addresses = '*' # listen on all interfaces
|
||||||
|
|
||||||
# Backup extension for postgresql.conf file, defaults to ``.bak``.
|
|
||||||
# Set to False to stop creation of backup on postgresql.conf changes.
|
|
||||||
{%- if 'status.time' in salt.keys() %}
|
|
||||||
postgresconf_backup: ".backup@{{ salt['status.time']('%y-%m-%d_%H:%M:%S') }}"
|
|
||||||
{%- endif %}
|
|
||||||
|
|
||||||
# Path to the `pg_hba.conf` file Jinja template on Salt Fileserver
|
# Path to the `pg_hba.conf` file Jinja template on Salt Fileserver
|
||||||
pg_hba.conf: salt://postgres/templates/pg_hba.conf.j2
|
pg_hba.conf: salt://postgres/templates/pg_hba.conf.j2
|
||||||
|
|
||||||
|
@ -48,6 +42,12 @@ postgres:
|
||||||
- ['local', 'db1', 'localUser']
|
- ['local', 'db1', 'localUser']
|
||||||
- ['host', 'db2', 'remoteUser', '192.168.33.0/24']
|
- ['host', 'db2', 'remoteUser', '192.168.33.0/24']
|
||||||
|
|
||||||
|
# Backup extension for configuration files, defaults to ``.bak``.
|
||||||
|
# Set ``False`` to stop creation of backups when config files change.
|
||||||
|
{%- if 'status.time' in salt.keys() %}
|
||||||
|
config_backup: ".backup@{{ salt['status.time']('%y-%m-%d_%H:%M:%S') }}"
|
||||||
|
{%- endif %}
|
||||||
|
|
||||||
# PostgreSQL service name
|
# PostgreSQL service name
|
||||||
service: postgresql
|
service: postgresql
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ postgres:
|
||||||
|
|
||||||
conf_dir: /var/lib/pgsql/data
|
conf_dir: /var/lib/pgsql/data
|
||||||
postgresconf: ""
|
postgresconf: ""
|
||||||
postgresconf_backup: '.bak'
|
|
||||||
|
|
||||||
pg_hba.conf: salt://postgres/templates/pg_hba.conf.j2
|
pg_hba.conf: salt://postgres/templates/pg_hba.conf.j2
|
||||||
acls:
|
acls:
|
||||||
|
@ -31,6 +30,8 @@ postgres:
|
||||||
# IPv6 local connections:
|
# IPv6 local connections:
|
||||||
- ['host', 'all', 'all', '::1/128', 'md5']
|
- ['host', 'all', 'all', '::1/128', 'md5']
|
||||||
|
|
||||||
|
config_backup: '.bak'
|
||||||
|
|
||||||
service: postgresql
|
service: postgresql
|
||||||
|
|
||||||
bake_image: False
|
bake_image: False
|
||||||
|
|
|
@ -8,8 +8,6 @@
|
||||||
{%- do includes.append('postgres.upstream') %}
|
{%- do includes.append('postgres.upstream') %}
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
{%- set pkgs = [postgres.pkg] + postgres.pkgs_extra %}
|
|
||||||
|
|
||||||
{%- if includes -%}
|
{%- if includes -%}
|
||||||
|
|
||||||
include:
|
include:
|
||||||
|
@ -17,6 +15,8 @@ include:
|
||||||
|
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
|
{%- set pkgs = [postgres.pkg] + postgres.pkgs_extra %}
|
||||||
|
|
||||||
# Install, configure and start PostgreSQL server
|
# Install, configure and start PostgreSQL server
|
||||||
|
|
||||||
postgresql-server:
|
postgresql-server:
|
||||||
|
@ -82,7 +82,7 @@ postgresql-conf:
|
||||||
{{ postgres.postgresconf|indent(8) }}
|
{{ postgres.postgresconf|indent(8) }}
|
||||||
- show_changes: True
|
- show_changes: True
|
||||||
- append_if_not_found: True
|
- append_if_not_found: True
|
||||||
- backup: {{ postgres.postgresconf_backup }}
|
- backup: {{ postgres.config_backup }}
|
||||||
- require:
|
- require:
|
||||||
- file: postgresql-config-dir
|
- file: postgresql-config-dir
|
||||||
- watch_in:
|
- watch_in:
|
||||||
|
@ -90,9 +90,23 @@ postgresql-conf:
|
||||||
|
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
|
{%- 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:
|
postgresql-pg_hba:
|
||||||
file.managed:
|
file.managed:
|
||||||
- name: {{ postgres.conf_dir }}/pg_hba.conf
|
- name: {{ pg_hba_path }}
|
||||||
- user: {{ postgres.user }}
|
- user: {{ postgres.user }}
|
||||||
- group: {{ postgres.group }}
|
- group: {{ postgres.group }}
|
||||||
- mode: 600
|
- mode: 600
|
||||||
|
|
Loading…
Add table
Reference in a new issue