mirror of
https://github.com/saltstack-formulas/postgres-formula.git
synced 2025-04-16 09:40:26 +00:00
Use top-level postgres.port
and existing states to set port
This commit is contained in:
parent
0d9a5ba239
commit
e1a19ed78f
4 changed files with 28 additions and 32 deletions
|
@ -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:
|
postgres:
|
||||||
# UPSTREAM REPO
|
# UPSTREAM REPO
|
||||||
# Set True to configure upstream postgresql.org repository for YUM/APT/ZYPP
|
# Set True to configure upstream postgresql.org repository for YUM/APT/ZYPP
|
||||||
|
@ -32,13 +36,9 @@ postgres:
|
||||||
hard: 64000
|
hard: 64000
|
||||||
|
|
||||||
# POSTGRES
|
# POSTGRES
|
||||||
# Non-standard port to use for the cluster
|
|
||||||
# Only set if port `5432` is not appropriate
|
|
||||||
port: 5433
|
|
||||||
|
|
||||||
# Append the lines under this item to your postgresql.conf file.
|
# Append the lines under this item to your postgresql.conf file.
|
||||||
# Pay attention to indent exactly with 4 spaces for all lines.
|
# Pay attention to indent exactly with 4 spaces for all lines.
|
||||||
postgresconf: |
|
postgresconf: |-
|
||||||
listen_addresses = '*' # listen on all interfaces
|
listen_addresses = '*' # listen on all interfaces
|
||||||
|
|
||||||
# Path to the `pg_hba.conf` file Jinja template on Salt Fileserver
|
# Path to the `pg_hba.conf` file Jinja template on Salt Fileserver
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
postgres:
|
postgres:
|
||||||
use_upstream_repo: True
|
use_upstream_repo: True
|
||||||
version: '9.5'
|
version: '9.5'
|
||||||
default_port: 5432
|
|
||||||
pkg: postgresql
|
pkg: postgresql
|
||||||
pkgs_extra: []
|
pkgs_extra: []
|
||||||
pkg_client: postgresql-client
|
pkg_client: postgresql-client
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
{{ state }}-{{ name }}:
|
{{ state }}-{{ name }}:
|
||||||
{{ state }}.{{ ensure|default('present') }}:
|
{{ state }}.{{ ensure|default('present') }}:
|
||||||
{{- format_kwargs(kwarg) }}
|
{{- format_kwargs(kwarg) }}
|
||||||
- db_port: {{ postgres.port|default(postgres.default_port) }}
|
|
||||||
- onchanges:
|
- onchanges:
|
||||||
- test: postgres-reload-modules
|
- test: postgres-reload-modules
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,19 @@ postgresql-config-dir:
|
||||||
- require:
|
- require:
|
||||||
- cmd: postgresql-cluster-prepared
|
- 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:
|
postgresql-conf:
|
||||||
file.blockreplace:
|
file.blockreplace:
|
||||||
|
@ -94,15 +106,23 @@ postgresql-conf:
|
||||||
- marker_start: "# Managed by SaltStack: listen_addresses: please do not edit"
|
- marker_start: "# Managed by SaltStack: listen_addresses: please do not edit"
|
||||||
- marker_end: "# Managed by SaltStack: end of salt managed zone --"
|
- marker_end: "# Managed by SaltStack: end of salt managed zone --"
|
||||||
- content: |
|
- content: |
|
||||||
|
{%- if postgres.postgresconf %}
|
||||||
{{ postgres.postgresconf|indent(8) }}
|
{{ postgres.postgresconf|indent(8) }}
|
||||||
|
{%- endif %}
|
||||||
|
{%- if db_port %}
|
||||||
|
port = {{ db_port }}
|
||||||
|
{%- endif %}
|
||||||
- show_changes: True
|
- show_changes: True
|
||||||
- append_if_not_found: True
|
- append_if_not_found: True
|
||||||
{#- Detect empty values (none, '') in the config_backup #}
|
{#- Detect empty values (none, '') in the config_backup #}
|
||||||
- backup: {{ postgres.config_backup|default(false, true) }}
|
- backup: {{ postgres.config_backup|default(false, true) }}
|
||||||
- require:
|
- require:
|
||||||
- file: postgresql-config-dir
|
- file: postgresql-config-dir
|
||||||
|
{%- if db_port %}
|
||||||
|
- file: postgresql-conf-comment-port
|
||||||
|
{%- endif %}
|
||||||
- watch_in:
|
- watch_in:
|
||||||
- service: postgresql-running
|
- service: postgresql-running
|
||||||
|
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
|
@ -184,7 +204,7 @@ postgresql-running:
|
||||||
service.running:
|
service.running:
|
||||||
- name: {{ postgres.service }}
|
- name: {{ postgres.service }}
|
||||||
- enable: True
|
- enable: True
|
||||||
{% if grains.os not in ('MacOS',) %}
|
{% if grains.os not in ('MacOS',) and not db_port %}
|
||||||
- reload: True
|
- reload: True
|
||||||
{% endif %}
|
{% endif %}
|
||||||
- watch:
|
- watch:
|
||||||
|
@ -192,25 +212,3 @@ postgresql-running:
|
||||||
- file: postgresql-pg_ident
|
- file: postgresql-pg_ident
|
||||||
|
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
{%- if postgres.port|default(false) %}
|
|
||||||
|
|
||||||
postgresql-port:
|
|
||||||
file.replace:
|
|
||||||
- name: {{ postgres.conf_dir }}/postgresql.conf
|
|
||||||
- pattern: ^#*\s*(port)\s*=\s*\d{4,5}(\s*).*$
|
|
||||||
- repl: >-
|
|
||||||
\1 = {{ postgres.port }}\2# Managed by SaltStack: please do not edit
|
|
||||||
- flags: 8 # ['MULTILINE']
|
|
||||||
- show_changes: True
|
|
||||||
- append_if_not_found: True
|
|
||||||
- backup: {{ postgres.config_backup|default(false, true) }}
|
|
||||||
- require:
|
|
||||||
- file: postgresql-config-dir
|
|
||||||
- watch_in:
|
|
||||||
- service: postgresql-port
|
|
||||||
|
|
||||||
service.running:
|
|
||||||
- name: {{ postgres.service }}
|
|
||||||
|
|
||||||
{%- endif %}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue