Skip to content

Commit 313e33c

Browse files
committed
Properly check for inclusion of conf.d and don't modify existing
declarations
1 parent 787b7c2 commit 313e33c

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

tasks/main.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,29 @@
3636
owner: "{{ postgresql_user_name }}"
3737
group: "{{ postgresql_user_name }}"
3838

39+
# lineinfile's behavior when `backrefs = True` is very odd. We don't want to overwrite include_dirs if it's already
40+
# properly set, but we don't know the exact format it will be in (with or without '=', with a comment at end of line,
41+
# etc.). So check for a match first and then add if there's no match.
42+
- name: Check for conf.d include in postgresql.conf
43+
lineinfile:
44+
line: 'why ansible ;('
45+
# The '=' is optional but is present in postgresql.conf.sample, which Debian's sample is based off of (but include*
46+
# directive examples in the PostgreSQL docs don't use it). Also ignore comments and whitespace after the directive.
47+
regexp: '^include_dir(\s+|\s*=\s*)?''conf.d''\s*(#.*)?$'
48+
path: "{{ postgresql_conf_dir }}/postgresql.conf"
49+
backrefs: true
50+
check_mode: true
51+
changed_when: __postgresql_include_dir_result is not changed # yeah...
52+
register: __postgresql_include_dir_result
53+
when: "postgresql_version is version_compare('9.3', '>=')"
54+
3955
- name: Set conf.d include in postgresql.conf
4056
lineinfile:
4157
line: "include_dir 'conf.d'"
42-
dest: "{{ postgresql_conf_dir }}/postgresql.conf"
58+
path: "{{ postgresql_conf_dir }}/postgresql.conf"
4359
backup: yes
4460
notify: Reload PostgreSQL
45-
when: "postgresql_version is version_compare('9.3', '>=')"
46-
61+
when: "postgresql_version is version_compare('9.3', '>=') and __postgresql_include_dir_result is changed"
4762

4863
- name: Include 25ansible_postgresql.conf in postgresql.conf
4964
lineinfile:

0 commit comments

Comments
 (0)