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.

150 lines
4.8 KiB

  1. - include: service.yaml
  2. # static: yes # see static include issue: https://github.com/ansible/ansible/issues/13485
  3. vars:
  4. service_name: dovecot
  5. service_packages:
  6. - dovecot-ldap
  7. - dovecot-imapd
  8. - rsyslog
  9. - lineinfile: dest=/etc/postfix/main.cf line="virtual_transport = dovecot" state=present
  10. notify: restart postfix
  11. - blockinfile:
  12. dest: /etc/postfix/master.cf
  13. block: |
  14. dovecot unix - n n - - pipe
  15. flags=DRhu user=postman:postman argv=/usr/lib/dovecot/deliver -d ${recipient} -f ${sender}
  16. notify: restart postfix
  17. - name: create postman group
  18. group: name=postman state=present
  19. - name: create postman user
  20. user: name=postman state=present shell=/dev/null
  21. - name: edit dovecot configuration
  22. lineinfile: dest=/etc/dovecot/conf.d/10-master.conf line=' port = 143' insertafter='inet_listener imap {' state=present
  23. notify: restart dovecot
  24. - blockinfile:
  25. dest: /etc/dovecot/conf.d/10-master.conf
  26. insertafter: 'inet_listener imaps {'
  27. marker: '#{mark} ANSIBLE BLOCK FOR IMAPS PORT'
  28. block: |
  29. port = 993
  30. ssl = yes
  31. notify: restart dovecot
  32. - blockinfile:
  33. dest: "/etc/dovecot/conf.d/10-master.conf"
  34. insertafter: "unix_listener auth-userdb {"
  35. marker: '#{mark} ANSIBLE BLOCK FOR AUTH USER'
  36. block: |
  37. group = postman
  38. mode = 0664
  39. user = postman
  40. notify: restart dovecot
  41. - lineinfile: dest=/etc/dovecot/conf.d/10-mail.conf line='mail_location = maildir:/home/postman/%d/%n' regexp='^mail_location = ' state=present
  42. notify: restart dovecot
  43. - lineinfile: dest=/etc/dovecot/conf.d/10-mail.conf line='mail_gid = postman' state=present
  44. notify: restart dovecot
  45. - lineinfile: dest=/etc/dovecot/conf.d/10-mail.conf line='mail_uid = postman' state=present
  46. notify: restart dovecot
  47. - lineinfile: dest=/etc/dovecot/conf.d/10-auth.conf line="!include auth-system.conf.ext" state=absent
  48. notify: restart dovecot
  49. - lineinfile: dest=/etc/dovecot/conf.d/10-auth.conf line="!include auth-ldap.conf.ext" state=present
  50. notify: restart dovecot
  51. - lineinfile: dest=/etc/dovecot/conf.d/10-auth.conf line="auth_default_realm = {{ domain }}"
  52. notify: restart dovecot
  53. - lineinfile: dest=/etc/dovecot/conf.d/10-auth.conf line="auth_mechanisms = login plain"
  54. notify: restart dovecot
  55. - name: enable ssl key
  56. blockinfile:
  57. dest: /etc/dovecot/conf.d/10-ssl.conf
  58. block: |
  59. ssl = yes
  60. ssl_cert = </etc/dovecot/dovecot.cert
  61. ssl_key = </etc/dovecot/private/dovecot.key
  62. - name: generate the RSA key
  63. shell: "openssl genrsa -out /etc/dovecot/private/dovecot.key 2048"
  64. args:
  65. creates: /etc/dovecot/private/dovecot.key
  66. notify: restart dovecot
  67. - name: create CSR
  68. shell: 'openssl req -new -sha256 -subj "/C=IT/ST=ITALY/L=TUSCANY/O=IT/CN={{ fqdn_domain }}" -key /etc/dovecot/private/dovecot.key -out /etc/dovecot/private/dovecot.csr'
  69. args:
  70. creates: /etc/dovecot/private/dovecot.csr
  71. notify: restart dovecot
  72. - name: check if dovecot cert key exist
  73. stat:
  74. path: /etc/dovecot/dovecot.cert
  75. register: dovecot_cert_key
  76. - block:
  77. - name: get pub key
  78. shell: "cat /etc/dovecot/private/dovecot.csr"
  79. register: pub_key
  80. - debug: var=pub_key verbosity=2
  81. - name: generate host request
  82. set_fact:
  83. cert_request:
  84. type: 'sign_request'
  85. request:
  86. keyType: 'ssl_host'
  87. hostName: '{{ inventory_hostname }}'
  88. keyData: '{{ pub_key.stdout }}'
  89. - debug: var=cert_request verbosity=2
  90. - name: start sign request
  91. raw: "{{ cert_request | to_json }}"
  92. delegate_to: "{{item}}"
  93. delegate_facts: True
  94. with_items: "{{groups['cas']}}"
  95. register: request_result
  96. - debug: var=request_result verbosity=2
  97. - set_fact:
  98. request_output: "{{ request_result.results[0].stdout|string|from_json }}"
  99. - debug: var=request_output
  100. - name: generate get request
  101. set_fact:
  102. get_request:
  103. type: 'get_certificate'
  104. requestID: '{{ request_output.requestID }}'
  105. - debug: var=get_request verbosity=2
  106. - debug: msg="Please manualy confirm sign request with id {{ request_output.requestID }}"
  107. - name: wait for cert
  108. raw: "{{ get_request | to_json }}"
  109. delegate_to: "{{item}}"
  110. delegate_facts: True
  111. with_items: "{{groups['cas']}}"
  112. register: cert_result
  113. - debug: var=cert_result verbosity=2
  114. - set_fact:
  115. cert_key: "{{ cert_result.results[0].stdout|string|from_json }}"
  116. - debug: var=request_output verbosity=2
  117. - name: set pub key
  118. shell: "echo '{{ cert_key.result }}' > /etc/dovecot/dovecot.cert"
  119. register: set_pub_key
  120. when: not dovecot_cert_key.stat.exists
  121. - template: src=dovecot-ldap.conf.ext.j2 dest=/etc/dovecot/dovecot-ldap.conf.ext
  122. notify: restart dovecot