Introduce notification for other playbooks.

This commit is contained in:
2021-11-23 15:38:00 +01:00
parent 9a2e5afe01
commit 3efcd0797c
2 changed files with 264 additions and 226 deletions

View File

@@ -5,61 +5,80 @@
gather_facts: true
tasks:
- include_vars: vars/hetzner/secret.yaml
- include_vars: vars/hetzner/variable.yaml
- name: Backup hetzner
block:
- include_vars: vars/hetzner/secret.yaml
- include_vars: vars/hetzner/variable.yaml
- name: Create backup directory
file:
path: "{{ backup_dir }}"
state: directory
- name: Create backup directory
file:
path: "{{ backup_dir }}"
state: directory
- name: Create customer directories
file:
path: "{{ backup_dir }}/{{ item.key }}"
state: directory
loop: "{{ lookup('dict', customers) }}"
loop_control:
label: "{{ item.key }}"
- name: Create customer directories
file:
path: "{{ backup_dir }}/{{ item.key }}"
state: directory
loop: "{{ lookup('dict', customers) }}"
loop_control:
label: "{{ item.key }}"
- name: Backup web directories
shell: tar cvfz {{ backup_dir }}/{{ item.key }}/web-{{ ansible_date_time.iso8601_basic_short }}.tar.gz {{ item. value.storage }}
when: item.value.storage is defined
loop: "{{ lookup('dict', customers) }}"
loop_control:
label: "{{ item.key }}"
- name: Backup web directories
shell: tar cvfz {{ backup_dir }}/{{ item.key }}/web-{{ ansible_date_time.iso8601_basic_short }}.tar.gz {{ item. value.storage }}
when: item.value.storage is defined
loop: "{{ lookup('dict', customers) }}"
loop_control:
label: "{{ item.key }}"
- name: Fetch web backups
fetch:
src: "{{ backup_dir }}/{{ item.key }}/web-{{ ansible_date_time.iso8601_basic_short }}.tar.gz"
dest: "{{ local_backup }}/{{ item.key }}/"
flat: yes
when: item.value.storage is defined
loop: "{{ lookup('dict', customers) }}"
loop_control:
label: "{{ item.key }}"
- name: Fetch web backups
fetch:
src: "{{ backup_dir }}/{{ item.key }}/web-{{ ansible_date_time.iso8601_basic_short }}.tar.gz"
dest: "{{ local_backup }}/{{ item.key }}/"
flat: yes
when: item.value.storage is defined
loop: "{{ lookup('dict', customers) }}"
loop_control:
label: "{{ item.key }}"
- name: Backup databases
shell: mysqldump -u{{ mysql_user }} -p{{ mysql_password }} {{ item.value.database }} > {{ backup_dir }}/{{ item.key }}/db-{{ ansible_date_time.iso8601_basic_short }}.sql
loop: "{{ lookup('dict', customers) }}"
loop_control:
label: "{{ item.key }}"
- name: Backup databases
shell: mysqldump -u{{ mysql_user }} -p{{ mysql_password }} {{ item.value.database }} > {{ backup_dir }}/{{ item.key }}/db-{{ ansible_date_time.iso8601_basic_short }}.sql
loop: "{{ lookup('dict', customers) }}"
loop_control:
label: "{{ item.key }}"
- name: Compress database backups
shell: gzip {{ backup_dir }}/{{ item.key }}/db-{{ ansible_date_time.iso8601_basic_short }}.sql
loop: "{{ lookup('dict', customers) }}"
loop_control:
label: "{{ item.key }}"
- name: Compress database backups
shell: gzip {{ backup_dir }}/{{ item.key }}/db-{{ ansible_date_time.iso8601_basic_short }}.sql
loop: "{{ lookup('dict', customers) }}"
loop_control:
label: "{{ item.key }}"
- name: Fetch database backups
fetch:
src: "{{ backup_dir }}/{{ item.key }}/db-{{ ansible_date_time.iso8601_basic_short }}.sql.gz"
dest: "{{ local_backup }}/{{ item.key }}/"
flat: yes
loop: "{{ lookup('dict', customers) }}"
loop_control:
label: "{{ item.key }}"
- name: Fetch database backups
fetch:
src: "{{ backup_dir }}/{{ item.key }}/db-{{ ansible_date_time.iso8601_basic_short }}.sql.gz"
dest: "{{ local_backup }}/{{ item.key }}/"
flat: yes
loop: "{{ lookup('dict', customers) }}"
loop_control:
label: "{{ item.key }}"
- name: Clean backup directory
file:
path: "{{ backup_dir }}"
state: absent
- name: Clean backup directory
file:
path: "{{ backup_dir }}"
state: absent
- name: Inform Mattermost about success
uri:
url: https://cs-mm.ddnss.de/hooks/og4ckuqet7fafb8kjuaigzuh7c
method: POST
body_format: json
body:
text: "{{ ansible_date_time.date }} {{ ansible_date_time.time }} (info): Playbook ran successful ({{ ansible_play_name }})"
rescue:
- name: Inform Mattermost about error
uri:
url: https://cs-mm.ddnss.de/hooks/og4ckuqet7fafb8kjuaigzuh7c
method: POST
body_format: json
body:
text: "{{ ansible_date_time.date }} {{ ansible_date_time.time }} (info): Playbook ran with error ({{ ansible_play_name }})"