Skip to content

Commit 0bb93c6

Browse files
committed
Switch postgresql_conf from a dict to a list of dicts to preserve
ordering. Supercedes #13.
1 parent fa4e27e commit 0bb93c6

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,21 @@ Role Variables
3737
- `postgresql_flavor`: On Debian-based platforms, this specifies whether you want to use PostgreSQL packages from pgdg
3838
or the distribution's apt repositories. Possible values: `apt`, `pgdg` (default: `apt`).
3939

40-
- `postgresql_conf`: A hash (dictionary) of `postgresql.conf` options and values. These options are not added to
41-
`postgresql.conf` directly - the role adds a `conf.d` subdirectory in the configuration directory and an include
42-
statement for that directory to `postgresql.conf`. Options set in `postgresql_conf` are then set in
43-
`conf.d/25ansible_postgresql.conf`.
40+
- `postgresql_conf`: A list of hashes (dictionaries) of `postgresql.conf` options (keys) and values. These options are
41+
not added to `postgresql.conf` directly - the role adds a `conf.d` subdirectory in the configuration directory and an
42+
include statement for that directory to `postgresql.conf`. Options set in `postgresql_conf` are then set in
43+
`conf.d/25ansible_postgresql.conf`. For legacy reasons, this can also be a single hash, but the list syntax is
44+
preferred because it preserves order.
4445

4546
Due to YAML parsing, you must take care when defining values in
4647
`postgresql_conf` to ensure they are properly written to the config file. For
4748
example:
4849

4950
```yaml
5051
postgresql_conf:
51-
max_connections: 250
52-
archive_mode: "off"
53-
work_mem: "'8MB'"
52+
- max_connections: 250
53+
- archive_mode: "off"
54+
- work_mem: "'8MB'"
5455
```
5556
5657
Becomes the following in `25ansible_postgresql.conf`:
@@ -149,8 +150,8 @@ Use the PostgreSQL 9.5 packages and set some `postgresql.conf` options and `pg_h
149150
vars:
150151
postgresql_version: 9.5
151152
postgresql_conf:
152-
listen_addresses: "''" # disable network listening (listen on unix socket only)
153-
max_connections: 50 # decrease connection limit
153+
- listen_addresses: "''" # disable network listening (listen on unix socket only)
154+
- max_connections: 50 # decrease connection limit
154155
postgresql_pg_hba_conf:
155156
- host all all 10.0.0.0/8 md5
156157
roles:

templates/25ansible_postgresql.conf.j2

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33
##
44

55
{% if postgresql_conf is defined %}
6-
{% for opt in postgresql_conf %}
6+
{% if postgresql_conf is mapping %}
7+
{% for opt in postgresql_conf | sort -%}
78
{{ opt }} = {{ postgresql_conf[opt] }}
89
{% endfor %}
10+
{% else %}
11+
{% for pair in postgresql_conf -%}
12+
{% for key in pair -%}
13+
{{ key }} = {{ pair[key] }}
14+
{% endfor %}
15+
{% endfor %}
16+
{% endif %}
917
{% endif %}

0 commit comments

Comments
 (0)