From 9d2b9bf1c42e42a329d28dc3e05651846ec189ef Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Tue, 16 Feb 2021 16:10:13 +0100 Subject: [PATCH] Add support for autofs mount points. --- defaults/main.yml | 14 ++++++++++++- tasks/additional_disks.yml | 1 + tasks/autofs.yml | 41 ++++++++++++++++++++++++++++++++++++++ tasks/main.yml | 2 ++ templates/auto.data.j2 | 1 + templates/auto.master.j2 | 3 +++ 6 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 tasks/autofs.yml create mode 100644 templates/auto.data.j2 create mode 100644 templates/auto.master.j2 diff --git a/defaults/main.yml b/defaults/main.yml index f97afe3..318cee4 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -12,11 +12,23 @@ locales_list: - { name: 'it_IT' } # -# Define the following variables to manage additional disks and mount points +# Define the following variables to manage additional disks and mount points, even static nfs ones additional_disks: False disks_and_mountpoints_list: [] # - { mountpoint: '/data', device: 'xvda3', fstype: 'xfs', opts: 'noatime', state: 'mounted', create_filesystem: True } +# autofs mount points +autofs_client_mountpoint: False +autofs_packages_deb: + - autofs + +autofs_packages_el: + - autofs + +# path: without the initial / +autofs_maps: [] +# - { map_name: 'data', mount_point_prefix: '/', path: 'data', nfs_server: 'nfs.example.com', remote_export: '/export' } + # tmpreaper tmpreaper_install: False tmpreaper_protect_extra: '' diff --git a/tasks/additional_disks.yml b/tasks/additional_disks.yml index 6e33c8e..471771f 100644 --- a/tasks/additional_disks.yml +++ b/tasks/additional_disks.yml @@ -20,6 +20,7 @@ when: - additional_disks - item.create_filesystem + - item.fstype != 'nfs' - name: Manage the additional file systems mount: name={{ item.mountpoint }} src={{ item.root_device | default('/dev') }}/{{ item.device }} fstype={{ item.fstype }} opts={{ item.opts }} state={{ item.state }} diff --git a/tasks/autofs.yml b/tasks/autofs.yml new file mode 100644 index 0000000..c094267 --- /dev/null +++ b/tasks/autofs.yml @@ -0,0 +1,41 @@ +--- +- name: Install and configure autofs on Ubuntu/Debian + block: + - name: Install the autofs packages on Ubuntu/Debian + apt: pkg={{ autofs_packages_deb }} state=present cache_valid_time=1800 + + when: ansible_distribution_file_variety == "Debian" + tags: [ 'nfs', 'autofs' ] + +- name: Install and configure autofs on EL + block: + - name: Install the autofs packages onn EL + yum: pkg={{ autofs_packages_el }} state=present + + when: ansible_distribution_file_variety == "RedHat" + tags: [ 'nfs', 'autofs' ] + +- name: Configure autofs and its maps + block: + - name: Create the mount points + file: dest={{ item.mountpoint_prefix }}/{{ item.path }} state=directory owner=root group=root mode=0755 + with_items: '{{ autofs_maps }}' + + - name: Install the autofs master configuration + template: src=auto.master.j2 dest=/etc/auto.master owner=root group=root mode=0644 + register: reg_autofs_master_conf + + - name: Install the autofs map files + template: src=auto.data.j2 dest=/etc/auto.{{ item.map_name }} owner=root group=root mode=0644 + with_items: '{{ autofs_maps }}' + register: autofs_conf + + - name: Ensure that autofs is enabled and running + service: name=autofs state=started enabled=yes + + - name: Restart autofs if the configuration changed + service: name=autofs state=restarted + when: reg_autofs_master_conf is changed + + tags: [ 'nfs', 'autofs' ] + diff --git a/tasks/main.yml b/tasks/main.yml index 5360f26..6aad689 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -5,6 +5,8 @@ - import_tasks: http_client_proxy.yml - import_tasks: additional_disks.yml when: additional_disks +- import_tasks: autofs.yml + when: autofs_client_mountpoint - import_tasks: tmpreaper.yml - import_tasks: trusted_ca.yml diff --git a/templates/auto.data.j2 b/templates/auto.data.j2 new file mode 100644 index 0000000..36d0326 --- /dev/null +++ b/templates/auto.data.j2 @@ -0,0 +1 @@ +{{ item.path }} / {{ item.nfs_server }}:{{ item.remote_export }} diff --git a/templates/auto.master.j2 b/templates/auto.master.j2 new file mode 100644 index 0000000..502c747 --- /dev/null +++ b/templates/auto.master.j2 @@ -0,0 +1,3 @@ +{% for maps in autofs_maps %} +{{ maps.mountpoint_prefix }} /etc/auto.{{ maps.map_name }} +{% endfor %}