ansible-role-postgresql/tasks/initialize.yml

31 lines
984 B
YAML
Raw Permalink Normal View History

2020-09-06 18:50:02 +00:00
---
- name: Set PostgreSQL environment variables.
template:
src: postgres.sh.j2
dest: /etc/profile.d/postgres.sh
mode: 0644
2023-12-23 09:14:46 +00:00
notify: Restart postgresql
2020-09-06 18:50:02 +00:00
- name: Ensure PostgreSQL data directory exists.
file:
path: "{{ postgresql_data_dir }}"
owner: "{{ postgresql_user }}"
group: "{{ postgresql_group }}"
state: directory
mode: 0700
- name: Check if PostgreSQL database is initialized.
stat:
path: "{{ postgresql_data_dir }}/PG_VERSION"
register: pgdata_dir_version
- name: Ensure PostgreSQL database is initialized.
2024-01-02 19:54:52 +00:00
command: "{{ postgresql_bin_path }}/initdb -D {{ postgresql_data_dir }} --locale=C.UTF-8 --encoding=UTF8 --data-checksums"
when: not pgdata_dir_version.stat.exists and (postgres_consul_tag is not defined or postgres_consul_tag == "active")
2020-09-06 18:50:02 +00:00
become: true
become_user: "{{ postgresql_user }}"
# See: https://github.com/ansible/ansible/issues/16048#issuecomment-229012509
vars:
ansible_ssh_pipelining: true