Playbooks to a new Lilik
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.

208 lines
4.9 KiB

  1. - include_role:
  2. name: service
  3. # static: yes # see static include issue: https://github.com/ansible/ansible/issues/13485
  4. vars:
  5. service_name: dovecot
  6. service_packages:
  7. - dovecot-ldap
  8. - dovecot-imapd
  9. - rsyslog
  10. - lineinfile: dest=/etc/postfix/main.cf line="virtual_transport = dovecot" state=present
  11. notify: restart postfix
  12. - blockinfile:
  13. dest: /etc/postfix/master.cf
  14. block: |
  15. dovecot unix - n n - - pipe
  16. flags=DRhu user=postman:postman argv=/usr/lib/dovecot/deliver -d ${recipient} -f ${sender}
  17. notify: restart postfix
  18. - name: create postman group
  19. group:
  20. name: postman
  21. state: present
  22. - name: create postman user
  23. user:
  24. name: postman
  25. state: present
  26. shell: /dev/null
  27. - name: edit dovecot configuration
  28. lineinfile:
  29. dest: /etc/dovecot/conf.d/10-master.conf
  30. line: ' port = 143'
  31. insertafter: 'inet_listener imap {'
  32. state: present
  33. notify: restart dovecot
  34. - blockinfile:
  35. dest: /etc/dovecot/conf.d/10-master.conf
  36. insertafter: 'inet_listener imaps {'
  37. marker: '#{mark} ANSIBLE BLOCK FOR IMAPS PORT'
  38. block: |
  39. port = 993
  40. ssl = yes
  41. notify: restart dovecot
  42. - blockinfile:
  43. dest: "/etc/dovecot/conf.d/10-master.conf"
  44. insertafter: "unix_listener auth-userdb {"
  45. marker: '#{mark} ANSIBLE BLOCK FOR AUTH USER'
  46. block: |
  47. group = postman
  48. mode = 0664
  49. user = postman
  50. notify: restart dovecot
  51. - lineinfile:
  52. dest: /etc/dovecot/conf.d/10-mail.conf
  53. line: 'mail_location = maildir:/home/postman/%d/%n'
  54. regexp: '^mail_location = '
  55. state: present
  56. notify: restart dovecot
  57. - lineinfile:
  58. dest: /etc/dovecot/conf.d/10-mail.conf
  59. line: 'mail_gid : postman'
  60. state: present
  61. notify: restart dovecot
  62. - lineinfile:
  63. dest: /etc/dovecot/conf.d/10-mail.conf
  64. line: 'mail_uid : postman'
  65. state: present
  66. notify: restart dovecot
  67. - lineinfile:
  68. dest: /etc/dovecot/conf.d/10-auth.conf
  69. line: "!include auth-system.conf.ext"
  70. state: absent
  71. notify: restart dovecot
  72. - lineinfile:
  73. dest: /etc/dovecot/conf.d/10-auth.conf
  74. line: "!include auth-ldap.conf.ext"
  75. state: present
  76. notify: restart dovecot
  77. - lineinfile:
  78. dest: /etc/dovecot/conf.d/10-auth.conf
  79. line: "auth_default_realm : {{ domain }}"
  80. notify: restart dovecot
  81. - lineinfile:
  82. dest: /etc/dovecot/conf.d/10-auth.conf
  83. line: "auth_mechanisms : login plain"
  84. notify: restart dovecot
  85. - name: enable ssl key
  86. blockinfile:
  87. dest: /etc/dovecot/conf.d/10-ssl.conf
  88. block: |
  89. ssl = yes
  90. ssl_cert = </etc/dovecot/dovecot.cert
  91. ssl_key = </etc/dovecot/private/dovecot.key
  92. - name: generate the RSA key
  93. openssl_privatekey:
  94. path: "/etc/dovecot/private/dovecot.key"
  95. size: 2048
  96. state: present
  97. type: RSA
  98. notify: restart dovecot
  99. - name: generate CSR
  100. openssl_csr:
  101. commonName: "{{ fqdn_domain }}"
  102. countryName: "IT"
  103. digest: sha256
  104. localityName: "TUSCANY"
  105. organizationName: "IT"
  106. path: "/etc/dovecot/private/dovecot.csr"
  107. privatekey_path: "/etc/dovecot/private/dovecot.key"
  108. state: present
  109. stateOrProvinceName: "ITALY"
  110. notify: restart dovecot
  111. - name: check if dovecot cert key exist
  112. stat:
  113. path: /etc/dovecot/dovecot.cert
  114. register: dovecot_cert_key
  115. - block:
  116. - name: get pub key
  117. slurp:
  118. src: "/etc/dovecot/private/dovecot.csr"
  119. register: pub_key
  120. - debug:
  121. var: pub_key
  122. verbosity: 2
  123. - name: generate host request
  124. set_fact:
  125. ca_request:
  126. type: 'sign_request'
  127. request:
  128. keyType: 'ssl_host'
  129. hostName: '{{ inventory_hostname }}.lilik.it'
  130. keyData: "{{ pub_key.content| b64decode}}"
  131. - debug:
  132. var: ca_request
  133. verbosity: 2
  134. - name: start sign request
  135. include: ca-dialog.yaml
  136. - debug:
  137. var: request_result
  138. verbosity: 2
  139. - set_fact:
  140. request_output: "{{ request_result.stdout|string|from_json }}"
  141. - debug:
  142. var: request_result
  143. - name: generate get request
  144. set_fact:
  145. ca_request:
  146. type: 'get_certificate'
  147. requestID: '{{ request_output.requestID }}'
  148. - debug:
  149. var: ca_request
  150. verbosity: 2
  151. - debug:
  152. msg: "Please manualy confirm sign request with id {{ request_output.requestID }}"
  153. - name: wait for cert
  154. include: ca-dialog.yaml
  155. - debug:
  156. var: request_result
  157. verbosity: 2
  158. - set_fact:
  159. cert_key: "{{ request_result.stdout|string|from_json }}"
  160. - debug:
  161. var: request_result
  162. verbosity: 2
  163. - name: set pub key
  164. copy:
  165. content: "{{ cert_key.result }}"
  166. dest: "/etc/dovecot/dovecot.cert"
  167. register: set_pub_key
  168. when: not dovecot_cert_key.stat.exists
  169. - template:
  170. src: dovecot-ldap.conf.ext.j2
  171. dest: /etc/dovecot/dovecot-ldap.conf.ext
  172. notify: restart dovecot