Skip to content

Commit 0f5f798

Browse files
committed
PostgreSQL install
0 parents  commit 0f5f798

File tree

6 files changed

+117
-0
lines changed

6 files changed

+117
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Ansible: Opencast PostgreSQL Role
2+
=================================
3+
4+
This Ansible role installs and prepares a PostgreSQL database server for Opencast.
5+
6+
7+
Role Variables
8+
--------------
9+
10+
- `opencast_postgresql_version`
11+
- PostgreSQL major version to install (default: `12`)
12+
- Enables CentOS AppStream
13+
- `opencast_postgresql_user:`
14+
- Database user to create (default: `opencast`)
15+
- `opencast_postgresql_password`
16+
- Databse password for user (_required_)
17+
- `opencast_postgresql_database`
18+
- Database name (default: `opencast`)
19+
- `opencast_postgresql_connection_hosts`
20+
- List of hosts allowed to connect to database (default: `[127.0.0.1/32, ::1/128]`)
21+
22+
23+
Example Playbook
24+
----------------
25+
26+
Example of how to configure and use the role:
27+
28+
```yaml
29+
- hosts: servers
30+
become: true
31+
roles:
32+
- role: lkiesow.opencast_postgresql
33+
opencast_postgresql_password: secret
34+
```

defaults/main.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
3+
opencast_postgresql_version: 12
4+
opencast_postgresql_user: opencast
5+
opencast_postgresql_database: opencast
6+
opencast_postgresql_connection_hosts:
7+
- 127.0.0.1/32
8+
- ::1/128

handlers/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
- name: restart postgresql
3+
service:
4+
name: postgresql
5+
state: restarted

meta/main.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
galaxy_info:
2+
author: Lars Kiesow
3+
role_name: opencast_user
4+
namespace: lkiesow
5+
description: Install and prepare PostgreSQL for Opencast
6+
license: BSD-3-Clause
7+
min_ansible_version: 2.9
8+
galaxy_tags:
9+
- opencast
10+
platforms:
11+
- name: EL
12+
versions:
13+
- 8
14+
dependencies: []

tasks/main.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
3+
- name: install postgresql
4+
dnf:
5+
name:
6+
- '@postgresql:{{ opencast_postgresql_version }}/server'
7+
- '@postgresql:{{ opencast_postgresql_version }}/client'
8+
- python3-psycopg2
9+
state: present
10+
11+
- name: initialize database
12+
command:
13+
cmd: postgresql-setup --initdb
14+
creates: /var/lib/pgsql/data/postgresql.conf
15+
16+
- name: set auth to scram-sha-256
17+
lineinfile:
18+
path: /var/lib/pgsql/data/postgresql.conf
19+
regexp: '^password_encryption'
20+
line: "password_encryption = 'scram-sha-256'"
21+
notify: restart postgresql
22+
23+
- name: configure postgres access
24+
template:
25+
src: pg_hba.conf
26+
dest: /var/lib/pgsql/data/pg_hba.conf
27+
owner: postgres
28+
group: postgres
29+
mode: '0644'
30+
notify: restart postgresql
31+
32+
- name: start and enable postgresql
33+
service:
34+
name: postgresql
35+
state: started
36+
enabled: true
37+
38+
- name: create postgresql user
39+
become_user: postgres
40+
community.postgresql.postgresql_user:
41+
name: '{{ opencast_postgresql_user }}'
42+
password: '{{ opencast_postgresql_password }}'
43+
44+
- name: create database
45+
become: true
46+
become_user: postgres
47+
community.postgresql.postgresql_db:
48+
name: '{{ opencast_postgresql_database }}'
49+
owner: '{{ opencast_postgresql_user }}'

templates/pg_hba.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# "local" is for Unix domain socket connections only
2+
local all all peer
3+
4+
# allow TCP connections with possword from some hosts:
5+
{% for host in opencast_postgresql_connection_hosts %}
6+
host all all {{ host }} scram-sha-256
7+
{% endfor %}

0 commit comments

Comments
 (0)