This repository has been archived on 2023-12-29. You can view files and clone it, but cannot push or open issues or pull requests.
pi-ansible/roles/os_config/tasks/disks.yml

57 lines
1.3 KiB
YAML
Raw Normal View History

2022-12-22 22:34:09 +00:00
# vim: ft=yaml.ansible
---
- name: (Create and) open LUKS containers
luks_device:
uuid: "{{ item.disk.uuid }}"
passphrase: "{{ item.disk.luks_pw }}"
name: "{{ item.name }}"
type: luks2
state: opened
loop:
- disk: "{{ secrets.hdd }}"
name: "{{ hdd_name }}"
- disk: "{{ secrets.ssd }}"
name: "{{ ssd_name }}"
- name: Create filesystems if they do not exist
filesystem:
dev: "/dev/mapper/{{ item }}"
fstype: ext4
state: present
loop:
- "{{ hdd_name }}"
- "{{ ssd_name }}"
- name: Mount filesystems
mount:
src: "/dev/disk/by-uuid/{{ item.uuid }}"
path: "{{ item.path }}"
fstype: ext4
2022-12-23 15:57:37 +00:00
fstab: /dev/null
state: present
2022-12-22 22:34:09 +00:00
loop:
- uuid: "{{ secrets.hdd.uuid }}"
path: "{{ hdd_mount_point }}"
- uuid: "{{ secrets.ssd.uuid }}"
path: "{{ ssd_mount_point }}"
2022-12-23 15:57:37 +00:00
- name: Check if swapfile is mounted
shell: "swapon | grep -q '{{ ssd_mount_point }}/swapfile'"
ignore_errors: true
register: swap_mounted
2022-12-22 22:34:09 +00:00
- name: Create swapfile
community.general.filesize:
path: "{{ ssd_mount_point }}/swapfile"
2022-12-23 15:57:37 +00:00
size: 2G
blocksize: 512B
2022-12-23 14:54:29 +00:00
owner: root
2022-12-23 15:57:37 +00:00
mode: u=rw,go=
when: swap_mounted is undefined
2022-12-22 22:34:09 +00:00
- name: Mount swapfile
shell: |
mkswap {{ ssd_mount_point }}/swapfile
swapon {{ ssd_mount_point }}/swapfile
2022-12-23 15:57:37 +00:00
when: swap_mounted is undefined