Skip to content
2 changes: 1 addition & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ postgresql_dist_redhat:
postgresql_dist_debian:
bindir: /usr/lib/postgresql/{{ postgresql_version }}/bin
confdir: /etc/postgresql/{{ postgresql_version }}/main
conf_postgresql_src: postgresql-conf-10-ubuntu.j2
conf_postgresql_src: postgresql-conf.j2
datadir: /var/lib/postgresql/{{ postgresql_version }}/main
basename: postgresql-{{ postgresql_version }}
service: postgresql
10 changes: 6 additions & 4 deletions molecule/resources/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import pytest
import testinfra.utils.ansible_runner
import uuid
from re import match
from utils import get_version

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
Expand Down Expand Up @@ -40,12 +39,15 @@ def test_server_listen(host):

count_listen_addresses = 0
for line in f.split('\n'):
if match(r'\s*listen_addresses', line):
if 'listen_addresses' in line:
count_listen_addresses += 1
listen_addresses = line
assert count_listen_addresses == 1

assert listen_addresses == "listen_addresses = localhost"
if line.startswith('#'):
sub_line = listen_addresses.split('#')[0].strip()
else:
sub_line = listen_addresses.split('#')[1].strip()
assert sub_line == "listen_addresses = 'localhost'"


def test_psql_version(host):
Expand Down
4 changes: 2 additions & 2 deletions molecule/resources/tests/test_extra_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def test_server_log_file_name(host):
# Check previous day too in case this is run at midnight
version = get_version(host)
if host.system_info.distribution == 'rocky':
logdir = '/var/lib/pgsql/{version}/data/pg_log'
logdir = '/var/lib/pgsql/{version}/data/log'
else:
logdir = '/var/lib/postgresql/{version}/main/pg_log'
logdir = '/var/lib/postgresql/{version}/main/log'
date1 = datetime.today()
date0 = date1 - timedelta(days=1)
logdir = logdir.format(version=version)
Expand Down
23 changes: 21 additions & 2 deletions tasks/initialise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,35 @@
PGSETUP_INITDB_OPTIONS: >-
--encoding=UTF8 --locale=en_US.UTF-8 --auth-host=md5

- name: postgres | Check for presence of "Modified by ome postgresql ansible role" in file
ansible.builtin.lineinfile:
path: "{{ postgresql_dist_confdir }}/postgresql.conf"
line: "#Modified by ome postgresql ansible role"
state: absent
check_mode: yes
changed_when: false
register: config_file_changed

# read the default postgresql configuration file
- name: postgres | get the postgres conf file contents
become_user: "{{ postgresql_become_user }}"
ansible.builtin.slurp:
src: "{{ postgresql_dist_confdir }}/postgresql.conf"
register: postgres_config_file_contents
when: config_file_changed.found | default(0) == 0


- name: postgres | postgresql config file
template:
ansible.builtin.template:
dest: >-
{{ postgresql_dist_confdir }}/postgresql.conf
src: "{{ postgresql_dist_conf_postgresql_src }}"
mode: 0644
owner: "{{ postgresql_become_user }}"
notify:
- restart postgresql
when: config_file_changed.found | default(0) == 0

become_user: "{{ postgresql_become_user }}"

- name: postgres | configure client authorisation
template:
Expand Down
Loading