finish install process
This commit is contained in:
parent
39503cc756
commit
dabc0e5365
@ -2,4 +2,5 @@
|
||||
postgres_repository_enabled: False
|
||||
postgres_version: 10
|
||||
postgres_repository_filename: "Postgresql-{{ postgres_version | regex_replace('\\.') }}"
|
||||
postgres_packagename: postgresql
|
||||
postgres_user: postgres
|
||||
postgres_group: postgres
|
||||
|
10
handlers/main.yml
Normal file
10
handlers/main.yml
Normal file
@ -0,0 +1,10 @@
|
||||
---
|
||||
- name: Restart service
|
||||
service:
|
||||
name: "{{ __postgres_daemon }}"
|
||||
state: restarted
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
||||
listen: __postgres_restart
|
||||
become: True
|
||||
become_user: root
|
@ -4,8 +4,21 @@
|
||||
package:
|
||||
name: "{{ item }}"
|
||||
state: present
|
||||
with_items:
|
||||
- "{{ postgres_packagename }}"
|
||||
- "{{ postgres_packagename }}-server"
|
||||
with_items: "{{ __postgres_packages }}"
|
||||
|
||||
- name: Ensure data directory exists
|
||||
file:
|
||||
path: "{{ __postgres_data_dir }}"
|
||||
owner: "{{ postgres_user }}"
|
||||
group: "{{ postgres_group }}"
|
||||
state: directory
|
||||
mode: 0700
|
||||
|
||||
- name: Setup custom systemd unit
|
||||
template:
|
||||
src: etc/systemd/system/postgresql.service.j2
|
||||
dest: "etc/systemd/system/{{ __postgres_daemon }}.service"
|
||||
mode: 0644
|
||||
notify: __postgres_restart
|
||||
become: True
|
||||
become_user: root
|
||||
|
@ -1,3 +1,4 @@
|
||||
---
|
||||
- import_tasks: prepare.yml
|
||||
- import_tasks: install.yml
|
||||
- import_tasks: post_tasks.yml
|
||||
|
19
tasks/post_tasks.yml
Normal file
19
tasks/post_tasks.yml
Normal file
@ -0,0 +1,19 @@
|
||||
---
|
||||
- name: Ensure PostgreSQL is up and running
|
||||
service:
|
||||
name: "{{ postgresql-10 }}"
|
||||
state: started
|
||||
enabled: yes
|
||||
become: True
|
||||
become_user: root
|
||||
|
||||
- name: Check if database is initialized
|
||||
stat:
|
||||
path: "{{ postgresql_data_dir }}/PG_VERSION"
|
||||
register: pgdata_dir_version
|
||||
|
||||
- name: Ensure database is initialized
|
||||
command: "/usr/pgsql-{{ __postgres_version }}/bin/postgresql-{{ __postgres_version }}-setup initdb"
|
||||
when: not pgdata_dir_version.stat.exists
|
||||
become: true
|
||||
become_user: "{{ postgres_user }}"
|
@ -1,20 +1,16 @@
|
||||
---
|
||||
- block:
|
||||
- name: Add PostgreSQL repository
|
||||
- name: Load helper variables
|
||||
include_vars: "main.yml"
|
||||
|
||||
- name: Add PostgreSQL repository
|
||||
yum_repository:
|
||||
name: postgresql
|
||||
file: "{{ postgres_repository_filename }}"
|
||||
description: PostgreSQL yum repository
|
||||
baseurl: "https://download.postgresql.org/pub/repos/yum/{{ postgres_version }}/redhat/rhel-{{ ansible_distribution_major_version }}-{{ ansible_architecture }}"
|
||||
baseurl: "https://download.postgresql.org/pub/repos/yum/{{ __postgres_version }}/redhat/rhel-{{ ansible_distribution_major_version }}-{{ ansible_architecture }}"
|
||||
gpgcheck: yes
|
||||
enabled: yes
|
||||
gpgkey: "https://download.postgresql.org/pub/repos/yum/RPM-GPG-KEY-PGDG-{{ postgres_version }}"
|
||||
|
||||
- set_fact:
|
||||
postgres_packagename: "postgresql{{ postgres_version | regex_replace('\\.') }}"
|
||||
|
||||
- debug:
|
||||
msg: "Set PostgreSQL package name to '{{ postgres_packagename }}'"
|
||||
become: True
|
||||
become_user: root
|
||||
when: postgres_repository_enabled
|
||||
gpgkey: "https://download.postgresql.org/pub/repos/yum/RPM-GPG-KEY-PGDG-{{ __postgres_version }}"
|
||||
become: True
|
||||
become_user: root
|
||||
when: postgres_repository_enabled
|
||||
|
4
templates/etc/systemd/system/postgresql.service.j2
Normal file
4
templates/etc/systemd/system/postgresql.service.j2
Normal file
@ -0,0 +1,4 @@
|
||||
## {{ ansible_managed }}
|
||||
.include {{ __postgres_service_file }}
|
||||
[Service]
|
||||
Environment=PGDATA={{ __postgres_data_dir }}
|
10
vars/main.yml
Normal file
10
vars/main.yml
Normal file
@ -0,0 +1,10 @@
|
||||
---
|
||||
__postgres_version: "{{ postgres_version | regex_replace('\\.') }}"
|
||||
__postgres_packagename: "postgresql{{ __postgres_version }}"
|
||||
__postgres_daemon: "postgresql-{{ __postgres_version }}"
|
||||
__postgres_service_file: "/usr/lib/systemd/system/{{ __postgres_daemon }}.service"
|
||||
__postgres_packages:
|
||||
- "{{ __postgres_packagename }}"
|
||||
- "{{ __postgres_packagename }}-server"
|
||||
__postgres_data_dir: "/var/lib/pgsql/{{ __postgres_version }}/data"
|
||||
__postgres_config_path: "/var/lib/pgsql/data"
|
Loading…
Reference in New Issue
Block a user