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-23 18:28:01 +01:00

67 lines
1.6 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: Get list of mounted devices
shell: mount
register: blk_list
- name: Create var mounted_devices
set_fact:
mounted_devices: "{{ blk_list.stdout_lines }}"
- name: Create filesystems if they do not exist
filesystem:
dev: "{{ item }}"
fstype: ext4
state: present
when: mounted_devices | select('search', item) | list | length == 0
loop:
- "/dev/mapper/{{ hdd_name }}"
- "/dev/mapper/{{ ssd_name }}"
- name: Mount filesystems
mount:
src: "{{ item.dev }}"
path: "{{ item.path }}"
fstype: ext4
fstab: /tmp/fstab.ansible
state: mounted
when: mounted_devices | select('search', item.dev) | list | length == 0
loop:
- dev: "/dev/mapper/{{ hdd_name }}"
path: "{{ hdd_mount_point }}"
- dev: "/dev/mapper/{{ ssd_name }}"
path: "{{ ssd_mount_point }}"
- name: Check if swapfile is mounted
shell: "swapon | grep -q '{{ ssd_mount_point }}/swapfile'"
ignore_errors: true
register: swap_mounted
- name: Create swapfile
community.general.filesize:
path: "{{ ssd_mount_point }}/swapfile"
size: 2G
blocksize: 512B
owner: root
mode: u=rw,go=
when: swap_mounted is undefined
- name: Mount swapfile
shell: |
mkswap {{ ssd_mount_point }}/swapfile
swapon {{ ssd_mount_point }}/swapfile
when: swap_mounted is undefined