ansible-role-postgresql/tasks/postgresql-config-deb.yml

145 lines
5.7 KiB
YAML

---
- name: postgresql-config-deb | Data directory for Deb/Ubuntu
when:
- psql_use_alternate_data_dir
- ansible_distribution_file_variety == "Debian"
tags: ['postgresql', 'postgres', 'pg_conf']
block:
- name: postgresql-config-deb | Create the postgresql data directory if it is not in the default place
ansible.builtin.file:
dest: "{{ psql_data_dir }}"
owner: postgres
group: postgres
mode: '700'
state: directory
- name: postgresql-config-deb | Set the postgresql data dir if it is different from the default
become: true
become_user: postgres
ansible.builtin.lineinfile:
path: "{{ psql_conf_dir }}/postgresql.conf"
regexp: "^data_directory\ ="
line: "data_directory = '{{ psql_data_dir }}'"
create: false
state: present
- name: postgresql-config-deb | Check if the new postgresql data directory has been populated already
ansible.builtin.stat:
path: "{{ psql_data_dir }}/.postgresql_data_dir"
register: postgresql_data_dir
- name: postgresql-config-deb | Stop the postgresql service while reconfiguring the data directory
ansible.builtin.service:
name: postgresql
state: stopped
when: not postgresql_data_dir.stat.exists
- name: postgresql-config-deb | Copy the postgresql data directory into the new place
ansible.builtin.shell:
cmd: |
if [ "/var/lib/postgresql/{{ psql_version | quote }}/main" != "{{ psql_data_dir | quote }}" ] ; then
cp -a /var/lib/postgresql/{{ psql_version | quote }}/main/* {{ psql_data_dir | quote }}
echo "Custom data dir" > "{{ psql_data_dir | quote }}/.postgresql_data_dir"
fi
args:
creates: '{{ psql_data_dir | quote }}/.postgresql_data_dir'
- name: postgresql-config-deb | Start the postgresql service that will use the new data directory
ansible.builtin.service:
name: postgresql
state: started
- name: postgresql-config-deb | Configuration of Deb/Ubuntu systems
when: ansible_distribution_file_variety == "Debian"
tags: ['postgresql', 'postgres', 'pg_conf']
block:
- name: postgresql-config-deb | Set some postgresql configuration parameters that require a db restart
become: true
become_user: postgres
community.postgresql.postgresql_set:
name: '{{ item.name }}'
value: "{% if item.set %}{{ item.value }}{% else %}default{% endif %}"
loop: '{{ psql_conf_parameters }}'
notify: Restart postgresql
- name: postgresql-config-deb | Set the postgresql logging configuration parameters
become: true
become_user: postgres
community.postgresql.postgresql_set:
name: '{{ item.name }}'
value: "{% if item.set %}{{ item.value }}{% else %}default{% endif %}"
loop: '{{ psql_log_configuration }}'
notify: Reload postgresql
tags: ['postgresql', 'postgres', 'pg_conf', 'pg_conf_log']
- name: postgresql-config-deb | Set the postgresql autovacuum configuration parameters
become: true
become_user: postgres
community.postgresql.postgresql_set:
name: '{{ item.name }}'
value: "{% if item.set %}{{ item.value }}{% else %}default{% endif %}"
loop: '{{ psql_autovacuum_configuration }}'
notify: Reload postgresql
tags: ['postgresql', 'postgres', 'pg_conf', 'pg_conf_autovacuum']
- name: postgresql-config-deb | Set the postgresql listen port
become: true
become_user: postgres
community.postgresql.postgresql_set:
name: 'port'
value: "{% if psql_listen_on_ext_int %}{{ psql_db_port }}{% else %}default{% endif %}"
notify: Restart postgresql
- name: postgresql-config-deb | We want postgres listen on the public IP
become: true
become_user: postgres
community.postgresql.postgresql_set:
name: 'listen_addresses'
value: "{% if psql_listen_on_ext_int %}*{% else %}default{% endif %}"
notify: Restart postgresql
- name: postgresql-config-deb | Custom configuration parameters
become: true
become_user: postgres
community.postgresql.postgresql_set:
name: '{{ item.name }}'
value: "{% if item.set %}{{ item.value }}{% else %}default{% endif %}"
loop: '{{ psql_conf_custom_parameters }}'
notify: Restart postgresql
- name: postgresql-config-deb | Flush flush_handlers Restart PostgreSQL
ansible.builtin.meta: flush_handlers
tags: ['postgresql', 'postgres', 'pg_hba', 'pg_conf']
- name: postgresql-config-deb | Log the connections
become: true
become_user: postgres
community.postgresql.postgresql_set:
name: 'log_connections'
value: "{% if psql_listen_on_ext_int %}on{% else %}default{% endif %}"
notify: Reload postgresql
- name: postgresql-config-deb | Log the disconnections
become: true
become_user: postgres
community.postgresql.postgresql_set:
name: 'log_disconnections'
value: "{% if psql_listen_on_ext_int is defined %}on{% else %}default{% endif %}"
notify: Reload postgresql
- name: postgresql-config-deb | Log the hostnames
become: true
become_user: postgres
community.postgresql.postgresql_set:
name: 'log_hostname'
value: "{% if psql_listen_on_ext_int %}on{% else %}default{% endif %}"
notify: Reload postgresql
- name: postgresql-config-deb | Flush flush_handlers Restart PostgreSQL
ansible.builtin.meta: flush_handlers
tags: ['postgresql', 'postgres', 'pg_hba', 'pg_conf']
- name: postgresql-config-deb | Flush flush_handlers Reload PostgreSQL
ansible.builtin.meta: flush_handlers
tags: ['postgresql', 'postgres', 'pg_hba', 'pg_conf']