From 8b3831d8d860acd1e0b272bdd4c4daf06614fd57 Mon Sep 17 00:00:00 2001 From: jabertwo <git@jabertwo.de> Date: Mon, 9 Sep 2024 21:45:37 +0200 Subject: [PATCH] mount drives automatically --- all/mount/tasks/main.yml | 22 ++++++++++++++++++++++ host_vars/weatherwax | 14 ++++++++++++++ site.yml | 3 ++- 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 all/mount/tasks/main.yml diff --git a/all/mount/tasks/main.yml b/all/mount/tasks/main.yml new file mode 100644 index 00000000..eee037b1 --- /dev/null +++ b/all/mount/tasks/main.yml @@ -0,0 +1,22 @@ +- name: Ensure mount directories exist for non-root drives + ansible.builtin.file: + path: "{{ item.value.path }}" + state: directory + mode: '0755' + loop: "{{ lookup('dict', drives) }}" + when: drives is defined and item.value.fstype != "swap" and item.value.path != "/" + +- name: Mount all drives (excluding swap) + ansible.builtin.mount: + path: "{{ item.value.path }}" + src: "UUID={{ item.value.uuid }}" + fstype: "{{ item.value.fstype }}" + state: mounted + loop: "{{ lookup('dict', drives) }}" + when: drives is defined and item.value.fstype != "swap" + +- name: Enable swap partition + ansible.builtin.command: + cmd: "swapon UUID={{ item.value.uuid }}" + loop: "{{ lookup('dict', drives) }}" + when: drives is defined and item.value.fstype == "swap" \ No newline at end of file diff --git a/host_vars/weatherwax b/host_vars/weatherwax index ba01efc4..d283bf75 100644 --- a/host_vars/weatherwax +++ b/host_vars/weatherwax @@ -29,6 +29,20 @@ administratorenteam: - "3d" - "jabertwo" +drives: + sda1: + uuid: 6278aa48-6fc9-4889-be5f-d168627141b8 + path: / + fstype: ext4 + sda2: + uuid: aae468a2-1090-48f6-97fc-7366a84462f0 + path: none + fstype: swap + sdb1: + uuid: 9b1c727b-a836-4e2b-a6e8-ca8b5a8949a2 + path: /mnt/data + fstype: btrfs + # Monitoring aktivieren alert: load: diff --git a/site.yml b/site.yml index 8b2373b7..b08e5595 100644 --- a/site.yml +++ b/site.yml @@ -6,8 +6,9 @@ - hosts: all remote_user: root roles: - - { role: all/hostname, tags: common } - { role: all/common, tags: common } + - { role: all/hostname, tags: hostname } + - { role: all/mount, tags: mount} - { role: all/sysctl, tags: sysctl } ################################################## -- GitLab