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.

254 lines
6.8 KiB

  1. ---
  2. - name: configure exim4-config
  3. debconf:
  4. name: 'exim4-config'
  5. question: '{{ item.key }}'
  6. vtype: 'string'
  7. value: '{{ item.value }}'
  8. with_dict:
  9. exim4/dc_smarthost: '{{ stmp_relay }}'
  10. exim4/dc_minimaldns: false
  11. exim4/dc_postmaster:
  12. exim4/dc_localdelivery: mbox format in /var/mail/
  13. exim4/dc_readhost:
  14. exim4/dc_other_hostnames: '{{ ansible_hostname }}.lilik.it'
  15. exim4/dc_relay_nets:
  16. exim4/exim4-config-title:
  17. exim4/no_config: false
  18. exim4/mailname: '{{ ansible_hostname }}.lilik.it'
  19. exim4/use_split_config: false
  20. exim4/hide_mailname: false
  21. exim4/dc_relay_domains:
  22. notify:
  23. - update exim4 configuration
  24. - restart exim4
  25. - name: configure exim4-config (sympa_transport)
  26. debconf:
  27. name: 'exim4-config'
  28. question: '{{ item.key }}'
  29. vtype: 'string'
  30. value: '{{ item.value }}'
  31. with_dict:
  32. exim4/dc_eximconfig_configtype: mail sent by smarthost; received via SMTP or fetchmail
  33. exim4/dc_local_interfaces:
  34. when: sympa_transport | bool
  35. notify:
  36. - update exim4 configuration
  37. - restart exim4
  38. - name: configure exim4-config (smarthost)
  39. debconf:
  40. name: 'exim4-config'
  41. question: '{{ item.key }}'
  42. vtype: 'string'
  43. value: '{{ item.value }}'
  44. with_dict:
  45. exim4/dc_eximconfig_configtype: mail sent by smarthost; no local mail
  46. exim4/dc_local_interfaces: 127.0.0.1 ; ::1
  47. when: not sympa_transport | bool
  48. notify:
  49. - update exim4 configuration
  50. - restart exim4
  51. - block:
  52. - include_role:
  53. name: service
  54. # static: yes # see static include issue: https://github.com/ansible/ansible/issues/13485
  55. vars:
  56. service_name: exim4
  57. service_packages:
  58. - exim4
  59. - name: generate the RSA key
  60. # TODO: reenable openssl_privatekey when moving to ansible 2.3
  61. # openssl_privatekey:
  62. # path: "/etc/exim4/exim.key"
  63. # size: 2048
  64. # state: present
  65. # type: RSA
  66. shell: "openssl genrsa -out /etc/exim4/exim.key 2048"
  67. args:
  68. creates: /etc/exim4/exim.key
  69. notify: restart exim4
  70. - name: generate CSR
  71. # TODO: reenable openssl_csr when moving to ansible 2.3
  72. # openssl_csr:
  73. # commonName: "{{ fqdn_domain }}"
  74. # countryName: "IT"
  75. # digest: sha256
  76. # localityName: "TUSCANY"
  77. # organizationName: "IT"
  78. # path: "/etc/exim4/exim.csr"
  79. # privatekey_path: "/etc/exim4/exim.key"
  80. # state: present
  81. # stateOrProvinceName: "ITALY"
  82. shell: 'openssl req -new -sha256 -subj "/C=IT/ST=ITALY/L=TUSCANY/O=IT/CN={{ fqdn_domain }}" -key /etc/exim4/exim.key -out /etc/exim4/exim.csr'
  83. args:
  84. creates: /etc/exim4/exim.csr
  85. notify: restart exim4
  86. - name: lookup ssl ca key
  87. set_fact:
  88. ssl_ca_key: "{{ lookup('file', 'lilik_ca_w1.pub') }}"
  89. - name: Update ssl CA key
  90. copy:
  91. content: "{{ ssl_ca_key }}"
  92. dest: "/etc/exim4/ssl_ca.crt"
  93. - name: check if exim4 cert is valid
  94. command: 'openssl verify -CAfile /etc/exim4/ssl_ca.crt /etc/exim4/exim.crt'
  95. register: exim4_cert_is_valid
  96. changed_when: false
  97. failed_when: false
  98. - block:
  99. - name: generate host request
  100. cert_request:
  101. proto: 'ssl'
  102. host: '{{ inventory_hostname }}.lilik.it'
  103. path: "/etc/exim4/exim.csr"
  104. register: ca_request
  105. - name: start sign request
  106. include: ca-dialog.yaml
  107. - debug:
  108. var: request_result
  109. verbosity: 2
  110. - set_fact:
  111. request_output: "{{ request_result.stdout|string|from_json }}"
  112. - debug:
  113. var: request_result
  114. - name: generate get request
  115. set_fact:
  116. ca_request:
  117. type: 'get_certificate'
  118. requestID: '{{ request_output.requestID }}'
  119. - debug:
  120. var: authorities_request
  121. verbosity: 2
  122. - debug:
  123. msg: "Please manualy confirm sign request with id {{ request_output.requestID }}"
  124. - name: wait for cert
  125. include: ca-dialog.yaml
  126. - debug:
  127. var: request_result
  128. verbosity: 2
  129. - set_fact:
  130. cert_key: "{{ request_result.stdout|string|from_json }}"
  131. - debug:
  132. var: request_result
  133. verbosity: 2
  134. - name: set pub key
  135. copy:
  136. content: "{{ cert_key.result }}"
  137. dest: "/etc/exim4/exim.crt"
  138. register: set_pub_key
  139. when: 'exim4_cert_is_valid.rc != 0'
  140. - include_role:
  141. name: service
  142. vars:
  143. service_name: opendkim
  144. service_packages:
  145. - opendkim
  146. - opendkim-tools
  147. - name: create opendkim folder
  148. file:
  149. path: /etc/opendkim/
  150. state: directory
  151. mode: 0750
  152. owner: root
  153. group: Debian-exim
  154. - name: create opendkim key for lilik.it
  155. command: "opendkim-genkey -D /etc/opendkim/ -d {{ fqdn_domain }} -s {{ ansible_hostname }}"
  156. args:
  157. creates: '/etc/opendkim/{{ ansible_hostname }}.private'
  158. - name: check /etc/opendkim/{{ ansible_hostname }}.private permissions
  159. file:
  160. path: '/etc/opendkim/{{ ansible_hostname }}.private'
  161. owner: root
  162. group: Debian-exim
  163. mode: 0640
  164. - name: exim4 macro for TLS, DKIM
  165. blockinfile:
  166. dest: /etc/exim4/exim4.conf.localmacros
  167. block: |
  168. MAIN_TLS_ENABLE = yes
  169. DKIM_CANON = relaxed
  170. DKIM_SELECTOR = {{ ansible_hostname}}
  171. DKIM_DOMAIN = {{ fqdn_domain }}
  172. DKIM_PRIVATE_KEY = /etc/opendkim/{{ ansible_hostname }}.private
  173. create: yes
  174. marker: "# {mark} ANSIBLE MANAGED BLOCK 1"
  175. notify:
  176. - update exim4 configuration
  177. - restart exim4
  178. - block:
  179. - name: exim4 macro for sympa aliases
  180. blockinfile:
  181. dest: /etc/exim4/exim4.conf.localmacros
  182. block: |
  183. #--------------
  184. # Activating pipe transport in system_aliases router (pipes in /etc/aliases)
  185. .ifndef SYSTEM_ALIASES_PIPE_TRANSPORT
  186. SYSTEM_ALIASES_PIPE_TRANSPORT = address_pipe
  187. .endif
  188. .ifndef SYSTEM_ALIASES_USER
  189. SYSTEM_ALIASES_USER = sympa
  190. .endif
  191. .ifndef SYSTEM_ALIASES_GROUP
  192. SYSTEM_ALIASES_GROUP = sympa
  193. .endif
  194. #--------------
  195. create: yes
  196. marker: "# {mark} ANSIBLE MANAGED BLOCK 2"
  197. notify:
  198. - update exim4 configuration
  199. - restart exim4
  200. - name: exim4 pipe for sympa aliases
  201. blockinfile:
  202. dest: /etc/exim4/exim4.conf.template
  203. block: |
  204. #--------------
  205. # Using alias pipe definitions for the Sympa lists in /etc/mail/sympa/aliases
  206. sympa_aliases:
  207. debug_print = "R: system_aliases for $local_part@$domain"
  208. driver = redirect
  209. domains = +local_domains
  210. allow_fail
  211. allow_defer
  212. data = ${lookup{$local_part}lsearch{/etc/mail/sympa/aliases}}
  213. user = sympa
  214. group = sympa
  215. pipe_transport = address_pipe
  216. #--------------
  217. insertbefore: 'system_aliases:'
  218. notify:
  219. - update-exim4.conf
  220. - restart exim4
  221. when: sympa_transport | bool