diff --git a/roles/host_maintenance/README.md b/roles/host_maintenance/README.md new file mode 100644 index 0000000..9bcc649 --- /dev/null +++ b/roles/host_maintenance/README.md @@ -0,0 +1,21 @@ + +systemd_mount vars task example: + +``` yaml +host_maintenance_disk_mounts: + - source: /dev/disk/by-uuid/xxxxxxx + target: /var/lib/rancher + mount_type: ext4 + unit_before: k3s.service + unit_conflicts: umount.target + mount_options: + - defaults + - source: /dev/disk/by-uuid/xxxxx + target: /var/lib/rancher/k3s/storage + unit_before: k3s.service + unit_conflicts: umount.target + mount_type: ext4 + mount_options: + - defaults + +``` \ No newline at end of file diff --git a/roles/host_maintenance/tasks/systemd_mount.yaml b/roles/host_maintenance/tasks/systemd_mount.yaml index 7a2987a..c3eed8c 100644 --- a/roles/host_maintenance/tasks/systemd_mount.yaml +++ b/roles/host_maintenance/tasks/systemd_mount.yaml @@ -1,7 +1,11 @@ -#vars: -# host_maintenance_systemd_mount_target: "" -# host_maintenance_systemd_mount_source: "" +- ansible.builtin.assert: + that: + - item.source is defined + - item.target is defined + - item.mount_type is defined + fail_msg: "All of source, target, and mount_type must be defined for each disk entry." + loop: "{{ host_maintenance_disk_mounts }}" - name: check target folders ansible.builtin.file: path: "{{ item.target }}" diff --git a/roles/host_maintenance/templates/systemd_mount.j2 b/roles/host_maintenance/templates/systemd_mount.j2 index d33e640..54987a8 100644 --- a/roles/host_maintenance/templates/systemd_mount.j2 +++ b/roles/host_maintenance/templates/systemd_mount.j2 @@ -1,14 +1,26 @@ +# set by ansible role mylimbo.globals.host_maintenance role, do not edit manually [Unit] Description=Mount {{ item.target }} managed by mylimbo.globals collections, host_maintenance role -#After= -Conflicts={{ item.unit_conflicts }} + +{% if item.unit_after is defined %} +# After dependencies +After={{ item.unit_after }} +{% endif %} + +{% if item.unit_before is defined %} +# Before dependencies Before={{ item.unit_before }} +{% endif %} [Mount] What={{ item.source }} Where={{ item.target }} Type={{ item.mount_type }} + +{% if item.mount_options is defined %} +# Mount options, if specified Options={{ item.mount_options | join(',') }} +{% endif %} [Install] WantedBy=multi-user.target \ No newline at end of file