create auto fs service

This commit is contained in:
vincent 2019-01-12 19:12:55 +01:00
parent 8bc03f07a6
commit c59df1fd13
6 changed files with 103 additions and 0 deletions

View File

@ -0,0 +1,14 @@
systemd_mounts: {}
systemd_mounts_enabled: []
systemd_mounts_manage_service: {}
systemd_mounts_allow_reload: {}
autofs_mounts_manage_service: {}
autofs_mounts_allow_reload: {}
systemd_mount_packages:
- cifs-utils
- nfs-utils
- davfs2

View File

@ -0,0 +1,37 @@
- name: Reload systemd
systemd:
daemon_reload: yes
when: systemd_mounts_manage_service
- name: Start systemd mount
systemd:
name: "{{ item.value.mount[1:] | replace('-', '\\x2d') | replace('/', \"-\") }}.mount"
state: started
with_dict: "{{ systemd_mounts }}"
when: systemd_mounts_manage_service
- name: Start systemd automount
systemd:
name: "{{ item.value.mount[1:] | replace('-', '\\x2d') | replace('/', \"-\") }}.automount"
state: started
with_dict: "{{ systemd_mounts }}"
when: systemd_mounts_manage_service
- name: Enable systemd mount
systemd:
name: "{{ item.value.mount[1:] | replace('-', '\\x2d') | replace('/', \"-\") }}.mount"
enabled: yes
with_dict: "{{ systemd_mounts }}"
notify:
- Start systemd mount
when: item.value.automount == false
- name: Enable systemd automount
systemd:
name: "{{ item.value.mount[1:] | replace('-', '\\x2d') | replace('/', \"-\") }}.automount"
enabled: yes
with_dict: "{{ systemd_mounts }}"
notify:
- Start systemd automount
when: item.value.automount == true

View File

View File

@ -0,0 +1,31 @@
#
# tasks for mounts
# systemd uses - for dir separator, so dirs with dashes need escaped according to systemd-escape rules
#
- name: SYSTEMD MOUNT | Install needed packages
package:
name: "{{ item }}"
state: installed
with_items: "{{ systemd_mount_packages }}"
- name: SYSTEMD MOUNT | Setup systemd Service for mountpoints
template:
src: systemd.mount.j2
dest: "/etc/systemd/system/{{ item.value.mount[1:] | replace('-', '\\x2d') | replace('/', '-') }}.mount"
with_dict: "{{ systemd_mounts }}"
notify:
- Reload systemd
- Enable systemd mount
when: item.key in systemd_mounts_enabled
- name: SYSTEMD MOUNT | Setup systemd Service for automount
template:
src: systemd.automount.j2
dest: "/etc/systemd/system/{{ item.value.mount[1:] | replace('-', '\\x2d') | replace('/', '-') }}.automount"
with_dict: "{{ systemd_mounts }}"
notify:
- Reload systemd
- Enable systemd automount
when: item.value.automount is defined and item.value.automount == true and item.key in systemd_mounts_enabled

View File

@ -0,0 +1,9 @@
[Unit]
Description=Automount {{ item.key }}
After=network.target multi-user.target
[Automount]
Where={{ item.value.mount }}
[Install]
WantedBy=default.target

View File

@ -0,0 +1,12 @@
[Unit]
Description=Mount {{ item.key }}
After=network.target multi-user.target
[Mount]
What={{ item.value.share }}
Where={{ item.value.mount }}
Type={{ item.value.type | default ('mounts_type') }}
Options={{ item.value.options | join(',') | default ('mounts_options') }}
[Install]
WantedBy=default.target