Commit f435c097 authored by Louis VINCHON's avatar Louis VINCHON
Browse files

Role postgresql, task systemd: use override instead of editing the unit file

The issue:
In its previous state the task directly edited postgresql's systemd unit file.
This file is systematically replaced by each postgresql update.
This is fine as long as we roll the update with this role only, but will break
as soon as an update is rolled by any other mean.

The solution:
Create an override file located in /etc/systemd/system/postgresql.service with
the appropriate custom options for the unit file (what we used to write in the
unit file).
This file will not be overriden and is therefore more stable.
parent c42647cb
---
- name: Set PGDATA environment variable on CentOS 7
lineinfile:
path: /usr/lib/systemd/system/postgresql.service
regexp: '^Environment=PGDATA='
line: 'Environment=PGDATA={{path_to_icat}}'
when: (ansible_facts['distribution'] == "CentOS" and ansible_facts['distribution_major_version'] == "7" and use_distribution_postgresql)
- name: Set PGDATA environment variable on CentOS 7
lineinfile:
path: /usr/lib/systemd/system/postgresql-{{ external_postgresql_version }}.service
regexp: '^Environment=PGDATA='
line: 'Environment=PGDATA={{path_to_icat}}'
when: (ansible_facts['distribution'] == "CentOS" and ansible_facts['distribution_major_version'] == "7" and not use_distribution_postgresql)
- name: Set PGDATA environment variable on CentOS 8
lineinfile:
path: /usr/lib/systemd/system/postgresql.service
regexp: '^Environment=PGDATA='
line: 'Environment=PGDATA={{path_to_icat}}'
when: (ansible_facts['distribution'] == "CentOS" and ansible_facts['distribution_major_version'] == "8" and use_distribution_postgresql)
- name: Set PGDATA environment variable on CentOS 8
lineinfile:
path: /usr/lib/systemd/system/postgresql-{{ external_postgresql_version }}.service
regexp: '^Environment=PGDATA='
line: 'Environment=PGDATA={{path_to_icat}}'
when: (ansible_facts['distribution'] == "CentOS" and ansible_facts['distribution_major_version'] == "8" and not use_distribution_postgresql)
# Dynamically set some variables commonly used by this task group.
- name: Setting facts for systemd operations.
vars:
external_postgres_suffix: "-{{ external_postgresql_version }}"
# Suffix will be '-version', e.g. '-13' for postgresql v13.x.x, or '' (nothing) if we do use the version distributed by the standard repository.
suffix: "{{ ( use_distribution_postgresql == false ) | ternary(external_postgres_suffix, '') }}"
set_fact:
postgres_unit_file_name: "postgresql{{ suffix }}.service"
# This task will place an 'override' for the systemd unit file distributed by postgresql.
# Modifying the original unit file is not recomended as it is replaced with each update of postgresql.
#
# Its current purpose is to define the path to the data directory where the database's actual data will be on the system.
# cf. The template file.
- name: "Define the {{ postgres_unit_file_name }} override file."
template:
src: templates/postgresql.service.j2
dest: "/etc/systemd/system/{{ postgres_unit_file_name }}"
owner: root
group: wheel
mode: '0644'
when:
- path_to_icat is defined
- path_to_icat != None
- path_to_icat | length > 0
- name: Start postgresql service on CentOS 7
systemd:
......
.include /usr/lib/systemd/system/{{ postgres_unit_file_name }}
[Service]
Environment=PGDATA={{ path_to_icat }}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment