You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 line
2.5KB

  1. ---
  2. - setup:
  3. gather_subset: "!all"
  4. - name: debian apt install packages
  5. apt:
  6. pkg: "{{ item }}"
  7. state: installed
  8. with_items:
  9. - cryptsetup
  10. when: ansible_os_family == "Debian"
  11. - name: close
  12. command:
  13. cryptsetup close
  14. {{ item.name }}
  15. with_items: "{{ dmcrypt_devices }}"
  16. when:
  17. dmcrypt_devices_state == "closed"
  18. - name: ramdisk
  19. mount:
  20. src: ram
  21. fstype: ramfs
  22. name: /ram
  23. state: mounted
  24. when:
  25. dmcrypt_devices_state == "formated" or
  26. dmcrypt_devices_state == "wiped" or
  27. dmcrypt_devices_state == "opened"
  28. - name: keyfile directory
  29. file:
  30. path: /ram/dmcrypt_devices/
  31. owner: root
  32. group: root
  33. mode: 0700
  34. state: directory
  35. when:
  36. dmcrypt_devices_state == "formated" or
  37. dmcrypt_devices_state == "wiped" or
  38. dmcrypt_devices_state == "opened"
  39. - name: shred device
  40. command: shred --iterations={{ dmcrypt_devices_shred_iterations }} {{ item.device }}
  41. with_items: "{{ dmcrypt_devices }}"
  42. when:
  43. dmcrypt_devices_state == "wiped" or
  44. dmcrypt_devices_state == "erased"
  45. - name: keyfile
  46. copy:
  47. content: "{{ item.key }}"
  48. dest: /ram/dmcrypt_devices/{{ item.name }}
  49. with_items: "{{ dmcrypt_devices }}"
  50. when:
  51. dmcrypt_devices_state == "formated" or
  52. dmcrypt_devices_state == "wiped" or
  53. dmcrypt_devices_state == "opened"
  54. - name: luksFormat
  55. command:
  56. cryptsetup luksFormat
  57. --cipher {{ item.cipher }}
  58. --hash {{ item.hash }}
  59. --key-size {{ item.key_size }}
  60. {{ item.device }}
  61. /ram/dmcrypt_devices/{{ item.name }}
  62. with_items: "{{ dmcrypt_devices }}"
  63. when:
  64. dmcrypt_devices_state == "formated" or
  65. dmcrypt_devices_state == "wiped"
  66. - name: open
  67. command:
  68. cryptsetup open --type luks
  69. --key-file=/ram/dmcrypt_devices/{{ item.name }}
  70. {{ item.discard | default(false) | ternary('--allow-discards','') }}
  71. {{ item.device }}
  72. {{ item.name }}
  73. with_items: "{{ dmcrypt_devices }}"
  74. when:
  75. dmcrypt_devices_state == "formated" or
  76. dmcrypt_devices_state == "opened"
  77. - name: wipe keyfile
  78. command: shred /ram/dmcrypt_devices/{{ item.name }}
  79. with_items: "{{ dmcrypt_devices }}"
  80. when:
  81. dmcrypt_devices_state == "formated" or
  82. dmcrypt_devices_state == "wiped" or
  83. dmcrypt_devices_state == "opened"
  84. - name: remove keyfile
  85. file:
  86. path: /ram/dmcrypt_devices/{{ item.name }}
  87. state: absent
  88. with_items: "{{ dmcrypt_devices }}"
  89. when:
  90. dmcrypt_devices_state == "formated" or
  91. dmcrypt_devices_state == "wiped" or
  92. dmcrypt_devices_state == "opened"