Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 35 additions & 38 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
mode: 0700
register: pgdata_dir_exist

- name: PostgreSQL | Check whether the postgres data directory is empty
find:
paths: "{{postgresql_data_directory}}"
file_type: any
register: pgdata_files_found

- name: PostgreSQL | Make sure postgres tablespaces directories exist
file:
path: "{{ item }}"
Expand Down Expand Up @@ -63,44 +69,35 @@
when: ansible_os_family == "RedHat"
ignore_errors: yes

- name: PostgreSQL | Stop PostgreSQL | Debian
service:
name: "{{ postgresql_service_name }}"
state: stopped
become: yes
when: ansible_os_family == "Debian" and postgresql_cluster_reset and pgdata_dir_exist.changed

- name: PostgreSQL | Reset the cluster - drop the existing one | Debian
shell: pg_dropcluster {{ postgresql_version }} {{ postgresql_cluster_name }}
become: yes
become_user: "{{ postgresql_service_user }}"
when: ansible_os_family == "Debian" and postgresql_cluster_reset and pgdata_dir_exist.changed

- name: PostgreSQL | Reset the cluster - create a new one (with specified encoding and locale) | Debian
shell: >
pg_createcluster --locale {{ postgresql_locale }}
-e {{ postgresql_encoding }} -d {{ postgresql_data_directory }}
{{ postgresql_version }} {{ postgresql_cluster_name }}
--
{% if postgresql_data_checksums and postgresql_version is version_compare('9.3', '>=') %}--data-checksums{% endif %}
{% if postgresql_pwfile != "" %}--pwfile={{ postgresql_pwfile }} {% endif %}
{% if postgresql_wal_directory != "" and postgresql_version is version_compare('10', '<') %}--xlogdir={{ postgresql_wal_directory }} {% endif %}
{% if postgresql_wal_directory != "" and postgresql_version is version_compare('10', '>=') %}--waldir={{ postgresql_wal_directory }} {% endif %}
become: yes
become_user: "{{ postgresql_service_user }}"
when: ansible_os_family == "Debian" and postgresql_cluster_reset and pgdata_dir_exist.changed

- name: PostgreSQL | Update systemd | Debian
command: systemctl daemon-reload
become: yes
when: ansible_os_family == "Debian" and postgresql_cluster_reset and pgdata_dir_exist.changed

- name: PostgreSQL | Start PostgreSQL | Debian
service:
name: "{{ postgresql_service_name }}"
state: started
become: yes
when: ansible_os_family == "Debian" and postgresql_cluster_reset and pgdata_dir_exist.changed
- block:
- name: PostgreSQL | Stop PostgreSQL | Debian
service:
name: "{{ postgresql_service_name }}"
state: stopped
become: yes

- name: PostgreSQL | Reset the cluster - drop the existing one | Debian
shell: pg_dropcluster {{ postgresql_version }} {{ postgresql_cluster_name }}
become: yes
become_user: "{{ postgresql_service_user }}"

- name: PostgreSQL | Reset the cluster - create a new one (with specified encoding and locale) | Debian
shell: >
pg_createcluster --locale {{ postgresql_locale }}
-e {{ postgresql_encoding }} -d {{ postgresql_data_directory }}
{{ postgresql_version }} {{ postgresql_cluster_name }}
--
{% if postgresql_data_checksums and postgresql_version is version_compare('9.3', '>=') %}--data-checksums{% endif %}
{% if postgresql_pwfile != "" %}--pwfile={{ postgresql_pwfile }} {% endif %}
{% if postgresql_wal_directory != "" and postgresql_version is version_compare('10', '<') %}--xlogdir={{ postgresql_wal_directory }} {% endif %}
{% if postgresql_wal_directory != "" and postgresql_version is version_compare('10', '>=') %}--waldir={{ postgresql_wal_directory }} {% endif %}
become: yes
become_user: "{{ postgresql_service_user }}"

- name: PostgreSQL | Update systemd | Debian
command: systemctl daemon-reload
become: yes
when: ansible_os_family == "Debian" and (postgresql_cluster_reset or pgdata_files_found.matched == 0)

- name: PostgreSQL | Check whether the postgres data directory is initialized | RedHat
stat:
Expand Down
1 change: 1 addition & 0 deletions tests/vars.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
postgresql_data_directory: /data/postgresql
postgresql_port: 5433

postgresql_databases:
Expand Down