Skip to content

Commit

Permalink
feat(plugin): use template for postgresql config, improve lineinfile
Browse files Browse the repository at this point in the history
Add Ansible managed comments to lineinfile, update regexp
  • Loading branch information
adf-patrickha committed May 3, 2024
1 parent dbc65a1 commit b4d2cfd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
32 changes: 25 additions & 7 deletions tasks/plugins_postgresql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
- name: plugins_postgresql | Enable local peer access for root user
ansible.builtin.lineinfile:
path: "{{ bareos_fd_plugin_psql_config_hba }}"
line: "local all root peer"
regexp: '^local\\s+all\\s+root\\s+peer$' # match for any amount of spaces
line: >-
local all root peer # Ansible managed:
Do NOT remove line manually! Managed by bareos_fd role
regexp: '^local\s+all\s+root\s+peer' # match for any amount of spaces
state: present
backup: true
notify: Reload postgresql
Expand All @@ -17,16 +19,32 @@
mode: "0751"
path: "{{ bareos_fd_plugin_psql_wal_archive }}"

- name: plugins_postgresql | Enable archive mode in config
ansible.builtin.blockinfile:
- name: plugins_postgresql | Make sure postgres conf.d dir is present
ansible.builtin.file:
state: directory
owner: postgres
group: postgres
mode: "0755"
path: "{{ bareos_fd_plugin_psql_root_dir }}/conf.d"

- name: plugins_postgresql | Include conf.d dir in postgresql.conf
ansible.builtin.lineinfile:
path: "{{ bareos_fd_plugin_psql_config }}"
block: |
archive_mode = on
archive_command = 'test ! -f {{ bareos_fd_plugin_psql_wal_archive }}/%f && cp %p {{ bareos_fd_plugin_psql_wal_archive }}/%f'
line: >-
include_dir = 'conf.d' # Ansible managed:
Do NOT remove line manually! Managed by bareos_fd role
regexp: '^#?(\s+)?include_dir' # match also commented line
state: present
backup: true
notify: Reload postgresql

- name: plugins_postgresql | Deploy config for wal archive mode

Check failure on line 41 in tasks/plugins_postgresql.yml

View workflow job for this annotation

GitHub Actions / lint

risky-file-permissions

File permissions unset or incorrect.

Check failure on line 41 in tasks/plugins_postgresql.yml

View workflow job for this annotation

GitHub Actions / lint

risky-file-permissions

File permissions unset or incorrect.
ansible.builtin.template:
src: "templates/plugin_postgresql_bareos_wal_archive.conf.j2"
dest: "{{ bareos_fd_plugin_psql_root_dir }}/conf.d/bareos_postgresql_wal_archive.conf"
backup: true
notify: Reload postgresql

- name: plugins_postgresql | Create plugin_defaults file
ansible.builtin.template:
src: "templates/plugin_postgresql_defaults.ini.j2"
Expand Down
3 changes: 3 additions & 0 deletions templates/plugin_postgresql_bareos_wal_archive.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{ ansible_managed | comment }}
archive_mode = on
archive_command = 'test ! -f {{ bareos_fd_plugin_psql_wal_archive | default("") }}/%f && cp %p {{ bareos_fd_plugin_psql_wal_archive | default("") }}/%f'

0 comments on commit b4d2cfd

Please sign in to comment.