Files
ansible/nas.yaml

89 lines
2.6 KiB
YAML

---
# This playbook creates a backup of odroid and writes it to the nas.
- name: Backup odroid to nas.
hosts: all
gather_facts: false
tasks:
- name: Backup odroid
block:
- include_vars: vars/common/variable.yaml
- name: Wakeup the nas
community.general.wakeonlan:
mac: '54:04:a6:f1:9b:80'
- name: Wait nas is responding
wait_for_connection:
timeout: 120
delay: 5
sleep: 5
- name: Gathering facts
setup:
- name: Check mount point exists
file:
path: /media/nas
state: directory
- name: Mount nas volume
ansible.posix.mount:
src: 192.168.178.50:/export/data
path: /media/nas
state: mounted
fstype: nfs
become: yes
- name: Backup docker data to nas
shell: rsync -a --delete /media/backup/docker/ /media/nas/Odroid/docker
become: yes
- name: Backup hetzner data to nas
shell: rsync -a --delete /media/backup/hetzner/ /media/nas/Odroid/hetzner
become: yes
- name: Backup nextcloud data to nas
shell: rsync -a --delete /media/backup/nextcloud/ /media/nas/Odroid/nextcloud
become: yes
- name: Backup media to nas
shell: rsync -a --delete /media/backup/media/ /media/nas/Odroid/media
become: yes
- name: Umount nas volume
ansible.posix.mount:
path: /media/nas
state: unmounted
become: yes
- name: Inform Mattermost about success
uri:
url: https://cs-mm.ddnss.de/api/v4/posts
method: POST
body_format: json
body:
channel_id: gub5buudpffxjf6fc1abkas8jo
message: "{{ ansible_date_time.date }} {{ ansible_date_time.time }} (info): Playbook ran successful ({{ ansible_play_name }})"
headers:
Content-Type: application/json
Authorization: Bearer 6ej3xr7cuinyfrzkbn64i85zco
status_code: [200, 201]
rescue:
- name: Umount nas volume
ansible.posix.mount:
path: /media/nas
state: unmounted
become: yes
- name: Inform Mattermost about error
uri:
url: "{{ mattermost_url }}"
method: POST
body_format: json
body:
username: "{{ mattermost_user }}"
text: "{{ ansible_date_time.date }} {{ ansible_date_time.time }} (info): Playbook ran with error ({{ ansible_play_name }})"