xoxys.postgres/tasks/install.yml

40 lines
1.1 KiB
YAML
Raw Normal View History

2018-10-14 22:11:01 +00:00
---
- block:
- name: Install PostgreSQL
package:
name: "{{ item }}"
state: present
2018-10-15 22:07:17 +00:00
with_items: "{{ __postgres_packages }}"
- name: Ensure data directory exists
file:
path: "{{ __postgres_data_dir }}"
owner: "{{ postgres_user }}"
group: "{{ postgres_group }}"
state: directory
mode: 0700
2018-10-15 22:23:42 +00:00
- name: Setup custom systemd service
2018-10-15 22:07:17 +00:00
template:
src: etc/systemd/system/postgresql.service.j2
2018-10-15 22:13:13 +00:00
dest: "/etc/systemd/system/{{ __postgres_daemon }}.service"
2018-10-15 22:07:17 +00:00
mode: 0644
notify: __postgres_restart
2018-10-15 22:23:42 +00:00
register: __postgres_systemd
2018-10-15 22:27:43 +00:00
- name: Force systemd to re-read configs
2018-10-15 22:23:42 +00:00
systemd:
daemon_reload: True
when: __postgres_systemd.changed
- name: Check if database is initialized
stat:
2018-10-15 22:27:43 +00:00
path: "{{ __postgres_data_dir }}/PG_VERSION"
2018-10-15 22:24:24 +00:00
register: __pgdata_dir_version
- name: Ensure database is initialized
command: "/usr/pgsql-{{ __postgres_version }}/bin/postgresql-{{ __postgres_version }}-setup initdb"
2018-10-15 22:24:24 +00:00
when: not __pgdata_dir_version.stat.exists
2018-10-14 22:11:01 +00:00
become: True
become_user: root