Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
ee7c7a1
Added ansible-postgres to connectbox
derekmaxson Dec 8, 2020
5038fa3
Added role to main.yml
derekmaxson Dec 8, 2020
c72b519
Permit trust access from UNIX and localhost
derekmaxson Dec 8, 2020
70217f1
Adding Moodle
derekmaxson Dec 8, 2020
790c0f5
Changing some files and settings
derekmaxson Dec 9, 2020
ad47643
PHP Initial Checkin
derekmaxson Dec 9, 2020
b9177cd
Remove PHP
derekmaxson Jan 4, 2021
96e4d75
Set password and authorization scheme for postgres
derekmaxson Jan 4, 2021
59108ca
PHP installation
derekmaxson Jan 5, 2021
350f08b
nginx add moodle to sites
derekmaxson Jan 5, 2021
2fa51d5
Moodle installation
derekmaxson Jan 5, 2021
9bfcc4a
Add new roles
derekmaxson Jan 5, 2021
ee2598e
Remove ansible-role-moodle-master and replace with custom role
derekmaxson Jan 5, 2021
490b422
Fix moodle nginx config to fix the CSS issues
derekmaxson Jan 5, 2021
a000526
Set moodledata directory permissions to 755 which Moodle requires
derekmaxson Jan 6, 2021
be36f44
Delete Old, Then Create A Moodle Database From Template
derekmaxson Jan 6, 2021
6668a84
Default Moodle Template Database
derekmaxson Jan 6, 2021
986d0da
Re-imaged the database
derekmaxson Jan 6, 2021
215b05a
Set default password for Moodle admin access
derekmaxson Jan 6, 2021
164f6c5
Set default name of hostname to connectbox -- but if env variable for…
derekmaxson Jan 6, 2021
413a34c
Pull Moodle from new Relay Trust git repo for Moodle customization
derekmaxson Jan 6, 2021
3c1f85f
Use default variable for hostname
derekmaxson Jan 6, 2021
9c6ee93
Moved from PHP to Moodle because Moodle restore requires empty directory
derekmaxson Jan 6, 2021
39d12c6
Move info.php install into the Moodle tasks
derekmaxson Jan 6, 2021
ac33ecf
Comments regarding ansible installation
derekmaxson Jan 6, 2021
6fcf09e
Update all the vhosts
derekmaxson Jan 13, 2021
31f8aa4
Update .gitignore
derekmaxson Jan 13, 2021
8fb1837
Fix the owner and group to be www-data for moodle
derekmaxson Jan 14, 2021
60f0c38
Change to PHP 7.3
derekmaxson Jan 14, 2021
8663fc0
Change to PHP 7.3
derekmaxson Jan 14, 2021
ce47b59
In process of determining the correct config for Moodle plus CB web s…
derekmaxson Jan 14, 2021
2085377
This does work as expected
derekmaxson Jan 19, 2021
48f5c33
Use global configuration for hostname
derekmaxson Jan 19, 2021
eeb4d60
Resolved this (read more)
derekmaxson Jan 19, 2021
0c59e64
Remove ipv6
derekmaxson Jan 19, 2021
118ef42
Update README.md
derekmaxson Jan 29, 2021
af2f4bf
Set default hostname, QR code for login, generic user account
derekmaxson Feb 3, 2021
b72ffea
Increase upload size to 200M
derekmaxson Feb 4, 2021
ca34886
overwrite_database=true in ansible will remove existing moodle databa…
derekmaxson Feb 4, 2021
064f7ef
Rebaseline the database to 3.10
derekmaxson Feb 8, 2021
44f5d98
Increase upload amounts
derekmaxson Feb 8, 2021
f2b0a0f
Increase upload amounts
derekmaxson Feb 8, 2021
bcc8786
Switch for indicating delete and rebuild Moodle Postgres database
derekmaxson Feb 8, 2021
23d2646
Moodle: tmpfs from moodlebox, 3.10 Moodle, Cron
derekmaxson Feb 8, 2021
6785876
Fully updated for Moodle 3.10
derekmaxson Feb 9, 2021
2c9e0f3
Update .gitignore
derekmaxson Feb 9, 2021
60a560f
Adjust tmpfs partitions for maximum upload space
derekmaxson Feb 10, 2021
01e3655
Update .gitignore
derekmaxson Feb 15, 2021
c3bae0b
Re-Enable Captive Portal, Admin & Local File Serving
derekmaxson Feb 15, 2021
28dad65
Fix overwrite sequence to not use old dump file
derekmaxson Feb 15, 2021
50eac47
Update moodle_database_template.dump
derekmaxson Feb 15, 2021
17c4b89
Update README.md
derekmaxson Feb 15, 2021
c2864de
Update .gitignore
derekmaxson Feb 26, 2021
7850e8f
Set cron to every 15 minutes
derekmaxson Feb 26, 2021
6c0f184
Fix some overwrite_database issues
derekmaxson Mar 22, 2021
93a8d64
Add from_rocketchat field
derekmaxson Mar 22, 2021
1b7f7fc
WHen AWS, don't setup RAM drive
derekmaxson Mar 22, 2021
9df527d
Add from_rocketchat field to mdl_messages table
derekmaxson Mar 24, 2021
558aba8
Add Buster repo for PHP
derekmaxson Mar 27, 2021
0fbcc55
Merge branch 'postgres-20201208' of https://github.com/RT-coding-team…
derekmaxson Mar 27, 2021
89bb078
Update .gitignore
derekmaxson Mar 27, 2021
8c08722
Merge branch 'master' into postgres-20201208
derekmaxson Mar 27, 2021
e98741d
Merge pull request #1 from RT-coding-team/postgres-20201208
derekmaxson Mar 27, 2021
eb598a5
Fix for debian vs stretch
derekmaxson Mar 28, 2021
e77bead
Merge pull request #2 from RT-coding-team/develop
derekmaxson Mar 28, 2021
42e2b26
Ensure that we are set to pi for raspian
derekmaxson Mar 29, 2021
075708d
Merge branch 'master' into postgres-20201208
derekmaxson Mar 29, 2021
90c7ab1
Merge pull request #3 from RT-coding-team/postgres-20201208
derekmaxson Mar 29, 2021
bc2d595
Change domain name for moodle to learn.SERVERNAME and regular content…
derekmaxson Apr 13, 2021
9abb3b6
Raspbian uses pi as the username
derekmaxson Apr 16, 2021
0100fe1
Check for Raspbian
derekmaxson Apr 16, 2021
873ec55
More flexible installation of PHP. Currently version 7.4
derekmaxson Apr 16, 2021
1e2dab8
Creating /var/www/moodledata directory at beginning
derekmaxson Apr 16, 2021
1737ac4
Revert "Check for Raspbian"
derekmaxson Apr 16, 2021
821df5e
Partitioning: full code implementation
derekmaxson Apr 19, 2021
da3e57f
MYSQL runs Moodle fully
derekmaxson Apr 19, 2021
8ddd1c5
Autorun course restore on courses found on USB
derekmaxson Apr 19, 2021
c4ea496
Fix the quotes around this command the wrong flag on the ipTables
derekmaxson Apr 19, 2021
b7fb5fa
Updated Readme for recent Well changes with MySQL
derekmaxson Apr 21, 2021
2813d0d
Fixes an issue on new OS
derekmaxson Apr 28, 2021
3ee49b1
Make sure that we update the apt cache prior to installation
derekmaxson Apr 28, 2021
2618fd8
Only do crda on pi
derekmaxson Apr 28, 2021
1d7ed99
Default Moodle Database and Files
derekmaxson Apr 28, 2021
bbc66b2
Updated moodle config and database restore process
derekmaxson Apr 28, 2021
7d68f2e
Merge pull request #4 from RT-coding-team/develop
derekmaxson Apr 28, 2021
8e975a6
Restoring Postgres
derekmaxson May 3, 2021
a8fc956
Add ffmpeg for file compression
derekmaxson May 8, 2021
c585f75
Update crons
derekmaxson Jun 1, 2021
43521ce
Re-Add Postgres in Ansible
derekmaxson Jun 1, 2021
46f5fb6
Add in files and sitename
derekmaxson Jun 1, 2021
2d24ed9
Force all existing user sessions out prior to reloading database
derekmaxson Jun 2, 2021
521772c
Incremental Update of Default Settings
derekmaxson Jun 2, 2021
9c44bea
Incremental Default Checkin
derekmaxson Jun 2, 2021
782d5c5
Remove entries in config changes log
derekmaxson Jun 2, 2021
e736451
Final Beta Defaults
derekmaxson Jun 2, 2021
e662b63
Remove User Account
derekmaxson Jun 2, 2021
ac20390
Download App Support
derekmaxson Jun 2, 2021
b8173c8
Rename
derekmaxson Jun 2, 2021
81c8a2b
Rename
derekmaxson Jun 2, 2021
79e8973
Use Android Icon For Download
derekmaxson Jun 3, 2021
df5acf8
Use default hostname as the SSID
derekmaxson Jun 3, 2021
e0700bd
Make sure that we do the initial build
derekmaxson Jun 3, 2021
bcbf94f
Delete mariadb database dump because we use postgres
derekmaxson Jun 3, 2021
0560b11
Defaults
derekmaxson Jun 4, 2021
b3bd501
Ignore wifi errors
derekmaxson Jun 4, 2021
f6cbd0f
Remove mysql item that is unused
derekmaxson Jun 4, 2021
35a1ca6
Default Password
derekmaxson Jun 4, 2021
df9e71e
resizer and password changes
derekmaxson Jun 4, 2021
5ec281b
Add Well configs: moodle-security-key, course-download
derekmaxson Jun 22, 2021
04b4746
Upon connection of USB data, create a backup and write it to the USB
derekmaxson Jun 24, 2021
5b62b64
Wipe Function for Poison Pill for compromised Well boxes
derekmaxson Jun 29, 2021
12b2c40
Create awsinstall.md
derekmaxson Jul 1, 2021
9fcc9f6
Update README.md
derekmaxson Jul 1, 2021
d55b331
Update README.md
derekmaxson Jul 1, 2021
ab51880
Remove moodle-security-key from this script. Handling in push_messag…
derekmaxson Jul 1, 2021
6bcf822
Create createimage.md
derekmaxson Jul 2, 2021
b1875c6
Rename
derekmaxson Jul 2, 2021
11166f9
Update simplified_making_an_image.md
derekmaxson Jul 5, 2021
80beb32
Correct comments
derekmaxson Jul 7, 2021
681a5ce
Remove default because we don't need this
derekmaxson Aug 2, 2021
cbf4163
Add Moodle location to /etc/hosts
derekmaxson Aug 2, 2021
960142a
Add in lines for debug display of Moodle. Uncomment to activate
derekmaxson Aug 3, 2021
77f9797
Remove partition for moodledata
derekmaxson Aug 4, 2021
2e0b6e6
Adjust moodledata configuration
derekmaxson Aug 4, 2021
e31296d
DNS configuration for http://learn.thewell
derekmaxson Aug 4, 2021
1985bf9
Delete home_pi_resizer_pl.j2
derekmaxson Aug 16, 2021
a0d28a3
Don't execute the resizer here. This needs to go into /boot/cmdline.txt
derekmaxson Aug 16, 2021
ec9d2da
Update .gitignore
derekmaxson Aug 16, 2021
4ed5140
Fix link to 8812au driver
derekmaxson Sep 8, 2021
c62cfc7
Use whatever version of PHP we can get
derekmaxson Sep 8, 2021
01c4d00
Only build moodle when requested
derekmaxson Sep 8, 2021
c9a603d
Fix for gunicorn and other services to use established known good ver…
derekmaxson Oct 11, 2021
5e5a845
Add brand.txt for configs on the hat's display
derekmaxson Oct 11, 2021
d05aba0
Add ACL to fix issue with installing postgres
derekmaxson Oct 11, 2021
a94625f
Add brand getters/setters to api.py
Leonils Nov 21, 2021
770b6c0
Merge pull request #9 from Leonils/patch-1
derekmaxson Nov 21, 2021
177015a
Update README.md
derekmaxson Mar 31, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ ci/inventory
ghostdriver.log
ci/terraform.tfstate*
ansible/inventory
makenewimage.sh
ansible/inventory-*
makenewimage.pl
copyimagetosd.pl
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# --------------------------------
# --------------------------------
# --------------------------------
# ABANDONED
You can access the latest code: https://github.com/ConnectBox/connectbox-pi
# --------------------------------



[![Build Status](https://travis-ci.org/ConnectBox/connectbox-pi.svg?branch=master)](https://travis-ci.org/ConnectBox/connectbox-pi)

# TheWell version of ConnectBox

TheWell is a variant of ConnectBox that adds Moodle Learning Management System (v. 3.9.3), PHP (v. 7.4) and MySQL (MariaDB) (vv 10.3) to bring training system and learning content to the ConnectBox platform.

Summary Of Changes:
* ConnectBox Ansible roles are updated to build ConnectBox with Moodle, PHP and MySQL
* TheWell is for Debian OS (Raspbian) on Raspberry Pi (with modifications) or other Linux host
* Refer to Relay Trust Moodle Repo for Documentation Of Changes
* Default Moodle MySQL database is located in this repo under ansible/roles/moodle/templates/
* Legacy Connectbox File Serving is now at {{{hostname}}} such that Connectbox is http://thewell, Moodle is http://learn.thewell and Admin is http://thewell/admin
* (There will be more as this gets built out)

# ConnectBox

ConnectBox is a media sharing device based on small form factor computers including the Raspberry Pi 3, Raspberry Pi Zero W, NanoPi NEO, Orange Pi Zero and Pine64.
Expand All @@ -8,6 +29,10 @@ ConnectBox is a media sharing device based on small form factor computers includ

See [docs/deployment.md](docs/deployment.md)

# Making a Connectbox on AWS

See [docs/awsinstall.md](docs /docs/awsinstall.md)

# Connectbox setup and administration

See [docs/administration.md](docs/administration.md)
Expand All @@ -17,4 +42,4 @@ See [docs/administration.md](docs/administration.md)
See [docs/development.md](docs/development.md)

# MicroSD Card Images/Releases
See [https://github.com/ConnectBox/connectbox-pi/releases/](https://github.com/ConnectBox/connectbox-pi/releases/)
TBD
3 changes: 3 additions & 0 deletions ansible/group_vars/all
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ connectbox_config_root: /etc/connectbox
connectbox_usb_files_root: /media/usb0
connectbox_admin_credentials: admin:$apr1$CBOX2018$RlXBoHRRoiG3vMC7PS07q.
connectbox_default_hostname: connectbox
connectbox_logo: connectbox_logo.png
connectbox_log_dir: /var/log/connectbox
connectbox_access_log: "{{ connectbox_log_dir }}/connectbox-access.log"
connectbox_error_log: "{{ connectbox_log_dir }}/connectbox-error.log"

access_log_analyzer_repo: https://github.com/ConnectBox/access-log-analyzer.git
connectbox_client_repo: https://github.com/ConnectBox/connectbox-react-icon-client.git
connectbox_client_path: published/
connectbox_system_password: "!1TheWell"
build_moodle: False

nginx_admin_block: |
location /admin/api {
Expand Down
6 changes: 3 additions & 3 deletions ansible/group_vars/raspbian
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
connectbox_os: raspbian
ansible_user: root
ansible_user: pi

client_facing_if: "wlan1"
eth_facing_if: "wlan0"
client_facing_if: "wlan0"
eth_facing_if: "eth0"
182 changes: 182 additions & 0 deletions ansible/roles/ansible-postgresql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
PostgreSQL
==========

An [Ansible][ansible] role for installing and managing [PostgreSQL][postgresql] servers. This role works with both
Debian and RedHat based systems, and provides backup scripts for [PostgreSQL Continuous Archiving and Point-in-Time
Recovery][postgresql_pitr].

On RedHat-based platforms, the [PostgreSQL Global Development Group (PGDG) packages][pgdg_yum] packages will be
installed. On Debian-based platforms, you can choose from the distribution's packages (from APT) or the [PGDG
packages][pgdg_apt].

[ansible]: http://www.ansible.com/
[postgresql]: http://www.postgresql.org/
[postgresql_pitr]: http://www.postgresql.org/docs/9.4/static/continuous-archiving.html
[pgdg_yum]: http://yum.postgresql.org/
[pgdg_apt]: http://apt.postgresql.org/

**Changes that require a restart will not be applied unless you manually restart PostgreSQL.** This role will reload the
server for those configuration changes that can be updated with only a reload because reloading is a non-intrusive
operation, but options that require a full restart will not cause the server to restart.

Requirements
------------

This role requires Ansible 2.4+

Role Variables
--------------

### All variables are optional ###

- `postgresql_user_name`: System username to be used for PostgreSQL (default: `postgres`).

- `postgresql_version`: PostgreSQL version to install. On Debian-based platforms, the default is whatever version is
pointed to by the `postgresql` metapackage). On RedHat-based platforms, the default is `10`.

- `postgresql_flavor`: On Debian-based platforms, this specifies whether you want to use PostgreSQL packages from pgdg
or the distribution's apt repositories. Possible values: `apt`, `pgdg` (default: `apt`).

- `postgresql_conf`: A list of hashes (dictionaries) of `postgresql.conf` options (keys) and values. These options are
not added to `postgresql.conf` directly - the role adds a `conf.d` subdirectory in the configuration directory and an
include statement for that directory to `postgresql.conf`. Options set in `postgresql_conf` are then set in
`conf.d/25ansible_postgresql.conf`. For legacy reasons, this can also be a single hash, but the list syntax is
preferred because it preserves order.

Due to YAML parsing, you must take care when defining values in
`postgresql_conf` to ensure they are properly written to the config file. For
example:

```yaml
postgresql_conf:
- max_connections: 250
- archive_mode: "off"
- work_mem: "'8MB'"
```

Becomes the following in `25ansible_postgresql.conf`:

```
max_connections = 250
archive_mode = off
work_mem: '8MB'
```

- `postgresql_pg_hba_conf`: A list of lines to add to `pg_hba.conf`

- `postgresql_pg_hba_local_postgres_user`: If set to `false`, this will remove the `postgres` user's entry from
`pg_hba.conf` that is preconfigured on Debian-based PostgreSQL installations. You probably do not want to do this
unless you know what you're doing.

- `postgresql_pg_hba_local_socket`: If set to `false`, this will remove the `local` entry from `pg_hba.conf` that is
preconfigured by the PostgreSQL package.

- `postgresql_pg_hba_local_ipv4`: If set to `false`, this will remove the `host ... 127.0.0.1/32` entry from
`pg_hba.conf` that is preconfigured by the PostgreSQL package.

- `postgresql_pg_hba_local_ipv6`: If set to `false`, this will remove the `host ... ::1/128` entry from `pg_hba.conf`
that is preconfigured by the PostgreSQL package.

- `postgresql_pgdata`: Only set this if you have changed the `$PGDATA` directory from the package default. Note this
does not configure PostgreSQL to actually use a different directory, you will need to do that yourself, it just allows
the role to properly locate the directory.

- `postgresql_conf_dir`: As with `postgresql_pgdata` except for the configuration directory.

### Backups ###

- `postgresql_backup_dir`: If set, enables [PITR][postgresql_pitr] backups. Set this to a directory where your database
will be backed up (this can be any format supported by rsync, e.g. `user@host:/path`). The most recent backup will be
in a subdirectory named `current`.

- `postgresql_backup_rotate`: Boolean, defaults to `true`, which will cause the `current` directory to be renamed prior
to creating a new backup. If set to `false`, `current` will be deleted (this is useful if you are using snapshots or
some other means to archive previous backups).

- `postgresql_backup_local_dir`: Filesystem path on the PostgreSQL server where backup scripts will be placed and
working WALs will be written prior to a WAL archive.

- `postgresql_backup_[hour|minute]`: Controls what time the cron job will run to perform a full backup. Defaults to 1:00
AM.

- `postgresql_backup_[day|month|weekday]`: Additional cron controls for when the full backup is performed (default:
`*`).

- `postgresql_backup_mail_recipient`: User or address that should receive mail from the backup scripts.

- `postgresql_backup_remote_rsync_path`: Path to `rsync` on the remote system.

- `postgresql_backup_post_command`: Arbitrary command to run after successful completion of a scheduled backup.

Dependencies
------------

None

Example Playbook
----------------

Standard install: Default `postgresql.conf`, `pg_hba.conf` and default version for the OS:

```yaml
---

- hosts: dbservers
remote_user: root
roles:
- postgresql
```

Use the pgdg packages on a Debian-based host:

```yaml
---

- hosts: dbservers
remote_user: root
vars:
postgresql_flavor: pgdg
roles:
- postgresql
```

Use the PostgreSQL 9.5 packages and set some `postgresql.conf` options and `pg_hba.conf` entries:

```yaml
---

- hosts: dbservers
remote_user: root
vars:
postgresql_version: 9.5
postgresql_conf:
- listen_addresses: "''" # disable network listening (listen on unix socket only)
- max_connections: 50 # decrease connection limit
postgresql_pg_hba_conf:
- host all all 10.0.0.0/8 md5
roles:
- postgresql
```

Enable backups to /archive

```yaml
- hosts: all
remote_user: root
vars:
postgresql_backup_dir: /archive
roles:
- postgresql
```

License
-------

[Academic Free License ("AFL") v. 3.0][afl]

[afl]: http://opensource.org/licenses/AFL-3.0

Author Information
------------------

[Nate Coraor](https://github.com/natefoo)
10 changes: 10 additions & 0 deletions ansible/roles/ansible-postgresql/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---

postgresql_backup_local_dir: ~postgres/backup
postgresql_backup_active_dir: "{{ postgresql_backup_local_dir }}/active"
postgresql_backup_mail_recipient: postgres
postgresql_backup_rotate: true
postgresql_user_name: postgres
postgresql_user_password: mypassword

postgresql_archive_wal_rsync_args: '--ignore-existing -ptg --info=skip1'
35 changes: 35 additions & 0 deletions ansible/roles/ansible-postgresql/files/get_repo_rpm_release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python
"""
Determine the latest version of the yum repository package.

usage: get_repo_rpm_version.py url distribution

e.g.:

get_repo_rpm_version.py http://yum.postgresql.org/9.2/redhat/rhel-6-x86_64/ centos
"""

import re
import sys
import urllib2

url, dist = sys.argv[1:]

try:
repo = urllib2.urlopen(url)
except urllib2.HTTPError, e:
print >>sys.stderr, "Failed to fetch directory list from %s" % url
raise

pg_version = url.split('/')[3]
if pg_version[0] == "8" and dist != "sl":
re_pattern = 'href=[\'"](pgdg-%s-%s-[\d+].noarch.rpm)[\'"]' % (dist, pg_version)
else:
re_pattern = 'href=[\'"](pgdg-%s%s-%s-[\d+].noarch.rpm)[\'"]' % (dist, pg_version.replace('.', ''), pg_version)
match = re.findall(re_pattern, repo.read(), flags=re.I)

assert match, "No matching %s pgdg repository packages found for version %s at %s" % (dist, pg_version, url)

print match[0]

sys.exit(0)
4 changes: 4 additions & 0 deletions ansible/roles/ansible-postgresql/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---

- name: Reload PostgreSQL
service: name={{ postgresql_service_name }} state=reloaded
26 changes: 26 additions & 0 deletions ansible/roles/ansible-postgresql/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
galaxy_info:
author: The Galaxy Project
description: Install and manage a PostgreSQL (http://www.postgresql.org/) server.
company: The Galaxy Project
license: AFL v3.0
min_ansible_version: 2.4
platforms:
- name: EL
versions:
- all
- name: Fedora
versions:
- all
- name: Ubuntu
versions:
- all
- name: Debian
versions:
- all
galaxy_tags:
- database
- sql
- postgres
- postgresql
dependencies: []
56 changes: 56 additions & 0 deletions ansible/roles/ansible-postgresql/tasks/backup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---

- name: Create backup directories
file:
owner: postgres
group: postgres
mode: 0750
state: directory
path: "{{ item }}"
with_items:
- "{{ postgresql_backup_local_dir }}"
- "{{ postgresql_backup_local_dir }}/bin"
- "{{ postgresql_backup_active_dir }}"

- name: Install backup scripts
template:
src: "{{ item }}.j2"
dest: "{{ postgresql_backup_local_dir }}/bin/{{ item }}"
owner: postgres
group: postgres
mode: 0750
with_items:
- backup_working_wal.sh
- archive_wal.sh
- scheduled_backup.sh

- name: Set WAL archive config options
template:
src: 20ansible_backup.conf.j2
dest: "{{ postgresql_conf_dir }}/conf.d/20ansible_backup.conf"
owner: postgres
group: postgres
backup: yes
notify: Reload PostgreSQL

- name: Schedule backups
cron:
name: "PostgreSQL Backup"
cron_file: ansible_postgresql_backup
user: postgres
hour: "{{ postgresql_backup_hour | default(1) }}"
minute: "{{ postgresql_backup_minute | default(0) }}"
day: "{{ postgresql_backup_day | default(omit) }}"
month: "{{ postgresql_backup_month | default(omit) }}"
weekday: "{{ postgresql_backup_weekday | default(omit) }}"
job: >-
{{ postgresql_backup_local_dir }}/bin/scheduled_backup.sh{{
' && ' ~ postgresql_backup_post_command if postgresql_backup_post_command is defined else ''
}}

- name: Schedule PostgreSQL working WAL backup
cron:
name: "PostgreSQL WAL Backup"
cron_file: ansible_postgresql_walbackup
user: postgres
job: "{{ postgresql_backup_local_dir }}/bin/backup_working_wal.sh"
Loading