diff --git a/defaults/main.yml b/defaults/main.yml index 9e5a327..b5ae2dc 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -5,4 +5,11 @@ systemd_mounts_enabled: [] systemd_mount_packages: - cifs-utils - nfs-utils - - davfs2 \ No newline at end of file + - davfs2 + +#credentials_files: +# - 1: +# type: +# path: +# username: +# password: \ No newline at end of file diff --git a/handlers/main.yml b/handlers/main.yml index fa1021c..c143e03 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -4,27 +4,11 @@ daemon_reload: yes become: yes -- name: Start systemd mount - systemd: - name: "{{ item.value.mount[1:] | replace('-', '\\x2d') | replace('/', \"-\") }}.mount" - state: started - with_dict: "{{ systemd_mounts }}" - become: yes - -- name: Start systemd automount - systemd: - name: "{{ item.value.mount[1:] | replace('-', '\\x2d') | replace('/', \"-\") }}.automount" - state: started - with_dict: "{{ systemd_mounts }}" - become: yes - - 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 become: yes @@ -35,4 +19,21 @@ with_dict: "{{ systemd_mounts }}" when: item.value.automount == true - become: yes \ No newline at end of file + become: yes + + +- name: Start systemd mount + systemd: + name: "{{ item.value.mount[1:] | replace('-', '\\x2d') | replace('/', \"-\") }}.mount" + state: started + with_dict: "{{ systemd_mounts }}" + when: item.value.automount == false + become: yes + +- name: Start systemd automount + systemd: + name: "{{ item.value.mount[1:] | replace('-', '\\x2d') | replace('/', \"-\") }}.automount" + state: started + with_dict: "{{ systemd_mounts }}" + when: item.value.automount == true + become: yes diff --git a/tasks/main.yml b/tasks/main.yml index 17cd669..dfacc5a 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -4,6 +4,39 @@ # systemd uses - for dir separator, so dirs with dashes need escaped according to systemd-escape rules # + + +- 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 + 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 + when: item is defined and item.value.type == "davfs" + - name: SYSTEMD MOUNT | Install needed packages package: name: "{{ item }}" @@ -11,18 +44,11 @@ with_items: "{{ systemd_mount_packages }}" become: yes -- name: stat mount directory - stat: - path: "{{item.value.mount}}" - with_dict: "{{ systemd_mounts }}" - register: test_folder - - name: create mount directory if doesn't exist file: - path: "{{item.item}}" + path: "{{item.value.mount}}" state: directory - when: item.stat.exists == false - with_items: "{{test_folder.results}}" + with_dict: "{{ systemd_mounts }}" become: yes - name: SYSTEMD MOUNT | Setup systemd Service for mountpoints @@ -33,6 +59,7 @@ notify: - Reload systemd - Enable systemd mount + - Start systemd mount become: yes when: item.key in systemd_mounts_enabled @@ -48,5 +75,5 @@ become: yes when: item.value.automount is defined and item.value.automount == true and item.key in systemd_mounts_enabled -- name: execute handler - meta: flush_handlers \ No newline at end of file + + \ No newline at end of file diff --git a/templates/systemd.mount.j2 b/templates/systemd.mount.j2 index a515d02..8b63d64 100644 --- a/templates/systemd.mount.j2 +++ b/templates/systemd.mount.j2 @@ -5,8 +5,8 @@ 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') }} +Type={{ item.value.type | default ('mounts_type') }} [Install] WantedBy=default.target \ No newline at end of file