main.yml 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. - name: Determine if keys is mapped
  2. stat:
  3. path: "/dev/mapper/{{ key_store_crypt }}"
  4. register: key_store_luks
  5. - name: Determine if we should wipe the key_store
  6. set_fact:
  7. key_store_build: true
  8. when: key_store_luks.stat.exists is false or key_store_force
  9. - name: Drop the keyfile ramfs
  10. ansible.posix.mount:
  11. path: "{{ key_store_rammnt }}"
  12. src: ramfs
  13. fstype: ramfs
  14. state: absent
  15. when: key_store_build
  16. - name: Drop the local encrypted keystore
  17. ansible.posix.mount:
  18. path: "{{ key_store_datadir }}"
  19. src: "/dev/mapper/{{ key_store_crypt }}"
  20. fstype: xfs
  21. state: absent
  22. when: key_store_build
  23. - name: Drop the crypt device
  24. community.crypto.luks_device:
  25. state: closed
  26. name: keys
  27. when: key_store_build
  28. - name: Add base_user to the group "{{ key_store_group }}"
  29. include_role:
  30. name: add_group
  31. vars:
  32. add_group_groups: "{{ key_store_group }}:{{ key_store_gid }}"
  33. when: key_store_build
  34. - name: Load the loop module
  35. community.general.modprobe:
  36. name: loop
  37. state: present
  38. when: key_store_build
  39. - name: Create a backing file
  40. file:
  41. path: "{{ key_store_file }}"
  42. owner: "{{ key_store_owner }}"
  43. group: "{{ key_store_group }}"
  44. mode: 0600
  45. state: touch
  46. when: key_store_build
  47. - name: Allocate backing file
  48. command:
  49. argv:
  50. - dd
  51. - if=/dev/zero
  52. - "of={{ key_store_file }}"
  53. - "bs={{ key_store_block }}"
  54. - "count={{ key_store_size }}"
  55. when: key_store_build
  56. - name: Attach the loop device
  57. command:
  58. argv:
  59. - losetup
  60. - --find
  61. - --show
  62. - "{{ key_store_file }}"
  63. register: key_store_lodev
  64. when: key_store_build
  65. - name: Mount ramfs for keyfile
  66. include_role:
  67. name: mount
  68. vars:
  69. mount_path: "{{ key_store_rammnt }}"
  70. mount_owner: "{{ key_store_owner }}"
  71. mount_group: "{{ key_store_group }}"
  72. mount_mode: '0700'
  73. mount_dev: ramfs
  74. mount_fs: ramfs
  75. when: key_store_build
  76. - name: Create the keyfile
  77. file:
  78. path: "{{ key_store_ramkey }}"
  79. owner: "{{ key_store_owner }}"
  80. group: "{{ key_store_group }}"
  81. mode: '0600'
  82. state: touch
  83. when: key_store_build
  84. - name: Generate a key
  85. command:
  86. argv:
  87. - dd
  88. - if=/dev/urandom
  89. - "of={{ key_store_file }}"
  90. - "bs={{ key_store_block }}"
  91. - "count={{ key_store_keysize }}"
  92. - iflag=fullblock
  93. when: key_store_build
  94. - name: Encrypt the loop device
  95. community.crypto.luks_device:
  96. device: "{{ key_store_lodev.stdout }}"
  97. state: opened
  98. cipher: aes-xts-plain64
  99. keyfile: "{{ key_store_ramkey }}"
  100. name: keys
  101. when: key_store_build
  102. - name: Drop the ramfs (and its keyfile)
  103. ansible.posix.mount:
  104. path: "{{ key_store_rammnt }}"
  105. state: absent
  106. when: key_store_build
  107. - name: Create a filesystem
  108. community.general.filesystem:
  109. fstype: xfs
  110. dev: "/dev/mapper/{{ key_store_crypt }}"
  111. when: key_store_build
  112. - name: Mount the encrypted keystore
  113. include_role:
  114. name: mount
  115. vars:
  116. mount_path: "{{ key_store_datadir }}"
  117. mount_owner: "{{ key_store_owner }}"
  118. mount_group: "{{ key_store_group }}"
  119. mount_mode: '0750'
  120. mount_dev: "/dev/mapper/{{ key_store_crypt }}"
  121. mount_fs: xfs
  122. mount_opts: "defaults,noatime"