From c063fddb04da9c06a2c19ba528e69ae8d11fa1b4 Mon Sep 17 00:00:00 2001 From: tigattack <10629864+tigattack@users.noreply.github.com> Date: Sat, 12 Oct 2024 14:31:16 +0100 Subject: [PATCH] feat: ensure local mount path exists Adds a task to ensure the local mount path exists with optionally configurable mode, owner, and group. --- README.md | 7 ++++++- defaults/main.yml | 3 +++ tasks/mount.yml | 9 +++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e603f82..c01aaed 100644 --- a/README.md +++ b/README.md @@ -206,7 +206,9 @@ Note: This example assumes you have created the `rclone.service` systemd unit yo ### `rclone_mounts: ""` -This variable allows for the configuration of rclone mounts within your infrastructure. `rclone_mounts` should be a YAML list of objects, each including keys for `name`, `remote_name`, `remote_path`, `local_path`, `auto_mount`, and `extra_args`. This setup enables precise control over multiple mount points, their remote sources, and whether they should be automatically mounted. +This variable allows for the configuration of rclone mounts within your infrastructure. `rclone_mounts` should be a YAML list of objects, each including keys for `name`, `remote_name`, `remote_path`, `local_path`, `auto_mount`, and `extra_args`. Optionally, you can also pass `local_path_mode` (defaults to `0755`), `local_path_owner`, and `local_path_group` (both default to `root`). + +This setup enables precise control over multiple mount points, their remote sources, and whether they should be automatically mounted. The role will attempt to create all defined `remote_path`'s by default, **if** the `remote_path` is not simply `/`. You can disable this by setting `rclone_mkdir` to `false`. @@ -229,6 +231,9 @@ rclone_mounts: remote_name: BackblazeLM remote_path: "/my-app" local_path: "/var/backups/my-app/" + local_path_mode: 0755 + local_path_owner: root + local_path_group: root auto_mount: true extra_args: "--allow-other" ``` diff --git a/defaults/main.yml b/defaults/main.yml index 9440fcb..98b3f3a 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -44,5 +44,8 @@ rclone_mounts: [] # - name: test # remote_path: "/test" # local_path: "/mnt" +# local_path_mode: 0755 +# local_path_owner: root +# local_path_group: root # auto_mount: true # extra_args: "--allow-other" diff --git a/tasks/mount.yml b/tasks/mount.yml index d8773a7..cd1e8cf 100644 --- a/tasks/mount.yml +++ b/tasks/mount.yml @@ -12,6 +12,15 @@ register: rclone_mkdir_output changed_when: rclone_mkdir_output.rc == 0 +- name: Ensure local path exists + ansible.builtin.file: + path: "{{ item.local_path }}" + mode: "{{ item.local_path_mode | default('0755') }}" + owner: "{{ item.local_path_owner | default('root') }}" + group: "{{ item.local_path_group | default('root') }}" + state: directory + loop: "{{ rclone_mounts }}" + - name: Install fuse ansible.builtin.package: name: fuse