Hello everyone.
I need to fill the shared_preload_libraries property of the postgresql.conf file with the value pg_stat_statements. It can be empty or not.
Examples:
Case 1)
Initial state:
#shared_preload_libraries = ‘’ # (change requires restart)
Final result:
shared_preload_libraries = ‘pg_stat_statements ’ # (change requires restart)
Case 2)
Initial state:
shared_preload_libraries = ‘xxx,xxx2…,’ # (change requires restart)
Final result:
shared_preload_libraries = ‘xxx,xxx2…,pg_stat_statements ’ # (change requires restart)
What have you tried? Please post your problem code/results…
Seems like this could be done with the ansible.builtin.replace
module…
dnmvisser
(Dick Visser)
September 24, 2024, 4:06pm
3
Try this:
---
- hosts: pg_servers
vars:
path: postgresql.conf
splibs_regex: "^#?(shared_preload_libraries\\s+=\\s+')([^']*)('.*$)"
extra_splibs:
- pg_stat_statements
tasks:
- name: read file
ansible.builtin.slurp:
src: "{{ path }}"
register: pgconf
- ansible.builtin.set_fact:
matches: "{{ pgconf.content | b64decode | regex_search(splibs_regex, '\\1', '\\2', '\\3', multiline=True) }}"
- ansible.builtin.lineinfile:
path: "{{ path }}"
regexp: "{{ splibs_regex }}"
line: "{{ matches[0] ~ matches[1] | split(',') | reject('equalto', '') | union(extra_splibs) | join(',') ~ matches[2] }}"
when: matches
Hi dnmvisser,
I considered ‘localhost’ instead of ‘pg_servers’.
I got the error below:
"
…
TASK [ansible.builtin.lineinfile] ****************************************************************************************************************
fatal: [localhost]: FAILED! => {“msg”: “template error while templating string: no filter named ‘split’. String: {{ matches[0] ~ matches[1] | split(‘,’) | reject(‘equalto’, ‘’) | union(extra_splibs) | join(‘,’) ~ matches[2] }}”}
"
dnmvisser
(Dick Visser)
September 24, 2024, 6:23pm
5
try ansible.builtin.split
Sorry, The error persists:
TASK [ansible.builtin.lineinfile] ****************************************************************************************************************
fatal: [localhost]: FAILED! => {“msg”: “template error while templating string: no filter named ‘ansible.builtin.split’. String: {{ matches[0] ~ matches[1] | ansible.builtin.split(‘,’) | reject(‘equalto’, ‘’) | union(extra_splibs) | join(‘,’) ~ matches[2] }}”}
dnmvisser
(Dick Visser)
September 24, 2024, 7:38pm
7
what is the output of ‘ansible --version’ ?
1 Like
jiholland
(Jørn Ivar)
September 24, 2024, 7:47pm
8
I think maybe you are on an outdated version of Ansible. This:
what is the output of ‘ansible --version’ ?
dnmvisser
(Dick Visser)
September 25, 2024, 2:15am
10
That is EOL, use a supported version
Thanks for your help, but right now that’s not possible. I work in a company where upgrades take a long time.
Is there another way to do it?
dnmvisser
(Dick Visser)
September 25, 2024, 11:14am
13
|
Thanks for your help, but right now that’s not possible. I work in a company where upgrades take a long time.
Is there another way to do it?
Move to a company where upgrades are not such a problem
Or try one of the alternate installation methods, such as running it from a dedicated python venv.
chris
(Chris Croome)
September 25, 2024, 11:33am
14
Luiz_Gustavo:
Version: ansible 2.9.27
That version of Ansible doesn’t have the split
filter:
ansible.builtin.split filter – split a string into a list
New in ansible-core 2.11
ansible.builtin.split filter – split a string into a list — Ansible Community Documentation
Perhaps use the shell
module and one of these suggestions ?
Hi,
I really appreciate everyone’s help.
I’ll try to adapt it to what I need.