From f53ccfbfeba0d397cdad23c3801f934a087f2360 Mon Sep 17 00:00:00 2001 From: Kyattsukuro Date: Mon, 12 Oct 2026 23:46:30 +0200 Subject: [PATCH] Init --- README.md | 1 + defaults/main.yml | 11 +++++++++++ handlers/main.yml | 8 ++++++++ meta/main.yml | 20 ++++++++++++++++++++ tasks/main.yml | 41 ++++++++++++++++++++++++++++++++++++++++ templates/nfs.service.j2 | 13 +++++++++++++ templates/smb.service.j2 | 13 +++++++++++++ 7 files changed, 107 insertions(+) create mode 100644 README.md create mode 100644 defaults/main.yml create mode 100644 handlers/main.yml create mode 100644 meta/main.yml create mode 100644 tasks/main.yml create mode 100644 templates/nfs.service.j2 create mode 100644 templates/smb.service.j2 diff --git a/README.md b/README.md new file mode 100644 index 0000000..e0bf1c1 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# storage_mount diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..664ad68 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,11 @@ +path: /srv/{{ role_name }} + +storage_mount_override: {} +storage_mount_defaults: + type: "nfs4" + host: "" + host_path: "" + args: "" + dest_path: "" + user: "" + password: "" diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..c62b155 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,8 @@ +- name: restart container + community.docker.docker_compose_v2: + project_src: "{{ path }}" + project_name: "{{ role_name }}" + recreate: "always" + services: ["storage_mount"] + state: "restarted" + when: not _storage_mount_already_restarted diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..f7b5618 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,20 @@ +--- +galaxy_info: + author: "Niklas Freese " + description: storage_mount + company: "Urmel Services" + license: AGPL-3.0-or-later + min_ansible_version: 2.1 + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: + - role: traefik diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..45080f3 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,41 @@ +--- +- name: "set local variables from overrides and defaults" + set_fact: + storage_mount: "{{ (storage_mount_defaults | combine(storage_mount_override, recursive=True)) if storage_mount_override else storage_mount_defaults }}" + +- name: get final escaped name + command: "systemd-escape --suffix=mount --path {{ storage_mount.dest_path }}" + register: escaped_mount_path + +- block: + - name: install nfs dependencies + package: + name: + - nfs-common + + - name: template nsf.service + template: + src: nfs.service.j2 + dest: "/etc/systemd/system/{{ escaped_mount_path.stdout }}" + when: + - "'nfs' in storage_mount.type" + +- block: + - name: install cifs (for SMB) dependencies + package: + name: + - cifs-utils + + - name: template smb.service + template: + src: smb.service.j2 + dest: "/etc/systemd/system/{{ escaped_mount_path.stdout }}" + when: + - "'cifs' in storage_mount.type" + +- name: Ensure systemd mountpoint is enabled+started + systemd_service: + state: "started" + daemon_reload: true + enabled: true + name: "{{ escaped_mount_path.stdout }}" diff --git a/templates/nfs.service.j2 b/templates/nfs.service.j2 new file mode 100644 index 0000000..aa315c3 --- /dev/null +++ b/templates/nfs.service.j2 @@ -0,0 +1,13 @@ +[Unit] +Description=Mount {{ storage_mount.dest_path }} via NFS +After = network-online.target +Wants = network-online.target + +[Mount] +What={{ storage_mount.host }}:{{ storage_mount.host_path }} +Where={{ storage_mount.dest_path }} +Type={{ storage_mount.type }} +Options={{ storage_mount.args }} + +[Install] +WantedBy=graphical.target diff --git a/templates/smb.service.j2 b/templates/smb.service.j2 new file mode 100644 index 0000000..4209f33 --- /dev/null +++ b/templates/smb.service.j2 @@ -0,0 +1,13 @@ +[Unit] +Description=Mount {{ storage_mount.dest_path }} via SMB +After = network-online.target +Wants = network-online.target + +[Mount] +What=//{{ storage_mount.host }}/{{ storage_mount.host_path }} +Where={{ storage_mount.dest_path }} +Type={{ storage_mount.type }} +Options={{ storage_mount.args }} + +[Install] +WantedBy=graphical.target