From 21d4aace4f8061f1ef6f3bdfffcf35980754f647 Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Sat, 11 Apr 2020 18:49:23 +0200 Subject: [PATCH] [owncloud-autofs] Configure automount --- roles/owncloud-autofs/tasks/main.yml | 44 +++++++++++-------- .../auto.master.d/home-owncloud.autofs.j2 | 2 + .../auto.master.d/home-owncloud.sh.j2 | 42 ++++++++++++++++++ .../owncloud-autofs/templates/auto.master.j2 | 29 ++++++++++++ .../templates/default/autofs.j2 | 15 +++++++ 5 files changed, 114 insertions(+), 18 deletions(-) create mode 100644 roles/owncloud-autofs/templates/auto.master.d/home-owncloud.autofs.j2 create mode 100755 roles/owncloud-autofs/templates/auto.master.d/home-owncloud.sh.j2 create mode 100644 roles/owncloud-autofs/templates/auto.master.j2 create mode 100644 roles/owncloud-autofs/templates/default/autofs.j2 diff --git a/roles/owncloud-autofs/tasks/main.yml b/roles/owncloud-autofs/tasks/main.yml index 41392e1c..83db9c3f 100644 --- a/roles/owncloud-autofs/tasks/main.yml +++ b/roles/owncloud-autofs/tasks/main.yml @@ -9,25 +9,33 @@ retries: 3 until: apt_result is succeeded -#- name: Configure autofs deamon -# template: -# src: "{{ item }}.j2" -# dest: "/etc/{{ item }}" -# mode: 0644 -# loop: -# - default/autofs -# - auto.master -# notify: Restart autofs service +- name: Configure autofs deamon + template: + src: "{{ item }}.j2" + dest: "/etc/{{ item }}" + mode: 0644 + loop: + - default/autofs + - auto.master + notify: Restart autofs service -#- name: Configure home-adh autofs -# template: -# src: "auto.master.d/{{ item.0 }}.j2" -# dest: "/etc/auto.master.d/{{ item.0 }}" -# mode: "{{ item.1 }}" -# loop: -# - ["home-adh.autofs", "0644"] -# - ["home-adh.sh", "0755"] -# notify: Restart autofs service +- name: Configure home-adh autofs + template: + src: "auto.master.d/{{ item.0 }}.j2" + dest: "/etc/auto.master.d/{{ item.0 }}" + mode: "{{ item.1 }}" + loop: + - ["home-owncloud.autofs", "0644"] + - ["home-owncloud.sh", "0755"] + notify: Restart autofs service + +- name: Create /home-owncloud/ directory + file: + path: /home-owncloud + state: directory + mode: 0750 + owner: www-data + group: root - name: Install autoclean cron template: diff --git a/roles/owncloud-autofs/templates/auto.master.d/home-owncloud.autofs.j2 b/roles/owncloud-autofs/templates/auto.master.d/home-owncloud.autofs.j2 new file mode 100644 index 00000000..62c3cb15 --- /dev/null +++ b/roles/owncloud-autofs/templates/auto.master.d/home-owncloud.autofs.j2 @@ -0,0 +1,2 @@ +# {{ ansible_managed }} +/home-owncloud /etc/auto.master.d/home-owncloud.sh -t60 diff --git a/roles/owncloud-autofs/templates/auto.master.d/home-owncloud.sh.j2 b/roles/owncloud-autofs/templates/auto.master.d/home-owncloud.sh.j2 new file mode 100755 index 00000000..eded801c --- /dev/null +++ b/roles/owncloud-autofs/templates/auto.master.d/home-owncloud.sh.j2 @@ -0,0 +1,42 @@ +#!/bin/bash +# {{ ansible_managed }} + +# Certains user dans owncloud ont été créés sous la forme user_1234 ce qui faisait planter le autofs +# ceci est un fix +USER=$(echo $1 | sed "s/_[1-9]*$//") + +# On quitte si l'utilisateur $USER n'existe pas +if ! /usr/bin/id -- "$USER" &>/dev/null; then + logger -p local0.error -t autofs "user $USER n'existe pas" + exit 1 +fi + +UHOME=$(eval echo ~$USER) +UGROUP=$(/usr/bin/id -gn $USER) + +# Rafraîchi les stats du dossier +/bin/ls ${UHOME}/OwnCloud/ &>/dev/null || /bin/ls ${UHOME} &>/dev/null + +# Création du dossier OwnCloud s'il n'existe pas ou n'appartient pas a l'utilisateur +if [ ! -d "${UHOME}/OwnCloud" ] || ! ( + /usr/bin/find ${UHOME}/OwnCloud/ -maxdepth 0 -user $USER -group ${UGROUP} | + /bin/grep -q ${UHOME}/OwnCloud/ +); then + mkdir ${UHOME}/OwnCloud && + chmod 700 ${UHOME}/OwnCloud && + chown $USER:${UGROUP} ${UHOME}/OwnCloud + + if [ ! -d "${UHOME}/OwnCloud" ] || ! ( + /usr/bin/find ${UHOME}/OwnCloud/ -maxdepth 0 -user $USER -group ${UGROUP} | + /bin/grep -q ${UHOME}/OwnCloud/ + ); then + logger -p local0.error -t autofs "impossible de créer le dossier ${UHOME}/OwnCloud" + exit 1 + fi + + logger -p local0.info -t autofs "Dossier ${UHOME}/OwnCloud créé" +fi + +chmod 750 /home-owncloud && +chown www-data:root /home-owncloud && +echo "-fstype=fuse.bindfs,map=$USER/www-data:@$UGROUP/@www-data,resolve-symlinks :${UHOME}/OwnCloud" diff --git a/roles/owncloud-autofs/templates/auto.master.j2 b/roles/owncloud-autofs/templates/auto.master.j2 new file mode 100644 index 00000000..4ff2d9dd --- /dev/null +++ b/roles/owncloud-autofs/templates/auto.master.j2 @@ -0,0 +1,29 @@ +# {{ ansible_managed }} +# +# Sample auto.master file +# This is a 'master' automounter map and it has the following format: +# mount-point [map-type[,format]:]map [options] +# For details of the format look at auto.master(5). +# +#/misc /etc/auto.misc +# +# NOTE: mounts done from a hosts map will be mounted with the +# "nosuid" and "nodev" options unless the "suid" and "dev" +# options are explicitly given. +# +#/net -hosts +# +# Include /etc/auto.master.d/*.autofs +# The included files must conform to the format of this file. +# ++dir:/etc/auto.master.d +# +# Include central master map if it can be found using +# nsswitch sources. +# +# Note that if there are entries for /net or /misc (as +# above) in the included master map any keys that are the +# same will not be seen as the first read key seen takes +# precedence. +# +#+auto.master diff --git a/roles/owncloud-autofs/templates/default/autofs.j2 b/roles/owncloud-autofs/templates/default/autofs.j2 new file mode 100644 index 00000000..4c28d404 --- /dev/null +++ b/roles/owncloud-autofs/templates/default/autofs.j2 @@ -0,0 +1,15 @@ +# +# Init system options +# {{ ansible_managed }} +# +# If the kernel supports using the autofs miscellanous device +# and you wish to use it you must set this configuration option +# to "yes" otherwise it will not be used. +# +USE_MISC_DEVICE="yes" +# +# Use OPTIONS to add automount(8) command line options that +# will be used when the daemon is started. +# +#OPTIONS="" +#