Initialize the database, start the service.

This commit is contained in:
Jeff Geerling 2016-09-29 11:59:22 -05:00
parent 51101f0a82
commit 44e1ae1930
7 changed files with 37 additions and 7 deletions

View File

@ -43,7 +43,7 @@ script:
|| (echo 'Idempotence test: fail' && exit 1)
# Check PostgreSQL status.
- 'docker exec -u postgres "$(cat ${container_id})" pg_ctl status'
- 'docker exec -u postgres "$(cat ${container_id})" pg_ctl -D /var/lib/pgsql/data status'
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/

View File

@ -19,6 +19,11 @@ Available variables are listed below, along with default values (see `defaults/m
postgresql_enablerepo: ""
TODO.
postgresql_user: postgres
postgresql_group: postgres
TODO.
postgresql_databases:

View File

@ -2,6 +2,11 @@
# RHEL/CentOS only. Set a repository to use for PostgreSQL installation.
postgresql_enablerepo: ""
postgresql_data_dir: /var/lib/pgsql/data
postgresql_user: postgres
postgresql_group: postgres
# Databases to ensure exist.
postgresql_databases: []
# - name: example

View File

@ -1,2 +0,0 @@
---
# TODO

19
tasks/initialize.yml Normal file
View File

@ -0,0 +1,19 @@
---
- 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.
command: "initdb -D {{ postgresql_data_dir }}"
when: pgdata_dir_version.stat.exists
become: yes
become_user: "{{ postgresql_user }}"

View File

@ -9,8 +9,13 @@
- include: setup-Debian.yml
when: ansible_os_family == 'Debian'
- name: Ensure PostgreSQL is started and enabled on boot.
service:
name: "{{ postgresql_daemon }}"
state: started
enabled: yes
# Configure PostgreSQL.
- include: configure.yml
- include: secure-installation.yml
- include: initialize.yml
- include: databases.yml
- include: users.yml

View File

@ -1,2 +0,0 @@
---
# TODO.