From c1e3bbbe04863536e88d4d79afbbb85253e7d3b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Gon=C3=A7alves?= Date: Sat, 11 Dec 2021 11:56:27 +0000 Subject: roles/nfsd: Consistent configuration with other roles --- roles/nfsd/defaults/main.yml | 4 ++-- roles/nfsd/tasks/_freebsd.yml | 20 -------------------- roles/nfsd/tasks/main.yml | 26 +++++++++++++++++--------- roles/nfsd/tasks/os_freebsd.yml | 15 +++++++++++++++ roles/nfsd/templates/exports.j2 | 2 +- 5 files changed, 35 insertions(+), 32 deletions(-) delete mode 100644 roles/nfsd/tasks/_freebsd.yml create mode 100644 roles/nfsd/tasks/os_freebsd.yml diff --git a/roles/nfsd/defaults/main.yml b/roles/nfsd/defaults/main.yml index 1478e25..b214a7c 100644 --- a/roles/nfsd/defaults/main.yml +++ b/roles/nfsd/defaults/main.yml @@ -1,4 +1,4 @@ -nfsd_data_dir: /data/nfs +nfsd_dir: /data/nfs +nfsd_shared_dirs: "{{ vmm_vms | map(attribute='name') | list }}" nfsd_configuration_file: /etc/exports nfsd_processes: 10 -nfsd_shared_dirs: "{{ vmm_vms | map(attribute='name') | list }}" diff --git a/roles/nfsd/tasks/_freebsd.yml b/roles/nfsd/tasks/_freebsd.yml deleted file mode 100644 index 2cae34a..0000000 --- a/roles/nfsd/tasks/_freebsd.yml +++ /dev/null @@ -1,20 +0,0 @@ - -# nfsd ~~ roles/nfsd/tasks/_freebsd.yml - ---- - -- name: ensure daemons flag - lineinfile: - path: /etc/rc.conf - regexp: "^{{ item[0] }}=" - line: "{{ item[0] }}=\"{{ item[1] }}\"" - loop: - - ["nfs_server_flags", "-tun {{ nfsd_nb_process }}"] - - ["rpcbind_enable=", "YES"] - - ["mountd_flags", "-r"] - -- name: ensure rpcbind is enabled and restarted - service: - name: rpcbind - state: restarted - enabled: true diff --git a/roles/nfsd/tasks/main.yml b/roles/nfsd/tasks/main.yml index 7be5f2a..a8cabcf 100644 --- a/roles/nfsd/tasks/main.yml +++ b/roles/nfsd/tasks/main.yml @@ -1,6 +1,6 @@ - name: create nfsd data directory file: - path: "{{ nfsd_data_dir }}" + path: "{{ nfsd_dir }}" owner: 0 group: 0 mode: 0700 @@ -8,7 +8,7 @@ - name: create hosts directories file: - path: "{{ nfsd_data_dir }}/{{ item }}" + path: "{{ nfsd_dir }}/{{ item }}" owner: 0 group: 0 mode: 0777 @@ -19,17 +19,25 @@ template: src: exports.j2 dest: /etc/exports - owner: root + owner: 0 + group: 0 mode: 0640 register: result -- name: enable and start nfsd service - service: &nfsd_service - name: nfsd - state: "{{ 'restarted' if result.changed else 'started' }}" +- name: enable and restart portmap + service: &enable_and_restart + name: portmap + state: restarted enabled: true -- name: enable and restart mountd +- name: enable and reload/restart mountd service: - <<: *nfsd_service + <<: *enable_and_restart name: mountd + state: reloaded + +- name: enable and restart nfsd + service: + <<: *enable_and_restart + name: nfsd + state: restarted diff --git a/roles/nfsd/tasks/os_freebsd.yml b/roles/nfsd/tasks/os_freebsd.yml new file mode 100644 index 0000000..2a8a8cd --- /dev/null +++ b/roles/nfsd/tasks/os_freebsd.yml @@ -0,0 +1,15 @@ +- name: edit daemons flags + lineinfile: + path: /etc/rc.conf + regexp: "^{{ item[0] }}=" + line: "{{ item[0] }}=\"{{ item[1] }}\"" + loop: + - ["nfs_server_flags", "-tun {{ nfsd_nb_process }}"] + - ["rpcbind_enable=", "YES"] + - ["mountd_flags", "-r"] + +- name: enable and restart rpcbind + service: + name: rpcbind + state: restarted + enabled: true diff --git a/roles/nfsd/templates/exports.j2 b/roles/nfsd/templates/exports.j2 index 78ee61f..c579fed 100644 --- a/roles/nfsd/templates/exports.j2 +++ b/roles/nfsd/templates/exports.j2 @@ -3,6 +3,6 @@ {% for host in groups.servers %} {% if host in nfsd_shared_dirs %} {% set h = hostvars[host] %} -{{ nfsd_data_dir }}/{{ h.inventory_hostname }} -maproot=root {{ h.__ip.internal if h.__ip.internal is defined }} {{ h.__ip.external if h.__ip.external is defined }} +{{ nfsd_dir }}/{{ h.inventory_hostname }} -maproot=root {{ h.__ip.internal if h.__ip.internal is defined }} {{ h.__ip.external if h.__ip.external is defined }} {% endif %} {% endfor %} -- cgit v1.2.3