| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- - name: Reset our set_facts
- set_fact:
- key_store_build: false
- - name: Add base_user to the group "{{ key_store_group }}"
- include_role:
- name: add_group
- vars:
- add_group_groups: "{{ key_store_group }}"
- - name: Determine if keys is mapped
- stat:
- path: "/dev/mapper/{{ key_store_crypt }}"
- register: key_store_luks
- - name: Determine if we should wipe the key_store
- set_fact:
- key_store_build: true
- when: key_store_luks.stat.exists is false or key_store_force
- - name: Drop the keyfile ramfs
- ansible.posix.mount:
- path: "{{ key_store_rammnt }}"
- src: ramfs
- fstype: ramfs
- state: absent
- when: key_store_build
- - name: Drop the local encrypted keystore
- ansible.posix.mount:
- path: "{{ key_store_datadir }}"
- src: "/dev/mapper/{{ key_store_crypt }}"
- fstype: xfs
- state: absent
- when: key_store_build
- - name: Drop the crypt device
- community.crypto.luks_device:
- state: closed
- name: keys
- when: key_store_build
- - name: Load the loop module
- community.general.modprobe:
- name: loop
- state: present
- when: key_store_build
- - name: Create a backing file
- file:
- path: "{{ key_store_file }}"
- owner: "{{ key_store_owner }}"
- group: "{{ key_store_group }}"
- mode: 0600
- state: touch
- when: key_store_build
- - name: Allocate backing file
- command:
- argv:
- - dd
- - if=/dev/zero
- - "of={{ key_store_file }}"
- - "bs={{ key_store_block }}"
- - "count={{ key_store_size }}"
- when: key_store_build
- - name: Attach the loop device
- command:
- argv:
- - losetup
- - --find
- - --show
- - "{{ key_store_file }}"
- register: key_store_lodev
- when: key_store_build
- - name: Mount ramfs for keyfile
- include_role:
- name: mount
- vars:
- mount_path: "{{ key_store_rammnt }}"
- mount_owner: "{{ key_store_owner }}"
- mount_group: "{{ key_store_group }}"
- mount_mode: '0700'
- mount_dev: ramfs
- mount_fs: ramfs
- when: key_store_build
- - name: Create the keyfile
- file:
- path: "{{ key_store_ramkey }}"
- owner: "{{ key_store_owner }}"
- group: "{{ key_store_group }}"
- mode: '0600'
- state: touch
- when: key_store_build
- - name: Generate a key
- command:
- argv:
- - dd
- - if=/dev/urandom
- - "of={{ key_store_file }}"
- - "bs={{ key_store_block }}"
- - "count={{ key_store_keysize }}"
- - iflag=fullblock
- when: key_store_build
- - name: Encrypt the loop device
- community.crypto.luks_device:
- device: "{{ key_store_lodev.stdout }}"
- state: opened
- cipher: aes-xts-plain64
- keyfile: "{{ key_store_ramkey }}"
- name: keys
- when: key_store_build
- - name: Drop the ramfs (and its keyfile)
- ansible.posix.mount:
- path: "{{ key_store_rammnt }}"
- state: absent
- when: key_store_build
- - name: Create a filesystem
- community.general.filesystem:
- fstype: xfs
- dev: "/dev/mapper/{{ key_store_crypt }}"
- when: key_store_build
- - name: Mount the encrypted keystore
- include_role:
- name: mount
- vars:
- mount_dev: "/dev/mapper/{{ key_store_crypt }}"
- mount_path: "{{ key_store_datadir }}"
- mount_owner: "{{ key_store_owner }}"
- mount_group: "{{ key_store_group }}"
- mount_mode: '0750'
- mount_fs: xfs
|