autofs/tasks/main.yml
2019-11-24 14:49:14 +01:00

84 lines
2.2 KiB
YAML

#
# tasks for mounts
# systemd uses - for dir separator, so dirs with dashes need escaped according to systemd-escape rules
#
- name: Include OS-specific variables.
include_vars: "{{ ansible_os_family }}.yml"
- name: Make sure destination dir exists
file:
path: "{{ item.value.path | dirname }}"
state: directory
recurse: yes
with_dict: "{{ credentials_files }}"
become: true
when: item is defined
- name: set smb content to credential file
copy:
content: |
username={{ item.value.username }}
password={{ item.value.password }}
dest: "{{ item.value.path }}"
mode: 0600
with_dict: "{{ credentials_files }}"
become: true
no_log: true
when: item is defined and item.value.type == "smb"
- name: set davfs content to credential file
copy:
content: |
{{ item.value.adress }} {{ item.value.username }} {{ item.value.password }}
dest: "{{ item.value.path }}"
mode: 0600
with_dict: "{{ credentials_files }}"
become: true
no_log: true
when: item is defined and item.value.type == "davfs"
- name: SYSTEMD MOUNT | Install needed packages
package:
name: "{{ item }}"
state: present
with_items: "{{ systemd_mount_packages }}"
become: yes
- name: create mount directory if doesn't exist
file:
path: "{{item.value.mount}}"
state: directory
mode: 0777
with_dict: "{{ systemd_mounts }}"
become: yes
- 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
- Start systemd mount
become: yes
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
- Start systemd automount
become: yes
when: item.value.automount is defined and item.value.automount == true and item.key in systemd_mounts_enabled