lab-ansible/roles/common/tasks/disks.yml
2023-10-29 01:49:29 +02:00

53 lines
1.3 KiB
YAML

# vim: ft=yaml.ansible
---
- name: (Create and) open LUKS containers
community.crypto.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 }}"
no_log: true
- name: Create filesystems if they do not exist
community.general.filesystem:
dev: "{{ item }}"
fstype: ext4
state: present
loop:
- /dev/mapper/{{ hdd_name }}
- /dev/mapper/{{ ssd_name }}
- name: Mount filesystems
ansible.posix.mount:
src: "{{ item.dev }}"
path: "{{ item.path }}"
fstype: ext4
state: ephemeral
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
ansible.builtin.shell: |
mkswap {{ ssd_mount_point }}/swapfile
swapon {{ ssd_mount_point }}/swapfile
when: ansible_swaptotal_mb == 0