65 lines
2.3 KiB
YAML
65 lines
2.3 KiB
YAML
---
|
|
# This playbook backups the odroid docker containers.
|
|
- name: Backup Strato Production
|
|
hosts: all
|
|
gather_facts: true
|
|
|
|
tasks:
|
|
- name: Backup odroid
|
|
block:
|
|
- include_vars: vars/mattermost.yaml
|
|
- include_vars: vars/strato-production.yaml
|
|
|
|
- name: Check if directories exist
|
|
stat:
|
|
path: "{{ backup_dir }}/{{ item }}"
|
|
register: dirs
|
|
loop: "{{ systems }}"
|
|
|
|
- name: Create not existing directories
|
|
file:
|
|
path: "{{ backup_dir }}/{{ item.item }}"
|
|
state: directory
|
|
mode: 0755
|
|
group: chris
|
|
owner: chris
|
|
when: item.stat.exists == false
|
|
with_items: "{{ dirs.results }}"
|
|
loop_control:
|
|
label: "{{ item.item }}"
|
|
|
|
- name: Backup mysql databases
|
|
shell: docker exec {{ item }}-db mysqldump -u{{ item }} -p{{ lookup('vars', item ~ '-password') }} {{ item }} > {{ backup_dir }}/{{ item }}/db-{{ ansible_date_time.iso8601_basic_short }}.sql
|
|
loop: "{{ mysql_databases }}"
|
|
|
|
- name: Compress database backup files
|
|
shell: gzip {{ backup_dir }}/{{ item }}/db-{{ ansible_date_time.iso8601_basic_short }}.sql
|
|
loop: "{{ databases }}"
|
|
|
|
- name: Inform Mattermost about success
|
|
uri:
|
|
url: "{{ mattermost_url }}"
|
|
method: POST
|
|
body_format: json
|
|
body:
|
|
channel_id: "{{ channel_id }}"
|
|
message: "{{ ansible_date_time.date }} {{ ansible_date_time.time }}: Playbook ran successful ({{ ansible_play_name }})"
|
|
headers:
|
|
Content-Type: application/json
|
|
Authorization: "Bearer {{ semaphore_token }}"
|
|
status_code: [200, 201]
|
|
|
|
rescue:
|
|
- name: Inform Mattermost about error
|
|
uri:
|
|
url: "{{ mattermost_url }}"
|
|
method: POST
|
|
body_format: json
|
|
body:
|
|
channel_id: "{{ channel_id }}"
|
|
message: "{{ ansible_date_time.date }} {{ ansible_date_time.time }}: Playbook ran with error ({{ ansible_play_name }})"
|
|
headers:
|
|
Content-Type: application/json
|
|
Authorization: "Bearer {{ error_token }}"
|
|
status_code: [200, 201]
|