Homelab-Infra/roles/nfs_client/tasks/main.yml

70 lines
2.0 KiB
YAML

---
# nfs_client/tasks/main.yml
- name: Configure dummy NAS storage for test environment
when: env == "test"
block:
- name: Create dummy NAS root for test environment
become: true
file:
path: "{{ nfs_mount_point }}"
state: directory
owner: "{{ container_user }}"
group: "{{ container_group }}"
mode: "0755"
- name: Create dummy NAS storage tree for test environment
become: true
file:
path: "{{ nfs_mount_point }}/{{ item }}"
state: directory
owner: "{{ container_user }}"
group: "{{ container_group }}"
mode: "0775"
loop: "{{ storage_tree }}"
- name: Set SELinux context for dummy NAS storage in test environment
become: true
community.general.sefcontext:
target: "{{ nfs_mount_point }}(/.*)?"
setype: container_file_t
state: present
- name: Apply SELinux context for dummy NAS storage in test environment
become: true
command: restorecon -Rv "{{ nfs_mount_point }}"
changed_when: false
- name: Configure NFS client for non-test environments
when: env != "test"
block:
- name: Install required NFS client packages
become: true
dnf:
name: nfs-utils
state: present
- name: Check whether NFS mount point is already mounted
become: true
ansible.builtin.command: findmnt --mountpoint "{{ nfs_mount_point }}"
register: nfs_mount_check
changed_when: false
failed_when: false
- name: Ensure local NFS mount point exists before mounting
become: true
file:
path: "{{ nfs_mount_point }}"
state: directory
owner: root
group: root
mode: "0755"
when: nfs_mount_check.rc != 0
- name: Ensure NFS mount is present in fstab and mounted
become: true
ansible.posix.mount:
path: "{{ nfs_mount_point }}"
src: "{{ nfs_server }}:{{ nfs_export }}"
fstype: "{{ nfs_fstype }}"
opts: "{{ nfs_options }}"
state: mounted