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
2022-12-26 00:53:10 +01:00

54 lines
1.3 KiB
YAML

# 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: "{{ item }}"
fstype: ext4
state: present
loop:
- "/dev/mapper/{{ hdd_name }}"
- "/dev/mapper/{{ ssd_name }}"
when: ansible_mounts | selectattr('device', 'eq', item) | length == 0
- name: Mount filesystems
mount:
src: "{{ item.dev }}"
path: "{{ item.path }}"
fstype: ext4
fstab: /tmp/fstab.ansible
state: mounted
loop:
- dev: "/dev/mapper/{{ hdd_name }}"
path: "{{ hdd_mount_point }}"
- dev: "/dev/mapper/{{ ssd_name }}"
path: "{{ ssd_mount_point }}"
when: ansible_mounts | selectattr('device', 'eq', item.dev) | length == 0
- name: Create swapfile
community.general.filesize:
path: "{{ ssd_mount_point }}/swapfile"
size: 2G
blocksize: 512B
owner: root
mode: u=rw,go=
when: ansible_swaptotal_mb == 0
- name: Mount swapfile
shell: |
mkswap {{ ssd_mount_point }}/swapfile
swapon {{ ssd_mount_point }}/swapfile
when: ansible_swaptotal_mb == 0