Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the the original PostgreSQL configuration file #41

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
10 changes: 8 additions & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
# Recursively reset the owner/group of the postgres datadir?
postgresql_server_chown_datadir: false

postgres_config_file_contents: ''
######################################################################
# Internal role variables, do not modify
######################################################################
Expand All @@ -51,14 +52,19 @@
{{
(postgresql_package_version | length > 0) |
ternary('-' + postgresql_package_version, '')
}}
}}

Check failure on line 55 in defaults/main.yml

View workflow job for this annotation

GitHub Actions / Test (rockylinux9)

55:7 [trailing-spaces] trailing spaces

Check failure on line 55 in defaults/main.yml

View workflow job for this annotation

GitHub Actions / Test (rockylinux9)

yaml[trailing-spaces]

Trailing spaces

Check failure on line 55 in defaults/main.yml

View workflow job for this annotation

GitHub Actions / Test (ubuntu2204)

55:7 [trailing-spaces] trailing spaces

Check failure on line 55 in defaults/main.yml

View workflow job for this annotation

GitHub Actions / Test (ubuntu2204)

yaml[trailing-spaces]

Trailing spaces

# Attributes are parsed and used to set facts at tasks/debian.yml.
# Debian variation, following the same principles of 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

# conf_sample_file: sample configuration file, it should be copied during the installation by the installation package

Check failure on line 67 in defaults/main.yml

View workflow job for this annotation

GitHub Actions / Test (rockylinux9)

67:81 [line-length] line too long (118 > 80 characters)

Check failure on line 67 in defaults/main.yml

View workflow job for this annotation

GitHub Actions / Test (ubuntu2204)

67:81 [line-length] line too long (118 > 80 characters)
sbesson marked this conversation as resolved.
Show resolved Hide resolved

# the following two variables are used to download link ofr the source to get the sample configuration file

Check failure on line 69 in defaults/main.yml

View workflow job for this annotation

GitHub Actions / Test (rockylinux9)

69:81 [line-length] line too long (107 > 80 characters)

Check failure on line 69 in defaults/main.yml

View workflow job for this annotation

GitHub Actions / Test (ubuntu2204)

69:81 [line-length] line too long (107 > 80 characters)
# It will be used in case of the sample file is not find locally for any reason
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to have a hard fail in case conf_sample_file does not exist?

Are you aware of any scenario where this file could legitimately be expected to be missing?

Copy link
Contributor Author

@khaledk2 khaledk2 Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On our RHEL 9 test machine, there are 4 PostgreSQL versions have been installed (13, 14, 15, 16). Only version 16 folder has the sample file and the others do not have this file. I am not sure how these versions have been installed but I think the file should be there. I am not sure why it is missing. So, I have added the logic of downloading and extracting the file to account for similar cases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting (and slightly concerning). Note all of the PSQL sample configuration file checks seem to be currently skipped in the Molecule tests on both Rocky Linux. I don't know if that's expected or indicates another issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will check for the sample file if the original file does not exist and the configuration file has been edited before, i.e. in case of installing the same PostgreSQL version with a previous role version.

13 changes: 11 additions & 2 deletions molecule/resources/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,23 @@ def test_server_listen(host):
assert listen_addresses == "listen_addresses = localhost"


def test_backup_config_exist(host):
version = get_version(host)
if host.system_info.distribution == 'rocky':
config_backup = '/var/lib/pgsql/{version}/data/postgresql.conf.org'
else:
config_backup = '/etc/postgresql/{version}/main/postgresql.conf.org'
with host.sudo():
backup_file = config_backup.format(version=version)
assert host.file(backup_file).is_file


def test_psql_version(host):
ver = get_version(host)
out = host.check_output('psql --version')
assert out.startswith('psql (PostgreSQL) {}.'.format(ver))


# Create

def createdb(host, db, should_pass, password, name):
try:
host.check_output(
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
48 changes: 42 additions & 6 deletions tasks/initialise.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
# tasks file for ome.postgresql
##Ansible managed

Check warning on line 3 in tasks/initialise.yml

View workflow job for this annotation

GitHub Actions / Test (rockylinux9)

3:3 [comments] missing starting space in comment

Check warning on line 3 in tasks/initialise.yml

View workflow job for this annotation

GitHub Actions / Test (ubuntu2204)

3:3 [comments] missing starting space in comment
sbesson marked this conversation as resolved.
Show resolved Hide resolved

- block:
- name: postgres | set permissions on data directory
Expand All @@ -22,27 +23,62 @@
PGSETUP_INITDB_OPTIONS: >-
--encoding=UTF8 --locale=en_US.UTF-8 --auth-host=md5

- name: postgres | postgresql config file
template:
- name: postgres | check that the postgresql.conf.org file exists
ansible.builtin.stat:
path: "{{ postgresql_dist_confdir }}/postgresql.conf.org"
register: org_file

- name: postgres | remove the custom configurations from the file, if any
command: sed -i '/# Add settings for extensions here/q' "{{ postgresql_dist_confdir }}/postgresql.conf"

Check failure on line 32 in tasks/initialise.yml

View workflow job for this annotation

GitHub Actions / Test (rockylinux9)

32:81 [line-length] line too long (109 > 80 characters)

Check failure on line 32 in tasks/initialise.yml

View workflow job for this annotation

GitHub Actions / Test (ubuntu2204)

32:81 [line-length] line too long (109 > 80 characters)
when:
- not org_file.stat.exists

- name: postgres | remove the Ansible managed line, if any
ansible.builtin.lineinfile:
path: "{{ postgresql_dist_confdir }}/postgresql.conf"

Check failure on line 38 in tasks/initialise.yml

View workflow job for this annotation

GitHub Actions / Test (rockylinux9)

38:11 [indentation] wrong indentation: expected 8 but found 10

Check failure on line 38 in tasks/initialise.yml

View workflow job for this annotation

GitHub Actions / Test (ubuntu2204)

38:11 [indentation] wrong indentation: expected 8 but found 10
regexp: "#Ansible managed"
state: absent
when:
- not org_file.stat.exists

- name: postgres | copy a postgresql.conf to postgresql.conf.org
become_user: "{{ postgresql_become_user }}"
ansible.builtin.copy:
src: "{{ postgresql_dist_confdir }}/postgresql.conf"
dest: "{{ postgresql_dist_confdir }}/postgresql.conf.org"
remote_src: yes

Check warning on line 49 in tasks/initialise.yml

View workflow job for this annotation

GitHub Actions / Test (rockylinux9)

49:21 [truthy] truthy value should be one of [false, true]

Check warning on line 49 in tasks/initialise.yml

View workflow job for this annotation

GitHub Actions / Test (ubuntu2204)

49:21 [truthy] truthy value should be one of [false, true]
when:
- not org_file.stat.exists

# 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.org"
register: postgres_config_file_contents_o

- set_fact: postgres_config_file_contents={{ postgres_config_file_contents_o }}

Check failure on line 60 in tasks/initialise.yml

View workflow job for this annotation

GitHub Actions / Test (rockylinux9)

60:81 [line-length] line too long (83 > 80 characters)

Check failure on line 60 in tasks/initialise.yml

View workflow job for this annotation

GitHub Actions / Test (ubuntu2204)

60:81 [line-length] line too long (83 > 80 characters)

- name: postgres | copy postgresql config file
become_user: "{{ postgresql_become_user }}"
ansible.builtin.template:
dest: >-
{{ postgresql_dist_confdir }}/postgresql.conf
src: "{{ postgresql_dist_conf_postgresql_src }}"
mode: 0644
owner: "{{ postgresql_become_user }}"
notify:
- restart postgresql

become_user: "{{ postgresql_become_user }}"
sbesson marked this conversation as resolved.
Show resolved Hide resolved

- name: postgres | configure client authorisation
become_user: "{{ postgresql_become_user }}"
template:
dest: "{{ postgresql_dist_confdir }}/pg_hba.conf"
src: pg_hba-conf.j2
mode: 0640
notify:
- restart postgresql

become_user: "{{ postgresql_become_user }}"

- name: postgres | start service
service:
enabled: true
Expand Down
Loading
Loading