-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_enable_postgresql.yml
47 lines (41 loc) · 1.05 KB
/
install_enable_postgresql.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
---
- name: install and start postgresql
hosts: all
vars:
packages:
- postgresql
- postgresql-server
- postgresql-contrib
- python3-psycopg2
tasks:
- name: install package
yum:
name: "{{ item }}"
state: installed
loop: "{{ packages }}"
- name: PostgreSQL | Check whether the postgres data directory is initialized | RedHat
stat:
path: "/var/lib/pgsql/data/PG_VERSION"
register: pgdata_dir_initialized
- name: Ensure PostgreSQL database is initialized.
command: "initdb -D /var/lib/pgsql/data"
become: true
become_user: postgres
become_method: sudo
when: not pgdata_dir_initialized.stat.exists
- name: start the service
service:
name: postgresql
state: started
enabled: yes
- name: start the firewall if not running
service:
name: firewalld
state: started
enabled: yes
- name: enable postgresql through firewall
firewalld:
service: postgresql
state: enabled
permanent: yes
immediate: yes