Merge pull request #218 from myii/PR_port

Allow `port` to be configurable
This commit is contained in:
Niels Abspoel 2018-06-17 13:40:48 +02:00 committed by GitHub
commit 844ae9742c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 3 deletions

View file

@ -1,3 +1,7 @@
# Port to use for the cluster -- can be used to provide a non-standard port
# NOTE: If already set in the minion config, that value takes priority
postgres.port: '5432'
postgres:
# UPSTREAM REPO
# Set True to configure upstream postgresql.org repository for YUM/APT/ZYPP
@ -34,7 +38,7 @@ postgres:
# POSTGRES
# Append the lines under this item to your postgresql.conf file.
# Pay attention to indent exactly with 4 spaces for all lines.
postgresconf: |
postgresconf: |-
listen_addresses = '*' # listen on all interfaces
# Path to the `pg_hba.conf` file Jinja template on Salt Fileserver

View file

@ -86,7 +86,19 @@ postgresql-config-dir:
- require:
- cmd: postgresql-cluster-prepared
{%- if postgres.postgresconf %}
{%- set db_port = salt['config.option']('postgres.port') %}
{%- if db_port %}
postgresql-conf-comment-port:
file.comment:
- name: {{ postgres.conf_dir }}/postgresql.conf
- regex: ^port\s*=.+
- require:
- file: postgresql-config-dir
{%- endif %}
{%- if postgres.postgresconf or db_port %}
postgresql-conf:
file.blockreplace:
@ -94,15 +106,30 @@ postgresql-conf:
- marker_start: "# Managed by SaltStack: listen_addresses: please do not edit"
- marker_end: "# Managed by SaltStack: end of salt managed zone --"
- content: |
{%- if postgres.postgresconf %}
{{ postgres.postgresconf|indent(8) }}
{%- endif %}
{%- if db_port %}
port = {{ db_port }}
{%- endif %}
- show_changes: True
- append_if_not_found: True
{#- Detect empty values (none, '') in the config_backup #}
- backup: {{ postgres.config_backup|default(false, true) }}
- require:
- file: postgresql-config-dir
{%- if db_port %}
- file: postgresql-conf-comment-port
{%- endif %}
- watch_in:
- service: postgresql-running
- module: postgresql-service-restart
# Restart the service where reloading is not sufficient
# Currently only when changes are made to `postgresql.conf`
postgresql-service-restart:
module.wait:
- name: service.restart
- m_name: {{ postgres.service }}
{%- endif %}