Исправление по модулям luks + дополнительная проверка на ошибки
parent
aaf3abf692
commit
f6a5f76485
|
@ -1,37 +1,38 @@
|
|||
---
|
||||
- name: Create keyfile
|
||||
ansible.builtin.shell: |
|
||||
openssl genrsa -out /root/keyfile; chmod 0400 /root/keyfile
|
||||
ignore_errors: true
|
||||
community.crypto.openssl_privatekey:
|
||||
path: /root/keyfile
|
||||
|
||||
- name: Encrypt second disk
|
||||
ansible.builtin.shell: |
|
||||
cryptsetup -q luksFormat /dev/{{ sdisk_disk }} --key-file /root/keyfile
|
||||
ignore_errors: true
|
||||
|
||||
- name: Open encrypted second disk
|
||||
ansible.builtin.shell: |
|
||||
cryptsetup luksOpen /dev/{{ sdisk_disk }} {{ sdisk_name }} --key-file /root/keyfile
|
||||
- name: Create/Open encrypted second disk
|
||||
community.crypto.luks_device:
|
||||
device: "/dev/{{ sdisk_disk }}"
|
||||
state: "opened"
|
||||
name: "{{ sdisk_name }}"
|
||||
keyfile: "/root/keyfile"
|
||||
ignore_errors: true
|
||||
register: second_disk_status
|
||||
|
||||
- name: Format the encrypted second disk
|
||||
command: mkfs.ext4 /dev/mapper/{{ sdisk_name }}
|
||||
when: second_disk_status.rc == 0
|
||||
when: second_disk_status.failed|bool == false
|
||||
|
||||
- name: Ensure the mount point exists
|
||||
file:
|
||||
path: /mnt/{{ sdisk_name }}
|
||||
state: directory
|
||||
when: second_disk_status.failed|bool == false
|
||||
|
||||
- name: Mount the encrypted second disk
|
||||
mount:
|
||||
ansible.posix.mount:
|
||||
path: /mnt/{{ sdisk_name }}
|
||||
src: /dev/mapper/{{ sdisk_name }}
|
||||
fstype: ext4
|
||||
state: mounted
|
||||
register: second_disk_status
|
||||
when: second_disk_status.failed|bool == false
|
||||
|
||||
- name: Add crypttab
|
||||
ansible.builtin.shell: |
|
||||
printf "{{ sdisk_name }} /dev/{{ sdisk_disk }} /root/keyfile luks\n">/etc/crypttab
|
||||
when: second_disk_status.failed|bool == false
|
||||
|
||||
|
|
|
@ -12,24 +12,20 @@
|
|||
var: rroot_disk.stdout
|
||||
|
||||
- name: Create keyfile
|
||||
ansible.builtin.shell: |
|
||||
openssl genrsa -out /root/keyfile_rroot; chmod 0400 /root/keyfile_rroot
|
||||
community.crypto.openssl_privatekey:
|
||||
path: /root/keyfile_rroot
|
||||
ignore_errors: true
|
||||
when: rroot_disk.stdout | length > 0
|
||||
|
||||
- name: Encrypt rroot disk
|
||||
ansible.builtin.shell: |
|
||||
cryptsetup -q luksFormat /dev/{{ rroot_disk.stdout }} --key-file /root/keyfile_rroot
|
||||
- name: Create/Open encrypt rroot disk
|
||||
community.crypto.luks_device:
|
||||
device: "/dev/{{ rroot_disk.stdout }}"
|
||||
state: "opened"
|
||||
name: "{{ rroot_disk.stdout }}"
|
||||
keyfile: "/root/keyfile_rroot"
|
||||
ignore_errors: true
|
||||
when: rroot_disk.stdout | length > 0
|
||||
|
||||
- name: Open encrypted rroot disk
|
||||
ansible.builtin.shell: |
|
||||
cryptsetup luksOpen /dev/{{ rroot_disk.stdout }} {{ rroot_disk.stdout }} --key-file /root/keyfile_rroot
|
||||
ignore_errors: true
|
||||
register: rroot_disk_status
|
||||
when: rroot_disk.stdout | length > 0
|
||||
|
||||
- name: Format the encrypted rroot disk
|
||||
command: mkfs.ext4 /dev/mapper/{{ rroot_disk.stdout }}
|
||||
when: rroot_disk.stdout | length > 0
|
||||
|
|
Loading…
Reference in New Issue