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
This commit is contained in:
Imran Iqbal 2018-06-08 23:40:12 +01:00
parent 800259dffe
commit 06e5944133
4 changed files with 27 additions and 0 deletions

View file

@ -32,6 +32,10 @@ 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: |

View file

@ -3,6 +3,7 @@
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

View file

@ -23,6 +23,7 @@
{{ 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

View file

@ -192,3 +192,24 @@ 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}(.*)$
- repl: \1 = {{ postgres.port }}\2
- 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 %}