summaryrefslogtreecommitdiff
path: root/roles/storage/luks/volumes/tasks/main.yml
blob: 8fdb3019ea802bce2fa0390df20c49b244b39358 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
---
- name: install cryptsetup packages
  apt:
    name: cryptsetup-bin
    state: present

- name: Create temporary build directory
  tempfile:
    state: directory
  register: keyfile_dir
  changed_when: False
  check_mode: False

- name: create luks volumes
  block:
  - name: write passphrases into temporary keyfiles
    loop: "{{ luks_volumes | dict2items }}"
    loop_control:
      label: "{{ item.key }}"
    copy:
      dest: "{{ keyfile_dir.path }}/{{ item.key }}"
      content: "{{ item.value.passphrase }}"
      mode: 0600
    changed_when: False
    check_mode: False

  - name: create/open luks volumes
    loop: "{{ luks_volumes | dict2items }}"
    loop_control:
      label: "{{ item.key }} ({{ item.value.device }})"
    luks_device:
      name: "{{ item.key }}"
      device: "{{ item.value.device }}"
      keyfile: "{{ keyfile_dir.path }}/{{ item.key }}"
      state: opened

  always:
  - name: remove base-directory for keyfiles
    file:
      path: "{{ keyfile_dir.path }}"
      state: absent
    changed_when: False
    check_mode: False