40 lines
1.1 KiB
YAML
40 lines
1.1 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
|
|
ansible.posix.mount:
|
|
src: "{{ backup_nfs_remote }}:{{ backup_nfs_directory }}"
|
|
path: "{{ backup_nfs_mountpoint }}"
|
|
opts: rw,sync,hard,vers=4
|
|
state: ephemeral
|
|
fstype: nfs
|
|
|
|
- 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
|