Ian Wienand a246df66b4 refstack: create database storage area
The mariadb container currently doesn't persist it's database
anywhere.  Map /var/lib/refstack/db to /var/lib/mysql in the
container.

We have /var/refstack and /var/lib/refstack with various things.
While we're here move everythign under /var/lib/refstack.

Also use 127.0.0.1 to ensure mysql doesn't try to connect over a
socket, but tcp (I think pymsql does anyway, but it's a little
clearer).

Change-Id: I5605eac2848a6b2222698bf20c707baa4442fcd5
2021-02-10 17:35:04 +11:00

141 lines
2.9 KiB
YAML

- name: Ensure docker-compose directory exists
file:
state: directory
path: /etc/refstack-docker
mode: 0700
- name: Write docker-compose file
template:
src: docker-compose.yaml.j2
dest: /etc/refstack-docker/docker-compose.yaml
mode: 0600
- name: Install apache2
apt:
name:
- apache2
- apache2-utils
state: present
- name: Apache modules
apache2_module:
state: present
name: "{{ item }}"
loop:
- rewrite
- proxy
- proxy_http
- ssl
- headers
- proxy_wstunnel
- name: Copy apache config
template:
src: refstack.vhost.j2
dest: /etc/apache2/sites-enabled/000-default.conf
owner: root
group: root
mode: 0644
notify: refstack Reload apache2
- name: Create refstack storage
file:
state: directory
path: /var/lib/refstack/
owner: root
group: root
mode: 0755
- name: Create refstack config storage area
file:
state: directory
path: /var/lib/refstack/etc
owner: root
group: root
mode: 0755
- name: Create refstack data storage area
file:
state: directory
path: /var/lib/refstack/data
owner: root
group: root
mode: 0755
- name: Create refstack www storage area
file:
state: directory
path: /var/lib/refstack/www
owner: root
group: root
mode: 0755
- name: Create refstack db storage area
file:
state: directory
path: /var/lib/refstack/db
owner: root
group: root
mode: 0755
- name: Copy hound robots.txt
copy:
src: robots.txt
dest: /var/lib/refstack/www/robots.txt
- name: Write refstack.conf
template:
src: refstack.conf.j2
dest: /var/lib/refstack/etc/refstack.conf
- name: Write config.json
template:
src: config.json.j2
dest: /var/lib/refstack/etc/config.json
- name: Install distro packages
package:
name:
- docker-compose
state: present
- name: Run docker-compose pull
shell:
cmd: docker-compose pull
chdir: /etc/refstack-docker/
- name: Run docker-compose up
shell:
cmd: docker-compose up -d --timeout 60
chdir: /etc/refstack-docker/
- name: Run docker prune to cleanup unneeded images
shell:
cmd: docker image prune -f
- name: Create db backup dest
file:
state: directory
path: /var/backups/refstack-mariadb
mode: 0700
owner: root
group: root
- name: Set up cron job to backup the database
cron:
name: refstack-db-backup
state: present
user: root
job: >
/usr/bin/docker-compose -f /etc/refstack-docker/docker-compose.yaml exec -T mariadb
bash -c '/usr/bin/mysqldump --opt --databases refstack --single-transaction -uroot -p"$MYSQL_ROOT_PASSWORD"' |
gzip -9 > /var/backups/refstack-mariadb/refstack-mariadb.sql.gz
minute: "42"
hour: "4"
- name: Rotate db backups
include_role:
name: logrotate
vars:
logrotate_file_name: /var/backups/refstack-mariadb/refstack-mariadb.sql.gz