Skip to content

Commit 06cf198

Browse files
authored
This commit adds generation of internal configuration file (linux-system-roles#22)
* This commit adds generation of internal configuration file into /etc/postgresql to be ssl_enable and server_tunnig idempotent and behave correctly after state switching within multiple role runs. Currently tunning variable overwrites values in /var/lib/pgsql/data/postgresql.conf and it isnt possible to recover default setting in the next runs with switched off tunning. Now /var/lib/pgsql/data/postgresql.conf is not modified. Instead of modification there is internal configuration file for system role. * Add tempalte to generate internal conf file
1 parent c7b12d4 commit 06cf198

File tree

2 files changed

+32
-31
lines changed

2 files changed

+32
-31
lines changed

tasks/main.yml

+23-31
Original file line numberDiff line numberDiff line change
@@ -89,31 +89,6 @@
8989
- name: Manage certificates
9090
include_tasks: certificate.yml
9191

92-
- name: Enable SSL
93-
replace:
94-
path: /var/lib/pgsql/data/postgresql.conf
95-
regexp: '#(ssl\s=\s).*$'
96-
replace: '\1on'
97-
when:
98-
- postgresql_ssl_enable
99-
notify: Restart postgresql
100-
101-
- name: Set up recommanded shared_buffers size
102-
replace:
103-
path: "/var/lib/pgsql/data/postgresql.conf"
104-
regexp: '(shared_buffers\s=\s)([0-9]+)(\w\w)'
105-
replace: '\1 {{ (ansible_memory_mb.real.total / 4) | int | abs }}MB'
106-
when: postgresql_server_tuning
107-
notify: Restart postgresql
108-
109-
- name: Set up recommended cache_size
110-
replace:
111-
path: "/var/lib/pgsql/data/postgresql.conf"
112-
regexp: '#(effective_cache_size\s=\s)[0-9]+\w\w'
113-
replace: '\1 {{ (ansible_memory_mb.real.total / 2) | int | abs }}MB'
114-
when: postgresql_server_tuning
115-
notify: Restart postgresql
116-
11792
- name: Configure pg_hba.conf
11893
become: true
11994
template:
@@ -126,15 +101,32 @@
126101
when: postgresql_pg_hba_conf is defined
127102
notify: Restart postgresql
128103

104+
- name: Create postgresql directory in /etc
105+
file:
106+
path: /etc/postgresql
107+
state: directory
108+
mode: 0755
109+
110+
- name: Link generated conf file with server one
111+
lineinfile:
112+
path: /var/lib/pgsql/data/postgresql.conf
113+
line: "include_if_exists = '/etc/postgresql/system-roles-internal.conf'"
114+
insertafter: "EOF"
115+
notify: Restart postgresql
116+
117+
- name: Generate postgresql system-roles-internal.conf
118+
become: true
119+
template:
120+
backup: true
121+
dest: "/etc/postgresql/system-roles-internal.conf"
122+
src: postgresql-internal.conf.j2
123+
mode: 0600
124+
owner: postgres
125+
group: postgres
126+
129127
- name: Generate postgresql system-roles.conf
130128
when: postgresql_server_conf is defined
131129
block:
132-
- name: Create postgresql directory in /etc
133-
file:
134-
path: /etc/postgresql
135-
state: directory
136-
mode: '0755'
137-
138130
- name: Generate postgresql system-roles.conf
139131
become: true
140132
template:

templates/postgresql-internal.conf.j2

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{{ ansible_managed | comment }}
2+
3+
{% if postgresql_server_tuning %}
4+
shared_buffers = {{ (ansible_memory_mb.real.total / 4) | int | abs }}MB
5+
effective_cache_size = {{ (ansible_memory_mb.real.total / 2) | int | abs }}MB
6+
{% endif %}
7+
{% if postgresql_ssl_enable %}
8+
ssl = on
9+
{% endif %}

0 commit comments

Comments
 (0)