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.

269 lines
7.1 KiB

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