|
34 | 34 | state: mounted |
35 | 35 | changed_when: False |
36 | 36 |
|
37 | | -- name: LUKS format volumes |
38 | | - shell: > |
39 | | - cryptsetup isLuks /dev/{{ item.value.vg }}/{{ item.key }} || |
40 | | - cryptsetup luksFormat --batch-mode --verbose --key-file={{ |
41 | | - masterkey.path }}/keys/{{ ansible_hostname }}/{{ |
42 | | - item.key }} /dev/{{ item.value.vg }}/{{ item.key }} |
43 | | - register: luks_format |
44 | | - changed_when: ("Command successful" in luks_format.stdout) |
45 | | - with_dict: "{{ luks_volumes }}" |
46 | | - |
47 | | -# Encountered bug in ansible crypttab module, lineinfile is good enough |
48 | | -- name: Create crypttab |
49 | | - copy: |
50 | | - content: "" |
51 | | - dest: /etc/crypttab.setup |
52 | | - mode: 0644 |
53 | | - force: no |
54 | | - |
55 | | -- name: Crypt table entries |
56 | | - lineinfile: |
57 | | - line: "{{ 'luks-%-16s /dev/mapper/%s-%-16s %s/keys/%s/%-12s luks' % ( |
58 | | - item.key, item.value.vg, item.key, masterkey.path, ansible_hostname, |
59 | | - item.key) }}" |
60 | | - path: /etc/crypttab.setup |
61 | | - regexp: "^luks-{{ item.key }}.*" |
62 | | - with_dict: "{{ luks_volumes }}" |
63 | | - |
64 | | -# For unattended boot, we have a custom startup script, so we don't |
65 | | -# leave /etc/crypttab in place (Ubuntu systemd will otherwise |
66 | | -# insist on entering passphrase at reboot) |
67 | | - |
68 | | -- name: Temporary crypttab symlink |
69 | | - file: |
70 | | - path: /etc/crypttab |
71 | | - src: crypttab.setup |
72 | | - state: link |
73 | | - force: True |
74 | | - changed_when: False |
75 | | - |
76 | | -- name: LUKS start volumes |
77 | | - command: cryptdisks_start luks-{{ item.key }} |
78 | | - register: luks_start |
79 | | - changed_when: ("(started)" in luks_start.stdout) |
80 | | - with_dict: "{{ luks_volumes }}" |
81 | | - |
82 | | -- name: Create filesystem |
83 | | - filesystem: |
84 | | - dev: /dev/mapper/luks-{{ item.key }} |
85 | | - fstype: "{{ item.value.type if 'type' in item.value else fs_type }}" |
86 | | - opts: "{{ '-N %s000' % item.value.inodes if 'inodes' in item.value |
87 | | - else '' }} -m 0" |
88 | | - with_dict: "{{ luks_volumes }}" |
89 | | - |
90 | | -- name: Remove temporary crypttab symlink |
91 | | - file: |
92 | | - path: /etc/crypttab |
93 | | - state: absent |
94 | | - changed_when: False |
95 | | - |
96 | | -- name: crypt-setup boot script |
97 | | - template: |
98 | | - src: crypt-activate.sh.j2 |
99 | | - dest: /etc/crypt-activate.sh |
100 | | - mode: 0755 |
101 | | - |
102 | | -- name: Systemd unit file for crypt-vols |
103 | | - copy: |
104 | | - dest: /etc/systemd/system/crypt-vols.service |
105 | | - src: crypt-vols.service |
106 | | - |
107 | | -- name: Add fstab entries |
108 | | - mount: |
109 | | - fstype: "{{ item.value.type if 'type' in item.value else fs_type }}" |
110 | | - path: "{{ item.value.path }}" |
111 | | - src: "/dev/mapper/luks-{{ item.key }}" |
112 | | - opts: "{{ item.value.options if 'options' in item.value else '_netdev,noauto' }}" |
113 | | - state: present |
114 | | - with_dict: "{{ luks_volumes }}" |
115 | | - |
116 | | -- name: Enable crypt-vols |
117 | | - systemd: |
118 | | - name: crypt-vols |
119 | | - enabled: yes |
120 | | - state: restarted |
121 | | - changed_when: False |
122 | | - |
123 | | -- name: Unmount master key |
124 | | - mount: |
125 | | - path: "{{ masterkey.path }}" |
126 | | - state: unmounted |
127 | | - changed_when: False |
| 37 | +- name: Encrypted volume preparation |
| 38 | + block: |
| 39 | + - name: LUKS format volumes |
| 40 | + shell: > |
| 41 | + cryptsetup isLuks /dev/{{ item.value.vg }}/{{ item.key }} || |
| 42 | + cryptsetup luksFormat --batch-mode --verbose --key-file={{ |
| 43 | + masterkey.path }}/keys/{{ ansible_hostname }}/{{ |
| 44 | + item.key }} /dev/{{ item.value.vg }}/{{ item.key }} |
| 45 | + register: luks_format |
| 46 | + changed_when: ("Command successful" in luks_format.stdout) |
| 47 | + with_dict: "{{ luks_volumes }}" |
| 48 | + |
| 49 | + # Encountered bug in ansible crypttab module, lineinfile is good enough |
| 50 | + - name: Create crypttab |
| 51 | + copy: |
| 52 | + content: "" |
| 53 | + dest: /etc/crypttab.setup |
| 54 | + mode: 0644 |
| 55 | + force: no |
| 56 | + |
| 57 | + - name: Crypt table entries |
| 58 | + lineinfile: |
| 59 | + line: "{{ 'luks-%-16s /dev/mapper/%s-%-16s %s/keys/%s/%-12s luks' % ( |
| 60 | + item.key, item.value.vg, item.key, masterkey.path, ansible_hostname, |
| 61 | + item.key) }}" |
| 62 | + path: /etc/crypttab.setup |
| 63 | + regexp: "^luks-{{ item.key }}.*" |
| 64 | + with_dict: "{{ luks_volumes }}" |
| 65 | + |
| 66 | + # For unattended boot, we have a custom startup script, so we don't |
| 67 | + # leave /etc/crypttab in place (Ubuntu systemd will otherwise |
| 68 | + # insist on entering passphrase at reboot) |
| 69 | + |
| 70 | + - name: Temporary crypttab symlink |
| 71 | + file: |
| 72 | + path: /etc/crypttab |
| 73 | + src: crypttab.setup |
| 74 | + state: link |
| 75 | + force: True |
| 76 | + changed_when: False |
| 77 | + |
| 78 | + - name: LUKS start volumes |
| 79 | + command: cryptdisks_start luks-{{ item.key }} |
| 80 | + register: luks_start |
| 81 | + changed_when: ("(started)" in luks_start.stdout) |
| 82 | + with_dict: "{{ luks_volumes }}" |
| 83 | + |
| 84 | + - name: Create filesystem |
| 85 | + filesystem: |
| 86 | + dev: /dev/mapper/luks-{{ item.key }} |
| 87 | + fstype: "{{ item.value.type if 'type' in item.value else fs_type }}" |
| 88 | + opts: "{{ '-N %s000' % item.value.inodes if 'inodes' in item.value |
| 89 | + else '' }} -m 0" |
| 90 | + with_dict: "{{ luks_volumes }}" |
| 91 | + |
| 92 | + - name: Remove temporary crypttab symlink |
| 93 | + file: |
| 94 | + path: /etc/crypttab |
| 95 | + state: absent |
| 96 | + changed_when: False |
| 97 | + |
| 98 | + - name: crypt-setup boot script |
| 99 | + template: |
| 100 | + src: crypt-activate.sh.j2 |
| 101 | + dest: /etc/crypt-activate.sh |
| 102 | + mode: 0755 |
| 103 | + |
| 104 | + - name: Systemd unit file for crypt-vols |
| 105 | + copy: |
| 106 | + dest: /etc/systemd/system/crypt-vols.service |
| 107 | + src: crypt-vols.service |
| 108 | + |
| 109 | + - name: Add fstab entries |
| 110 | + mount: |
| 111 | + fstype: "{{ item.value.type if 'type' in item.value else fs_type }}" |
| 112 | + path: "{{ item.value.path }}" |
| 113 | + src: "/dev/mapper/luks-{{ item.key }}" |
| 114 | + opts: "{{ item.value.options if 'options' in item.value else '_netdev,noauto' }}" |
| 115 | + state: present |
| 116 | + with_dict: "{{ luks_volumes }}" |
| 117 | + |
| 118 | + - name: Enable crypt-vols |
| 119 | + systemd: |
| 120 | + name: crypt-vols |
| 121 | + enabled: yes |
| 122 | + state: restarted |
| 123 | + changed_when: False |
| 124 | + |
| 125 | + always: |
| 126 | + - name: Unmount master key |
| 127 | + mount: |
| 128 | + path: "{{ masterkey.path }}" |
| 129 | + state: unmounted |
| 130 | + changed_when: False |
0 commit comments