sce/roles/backup_nfs/tasks/main.yml
Ivo C.S. Wingelaar 3934bffbd1
Add backup restoration logic to NFS role
Passing the `backup_nfs_restore` variable will restore that timestamp.
2024-10-13 20:12:26 +02:00

50 lines
1.5 KiB
YAML

---
- name: Install NFS client software
ansible.builtin.apt:
name: nfs-common
state: present
- name: Check existence of mount directory
ansible.builtin.stat:
path: "{{ backup_nfs_mountpoint }}"
register: mountpoint
- name: Create mountpoint if it does not exist
ansible.builtin.file:
path: "{{ backup_nfs_mountpoint }}"
state: directory
mode: "0700"
owner: root
group: root
when: not mountpoint.stat.exists
- name: This block ensures the NFS directory will be unmounted if a task fails
block:
- name: Mount backup NFS directory (for creating backups)
ansible.posix.mount:
src: "{{ backup_nfs_remote }}:{{ backup_nfs_create_directory }}"
path: "{{ backup_nfs_mountpoint }}"
opts: rw,sync,hard,vers=4
state: ephemeral
fstype: nfs
when: backup_nfs_restore is undefined
- name: Mount backup NFS directory (for restoring backups)
ansible.posix.mount:
src: "{{ backup_nfs_remote }}:{{ backup_nfs_restore_directory }}"
path: "{{ backup_nfs_mountpoint }}"
opts: ro,sync,hard,vers=4
state: ephemeral
fstype: nfs
when: backup_nfs_restore is defined
- name: Execute backup tasks inside service account
ansible.builtin.include_tasks: machinectl.yml
loop: "{{ backup_nfs_targets }}"
loop_control:
loop_var: backup_nfs_users
always:
- name: Unmount backup NFS directory
ansible.posix.mount:
path: "{{ backup_nfs_mountpoint }}"
state: unmounted