diff --git a/defaults/main.yml b/defaults/main.yml index 11a3750..eff13cd 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -43,9 +43,30 @@ autofs_packages_el: autofs_maps: [] # - { map_name: 'data', mountpoint_prefix: '/', path: 'data', nfs_server: 'nfs.example.com', remote_export: '/export', is_home: False } -nfs_server_enabled: False +nfs_server_enabled: false nfs_server_ganesha_enabled: '{{ nfs_server_enabled }}' +nfs_server_kernel_el_pkgs: + - nfs-utils + - nfs4-acl-tools + +nfs_server_kernel_deb_pkgs: + - nfs-kernel-server + - nfs4-acl-tools + - nfstrace + - nfswatch + +nfs_server_exports: [] +# name, id, path, options, clients +# (*) indicate an optional parameter +# - name: export_filename +# id: 1 +# path: /export +# options: 'rw,sync,fsid=1,root_squash,no_wdelay' +# clients: +# - host1 +# - hostN + nfs_ganesha_conf_files: - ganesha.conf diff --git a/tasks/ganesha-nfs.yml b/tasks/ganesha-nfs.yml index ad6bdac..a6c83e8 100644 --- a/tasks/ganesha-nfs.yml +++ b/tasks/ganesha-nfs.yml @@ -10,7 +10,7 @@ mode: 0755 loop: '{{ nfs_server_ganesha_exports }}' - tags: [ 'san', 'nfs', 'storage', 'ganesha', 'ganesha_export' ] + tags: ['san', 'nfs', 'storage', 'ganesha', 'ganesha_export'] - name: Repositories and packages on EL block: @@ -41,21 +41,28 @@ when: ganesha_selinux_policy is changed when: ansible_distribution_file_variety == "RedHat" + tags: ['san', 'nfs', 'storage', 'ganesha', 'ganesha_pkg'] - name: Repositories and packages on Ubuntu/Debian block: - - name: Install the nfs ganesha packages on deb systems - ansible.builtin.apt: - pkg: '{{ nfs_server_ganesha_deb_pkgs }}' - state: present - cache_valid_time: 1800 + - name: Install the nfs ganesha packages on deb systems + apt: + pkg: '{{ nfs_server_ganesha_deb_pkgs }}' + state: present + cache_valid_time: 1800 + + - name: Ensure that the kernel NFS server package is not installed + apt: + pkg: nfs-kernel-server + state: absent when: ansible_distribution_file_variety == "Debian" + tags: ['san', 'nfs', 'storage', 'ganesha', 'ganesha_pkg'] -- name: Install and configure ganesha exports using the VFS backend +- name: Install and configure ganesha exports using the VFS backend block: - name: Install the ganesha configuration files - ansible.builtin.template: + template: src: '{{ item }}.j2' dest: '/etc/ganesha/{{ item }}' owner: root @@ -65,7 +72,7 @@ register: ganesha_conf_files - name: Install the ganesha export files - ansible.builtin.template: + template: src: ganesha-export.conf.j2 dest: '/etc/ganesha/{{ item.name }}.conf' owner: root @@ -74,6 +81,13 @@ loop: '{{ nfs_server_ganesha_exports }}' register: ganesha_conf_files + - name: Ensure that the Kernel NFS service is stopped on EL + service: + name: nfs-server + state: stopped + enabled: false + when: ansible_distribution_file_variety == "RedHat" + - name: Ensure that ganesha is started and enabled service: name=nfs-ganesha state=started enabled=yes @@ -81,4 +95,4 @@ service: name=nfs-ganesha state=reloaded when: ganesha_conf_files is changed - tags: [ 'san', 'nfs', 'storage', 'ganesha', 'ganesha_conf' ] + tags: ['san', 'nfs', 'storage', 'ganesha', 'ganesha_conf'] diff --git a/tasks/main.yml b/tasks/main.yml index d42b823..ce87754 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -11,3 +11,7 @@ - import_tasks: trusted_ca.yml - ansible.builtin.import_tasks: ganesha-nfs.yml when: nfs_server_ganesha_enabled +- import_tasks: nfs-kernel-server.yml + when: + - nfs_server_enanbled + - not nfs_server_ganesha_enabled diff --git a/tasks/nfs-kernel-server.yml b/tasks/nfs-kernel-server.yml new file mode 100644 index 0000000..1988a44 --- /dev/null +++ b/tasks/nfs-kernel-server.yml @@ -0,0 +1,75 @@ +--- +- name: Create the export directory trees + block: + - name: Create the directory of the nextcloud NFS export + ansible.builtin.file: + dest: '{{ item.path }}' + state: directory + owner: root + group: root + mode: 0755 + loop: '{{ nfs_server_exports }}' + + tags: ['san', 'nfs', 'storage', 'kernel_nfs'] + +- name: Repositories and packages on EL + block: + - name: Install the NFS packages on EL + yum: + name: '{{ nfs_server_kernel_el_pkgs }}' + state: present + + - name: Ensure that the Ganesha NFS server is not installed + yum: + name: nfs-ganesha + state: absent + + when: ansible_distribution_file_variety == "RedHat" + tags: ['san', 'nfs', 'storage', 'kernel_nfs'] + +- name: Repositories and packages on Ubuntu/Debian + block: + - name: Install the nfs packages on deb systems + apt: + pkg: '{{ nfs_server_kernel_deb_pkgs }}' + state: present + cache_valid_time: 1800 + + - name: Ensure that the ganesha server package is not installed + apt: + pkg: nfs-ganesha + state: absent + + when: ansible_distribution_file_variety == "Debian" + tags: ['san', 'nfs', 'storage', 'kernel_nfs'] + +- name: Manage the NFS exports + block: + - name: Install the NFS export file + template: + src: 'kernel-nfs-exports.j2' + dest: '/etc/exports' + owner: root + group: root + mode: 0644 + register: update_exportfs + + - name: Ensure that the Kernel NFS service is started and enabled on EL + service: + name: nfs-server + state: started + enabled: true + when: ansible_distribution_file_variety == "RedHat" + + - name: Ensure that the Kernel NFS service is started and enabled on deb systems + service: + name: nfs-kernel-server + state: started + enabled: true + when: ansible_distribution_file_variety == "Debian" + + - name: Refresh the exports + shell: exportfs -a + when: update_exportfs is changed + + tags: ['san', 'nfs', 'storage', 'kernel_nfs', 'kernel_nfs_conf'] diff --git a/templates/kernel-nfs-exports.j2 b/templates/kernel-nfs-exports.j2 new file mode 100644 index 0000000..8441c73 --- /dev/null +++ b/templates/kernel-nfs-exports.j2 @@ -0,0 +1 @@ +{{ item.path }} {% for c in item.clients %}{{ c }}({{ item.options }}) {% endfor %}