Skip to content

Commit 06e5944

Browse files
committed
Allow port to be configurable
Regex: - `^` Line start - `#*\s*` Find line even if commented out - `(port)` 'port' -- capture as backreference `\1` - `\s*=\s*` Equals sign, whether or not surrounded by whitespace - `\d{4,5}` Existing port value, expected at 4/5 digits - `(.*)` Remainder (i.e. comment) -- capture as backreference `\2` - `$` Line end
1 parent 800259d commit 06e5944

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

pillar.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ postgres:
3232
hard: 64000
3333

3434
# POSTGRES
35+
# Non-standard port to use for the cluster
36+
# Only set if port `5432` is not appropriate
37+
port: 5433
38+
3539
# Append the lines under this item to your postgresql.conf file.
3640
# Pay attention to indent exactly with 4 spaces for all lines.
3741
postgresconf: |

postgres/defaults.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
postgres:
44
use_upstream_repo: True
55
version: '9.5'
6+
default_port: 5432
67
pkg: postgresql
78
pkgs_extra: []
89
pkg_client: postgresql-client

postgres/macros.jinja

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
{{ state }}-{{ name }}:
2424
{{ state }}.{{ ensure|default('present') }}:
2525
{{- format_kwargs(kwarg) }}
26+
- db_port: {{ postgres.port|default(postgres.default_port) }}
2627
- onchanges:
2728
- test: postgres-reload-modules
2829

postgres/server/init.sls

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,24 @@ postgresql-running:
192192
- file: postgresql-pg_ident
193193
194194
{%- endif %}
195+
196+
{%- if postgres.port|default(false) %}
197+
198+
postgresql-port:
199+
file.replace:
200+
- name: {{ postgres.conf_dir }}/postgresql.conf
201+
- pattern: ^#*\s*(port)\s*=\s*\d{4,5}(.*)$
202+
- repl: \1 = {{ postgres.port }}\2
203+
- flags: 8 # ['MULTILINE']
204+
- show_changes: True
205+
- append_if_not_found: True
206+
- backup: {{ postgres.config_backup|default(false, true) }}
207+
- require:
208+
- file: postgresql-config-dir
209+
- watch_in:
210+
- service: postgresql-port
211+
212+
service.running:
213+
- name: {{ postgres.service }}
214+
215+
{%- endif %}

0 commit comments

Comments
 (0)