From 13ef8e5744442b6a6d61a96888f87a1c96c44ba6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Gon=C3=A7alves?= Date: Sat, 11 Dec 2021 11:55:55 +0000 Subject: roles: Add nfsclient --- group_vars/all.yml | 1 + playbooks/site.yml | 15 +++++++++++++-- roles/nfsclient/defaults/main.yml | 5 +++++ roles/nfsclient/tasks/main.yml | 32 ++++++++++++++++++++++++++++++++ roles/nfsclient/tasks/os_alpine.yml | 10 ++++++++++ roles/nfsclient/tasks/os_openbsd.yml | 0 6 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 roles/nfsclient/defaults/main.yml create mode 100644 roles/nfsclient/tasks/main.yml create mode 100644 roles/nfsclient/tasks/os_alpine.yml create mode 100644 roles/nfsclient/tasks/os_openbsd.yml diff --git a/group_vars/all.yml b/group_vars/all.yml index 694927c..72bf8d6 100644 --- a/group_vars/all.yml +++ b/group_vars/all.yml @@ -2,6 +2,7 @@ ansible_hostname: "{{ ansible_host }}" ansible_become_method: su wireguard_domain_controller: "{{ __global_domain_controller }}" +nfsclient_server: "stack0" __is_vm: false diff --git a/playbooks/site.yml b/playbooks/site.yml index 96dffb5..d354cb7 100644 --- a/playbooks/site.yml +++ b/playbooks/site.yml @@ -7,12 +7,23 @@ roles: - role: sshd tags: role_sshd - - role: httpd - tags: role_httpd - hosts: stack0 roles: - role: nfsd tags: role_nfsd + +- hosts: stack0-* + roles: + - role: nfsclient + tags: role_nfsclient + +- hosts: servers + roles: + - role: httpd + tags: role_httpd + +- hosts: stack0 + roles: - role: vmm tags: role_vmm diff --git a/roles/nfsclient/defaults/main.yml b/roles/nfsclient/defaults/main.yml new file mode 100644 index 0000000..d0ca08e --- /dev/null +++ b/roles/nfsclient/defaults/main.yml @@ -0,0 +1,5 @@ +nfsclient_dir: /data +nfsclient_fstab_path: /etc/fstab +nfsclient_server_dir: /data/nfs +nfsclient_server_host: null +nfsclient_server_ip: null diff --git a/roles/nfsclient/tasks/main.yml b/roles/nfsclient/tasks/main.yml new file mode 100644 index 0000000..7799a60 --- /dev/null +++ b/roles/nfsclient/tasks/main.yml @@ -0,0 +1,32 @@ +- name: translate server string to server dict + set_fact: + nfsclient_server_ip: "{{ hostvars[nfsclient_server].__ip.external }}" + when: not nfsclient_server_ip + +- name: include distribution specific prerequisites + include_tasks: "os_{{ ansible_distribution | lower }}.yml" + ignore_errors: true + +- name: create directory on client + file: + path: "{{ nfsclient_dir }}" + owner: 0 + group: 0 + mode: 0755 + state: directory + +- name: cleanup fstab with previous nfs setup + lineinfile: + path: "{{ nfsclient_fstab_path }}" + regexp: ^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:/.* {{ nfsclient_dir }} nfs + state: absent + register: result + +- name: complete fstab with nfs + lineinfile: + path: "{{ nfsclient_fstab_path }}" + line: "{{ nfsclient_server_ip }}:{{ nfsclient_server_dir }}/{{ inventory_hostname }} {{ nfsclient_dir }} nfs rw,nodev,nosuid 0 0" + +- name: reload fstab + shell: mount -a + ignore_errors: true diff --git a/roles/nfsclient/tasks/os_alpine.yml b/roles/nfsclient/tasks/os_alpine.yml new file mode 100644 index 0000000..62d8f70 --- /dev/null +++ b/roles/nfsclient/tasks/os_alpine.yml @@ -0,0 +1,10 @@ +- name: install nfs-utils + package: + name: nfs-utils + state: present + +- name: restart and enable nfsmount + service: + name: nfsmount + state: restarted + enabled: true diff --git a/roles/nfsclient/tasks/os_openbsd.yml b/roles/nfsclient/tasks/os_openbsd.yml new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3