Update backup to nas and remove mattermost variables.
This commit is contained in:
124
nas.yaml
124
nas.yaml
@@ -1,91 +1,59 @@
|
||||
---
|
||||
# This playbook creates a backup of odroid and writes it to the nas.
|
||||
- name: Backup odroid to nas.
|
||||
# This playbook creates a backup of minisforum and writes it to odroid.
|
||||
- name: Backup minisforum to odroid
|
||||
hosts: all
|
||||
vars:
|
||||
directories:
|
||||
- docker
|
||||
- media
|
||||
- nextcloud
|
||||
- sftp
|
||||
- strato-production
|
||||
gather_facts: false
|
||||
|
||||
tasks:
|
||||
- name: Backup odroid
|
||||
block:
|
||||
- include_vars: vars/mattermost.yaml
|
||||
- name: Wakeup odroid
|
||||
community.general.wakeonlan:
|
||||
mac: '00:1E:06:45:4C:45'
|
||||
broadcast: 192.168.178.255
|
||||
delegate_to: localhost
|
||||
|
||||
- name: Wakeup the nas
|
||||
community.general.wakeonlan:
|
||||
mac: '54:04:a6:f1:9b:80'
|
||||
- name: Wait odroid is responding
|
||||
ansible.builtin.wait_for_connection:
|
||||
|
||||
- name: Wait nas is responding
|
||||
wait_for_connection:
|
||||
timeout: 120
|
||||
delay: 5
|
||||
sleep: 5
|
||||
- name: Gathering facts
|
||||
ansible.builtin.setup:
|
||||
|
||||
- name: Gathering facts
|
||||
setup:
|
||||
- name: Mount minisforum storage
|
||||
ansible.posix.mount:
|
||||
src: 192.168.178.46:/
|
||||
path: /media/nas
|
||||
state: mounted
|
||||
fstype: nfs
|
||||
become: true
|
||||
|
||||
- name: Check mount point exists
|
||||
file:
|
||||
path: /media/nas
|
||||
state: directory
|
||||
- name: Check backup directory exists
|
||||
ansible.builtin.file:
|
||||
path: /media/backup/minisforum
|
||||
state: directory
|
||||
mode: '0755'
|
||||
|
||||
- name: Mount nas volume
|
||||
ansible.posix.mount:
|
||||
src: 192.168.178.55:/export/data
|
||||
path: /media/nas
|
||||
state: mounted
|
||||
fstype: nfs
|
||||
become: yes
|
||||
- name: Check file path for storage directories exists
|
||||
ansible.builtin.file:
|
||||
path: /media/backup/minisforum/{{ item }}
|
||||
state: directory
|
||||
mode: '0755'
|
||||
loop: "{{ directories }}"
|
||||
|
||||
- name: Backup docker data to nas
|
||||
shell: rsync -a --delete /media/backup/docker/ /media/nas/Odroid/docker
|
||||
become: yes
|
||||
- name: Backup minisforum directories
|
||||
ansible.builtin.shell: rsync -a --delete /media/nas/{{ item }}/ /media/backup/minisforum/{{ item }}/
|
||||
loop: "{{ directories }}"
|
||||
|
||||
- name: Backup hetzner data to nas
|
||||
shell: rsync -a --delete /media/backup/hetzner/ /media/nas/Odroid/hetzner
|
||||
become: yes
|
||||
- name: Unmount the volume
|
||||
ansible.posix.mount:
|
||||
path: /media/nas
|
||||
state: unmounted
|
||||
become: true
|
||||
|
||||
- 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: "{{ 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: 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:
|
||||
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]
|
||||
- name: Shutdown nas
|
||||
ansible.builtin.shell: sudo shutdown -h 1
|
||||
|
||||
Reference in New Issue
Block a user