Add support for autofs mount points.

This commit is contained in:
Andrea Dell'Amico 2021-02-16 16:10:13 +01:00
parent 3989706fc2
commit 9d2b9bf1c4
6 changed files with 61 additions and 1 deletions

View File

@ -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: ''

View File

@ -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 }}

41
tasks/autofs.yml Normal file
View File

@ -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' ]

View File

@ -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

1
templates/auto.data.j2 Normal file
View File

@ -0,0 +1 @@
{{ item.path }} / {{ item.nfs_server }}:{{ item.remote_export }}

3
templates/auto.master.j2 Normal file
View File

@ -0,0 +1,3 @@
{% for maps in autofs_maps %}
{{ maps.mountpoint_prefix }} /etc/auto.{{ maps.map_name }}
{% endfor %}