From b1b610e13358277cb5454aa2789678f25891f6c8 Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Wed, 6 Mar 2024 19:11:44 +0100 Subject: [PATCH] autofs: set the mount point ownership. --- defaults/main.yml | 11 ++++- handlers/main.yml | 5 +++ tasks/autofs.yml | 110 +++++++++++++++++++++++++++++----------------- 3 files changed, 85 insertions(+), 41 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index a8d3f85..cfc0cb1 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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 }}' diff --git a/handlers/main.yml b/handlers/main.yml index f4d0806..705bddb 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -2,3 +2,8 @@ - name: Netplan Apply ansible.builtin.command: cmd: netplan apply + +- name: Restart autofs + ansible.builtin.service: + name: autofs + state: restarted diff --git a/tasks/autofs.yml b/tasks/autofs.yml index c2c8c3b..e90eedf 100644 --- a/tasks/autofs.yml +++ b/tasks/autofs.yml @@ -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