63 lines
1.5 KiB
YAML
63 lines
1.5 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: mounted_devices
|
|
|
|
- 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: mounted_devices.stdout | regex_search(item) is none
|
|
|
|
- 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: mounted_devices.stdout | regex_search(item.dev) is none
|
|
|
|
- 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.rc != 0
|
|
|
|
- name: Mount swapfile
|
|
shell: |
|
|
mkswap {{ ssd_mount_point }}/swapfile
|
|
swapon {{ ssd_mount_point }}/swapfile
|
|
when: swap_mounted.rc != 0
|