main.yml 3.1 KB

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