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

73 lines
1.7 KiB
YAML

---
#nfs_client/tasks/main.yml
- 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"
when: env == "test"
- 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 }}"
when: env == "test"
- 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
when: env == "test"
- name: Apply SELinux context for dummy NAS storage in test environment
become: true
command: restorecon -Rv "{{ nfs_mount_point }}"
changed_when: false
when: env == "test"
- name: Install required NFS client packages
become: true
dnf:
name: nfs-utils
state: present
when: env != "test"
- name: Check whether NFS mount point is already mounted
become: true
command: findmnt --mountpoint "{{ nfs_mount_point }}"
register: nfs_mount_check
changed_when: false
failed_when: false
when: env != "test"
- name: Create NFS mount point
become: true
file:
path: "{{ nfs_mount_point }}"
state: directory
owner: root
group: root
mode: "0755"
when:
- env != "test"
- nfs_mount_check.rc != 0
- name: Configure NFS mount
become: true
ansible.posix.mount:
path: "{{ nfs_mount_point }}"
src: "{{ nfs_server }}:{{ nfs_export }}"
fstype: "{{ nfs_fstype }}"
opts: "{{ nfs_options }}"
state: mounted
when: env != "test"