autofs: set the mount point ownership.

This commit is contained in:
Andrea Dell'Amico 2024-03-06 19:11:44 +01:00
parent 315acd9c9f
commit b1b610e133
Signed by: adellam
GPG Key ID: 147ABE6CEB9E20FF
3 changed files with 85 additions and 41 deletions

View File

@ -66,7 +66,16 @@ autofs_packages_el:
# path: without the initial /
autofs_maps: []
# - { map_name: 'data', mountpoint_prefix: '/', path: 'data', nfs_server: 'nfs.example.com', remote_export: '/export', is_home: False }
# - map_name: 'data'
# mountpoint_prefix: '/'
# path: 'data'
# nfs_server: 'nfs.example.com'
# remote_export: '/export'
# is_home: false
# force_ownership: false
# owner_uid: 1000
# owner_gid: 1000
# permissions: "0750"
nfs_server_enabled: false
nfs_server_ganesha_enabled: '{{ nfs_server_enabled }}'

View File

@ -2,3 +2,8 @@
- name: Netplan Apply
ansible.builtin.command:
cmd: netplan apply
- name: Restart autofs
ansible.builtin.service:
name: autofs
state: restarted

View File

@ -1,36 +1,46 @@
---
- 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
- name: autofs | Install and configure autofs on Ubuntu/Debian
when: ansible_distribution_file_variety == "Debian"
tags: [ 'nfs', 'autofs' ]
- name: Install and configure autofs on EL
tags: ['nfs', 'autofs']
block:
- name: Install the autofs packages on EL
yum: pkg={{ autofs_packages_el }} state=present
- name: autofs | Install the autofs packages on Ubuntu/Debian
ansible.builtin.apt:
pkg: "{{ autofs_packages_deb }}"
state: present
cache_valid_time: 1800
- name: autofs | Install and configure autofs on EL
when: ansible_distribution_file_variety == "RedHat"
tags: [ 'nfs', 'autofs' ]
- name: Stop autofs if it is a 'hard' reconfiguration
tags: ['nfs', 'autofs']
block:
- name: Stop autofs
service: name=autofs state=stopped
- name: autofs | Install the autofs packages on EL
ansible.builtin.yum:
pkg: "{{ autofs_packages_el }}"
state: present
- name: autofs | Stop autofs if it is a 'hard' reconfiguration
tags: ['nfs', 'autofs', 'autofs_conf']
block:
- name: autofs | Stop autofs
ansible.builtin.service:
name: autofs
state: stopped
when: autofs_hard_reconfig is defined and autofs_hard_reconfig
tags: [ 'nfs', 'autofs', 'autofs_conf' ]
- name: Configure autofs and its maps
- name: autofs | Configure autofs and its maps
tags: ['nfs', 'autofs', 'autofs_conf']
block:
- name: Create the mount points
file: dest={{ item.mountpoint_prefix }} state=directory owner=root group=root mode=0755
with_items: '{{ autofs_maps }}'
- name: autofs | Create the mount points
ansible.builtin.file:
dest: "{{ item.mountpoint_prefix }}"
state: directory
owner: root
group: root
mode: "0755"
loop: '{{ autofs_maps }}'
- name: setup idmap.conf
ini_file:
- name: autofs | Setup idmap.conf
community.general.ini_file:
path: /etc/idmapd.conf
section: '{{ item.section }}'
option: '{{ item.option }}'
@ -39,11 +49,11 @@
owner: 'root'
group: 'root'
mode: '0644'
create: no
create: false
loop: '{{ idmap_conf_options }}'
- name: setup autofs.conf
ini_file:
- name: autofs | Setup autofs.conf
community.general.ini_file:
path: /etc/autofs.conf
section: '{{ item.section }}'
option: '{{ item.option }}'
@ -52,23 +62,43 @@
owner: 'root'
group: 'root'
mode: '0644'
create: no
create: false
loop: '{{ autofs_conf_options }}'
- 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: autofs | Install the autofs master configuration
ansible.builtin.template:
src: auto.master.j2
dest: /etc/auto.master
owner: root
group: root
mode: "0644"
notify: Restart autofs
- 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: autofs | Install the autofs map files
ansible.builtin.template:
src: auto.data.j2
dest: "/etc/auto.{{ item.map_name }}"
owner: root
group: root
mode: "0644"
loop: '{{ autofs_maps }}'
notify: Restart autofs
- name: Ensure that autofs is enabled and running
service: name=autofs state=started enabled=yes
- name: autofs | Ensure that autofs is enabled and running
ansible.builtin.service:
name: autofs
state: started
enabled: true
- name: Restart autofs if the configuration changed
service: name=autofs state=restarted
when: reg_autofs_master_conf is changed
- name: autofs | Force a restart of autofs after a configuration change
ansible.builtin.meta: flush_handlers
tags: ['nfs', 'autofs', 'autofs_conf']
tags: [ 'nfs', 'autofs', 'autofs_conf' ]
- name: autofs | Force the ownership of the mount point
ansible.builtin.file:
dest: "{{ item.item.mountpoint_prefix }}/{{ item.path }}"
owner: "{{ item.owner_uid }}"
group: "{{ item.owner_gid }}"
mode: "{{ item.permissions }}"
loop: "{{ autofs_maps }}"
when: item.force_ownership is defined and item.force_ownership