An Ansible Playbook to deploy OpenLDAP and FusionDirectory
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.

251 lines
6.6KB

  1. ---
  2. # This will deploy OpenLDAP and FusionDirectory on the mailserver
  3. - name: Prepate /etc/hosts
  4. lineinfile:
  5. path: /etc/hosts
  6. insertafter: '^127.0.1.1 '
  7. line: "{{ item }}"
  8. with_items:
  9. - "127.0.2.1 mail.{{ domain }} mail"
  10. - "127.0.3.1 auth.{{ domain }} auth"
  11. - name: Setup OpenLDAP and Dependencies
  12. apt:
  13. name: "{{ item }}"
  14. state: present
  15. update_cache: yes
  16. with_items:
  17. - ldap-utils
  18. - gnutls-bin
  19. - ca-certificates
  20. - python-ldap
  21. - python3-ldap
  22. - name: debconf configuration for slapd
  23. debconf:
  24. name: slapd
  25. question: "{{ item.question }}"
  26. value: "{{ item.value }}"
  27. vtype: "{{ item.vtype }}"
  28. with_items:
  29. - { question: slapd/no_configuration, value: False, vtype: boolean }
  30. - { question: slapd/domain, value: "{{ domain }}", vtype: string }
  31. - { question: shared/organization, value: "{{ organization }}", vtype: string }
  32. - { question: slapd/password1, value: "{{ ldap_admin_pass }}", vtype: password }
  33. - { question: slapd/password2, value: "{{ ldap_admin_pass }}", vtype: password }
  34. - { question: slapd/backend, value: MDB, vtype: select }
  35. - { question: slapd/purge_database, value: False, vtype: boolean }
  36. - { question: slapd/move_old_database, value: True, vtype: boolean }
  37. no_log: True
  38. - name: install slapd
  39. apt:
  40. name: slapd
  41. state: present
  42. - name: Create the ROOT CA store
  43. file:
  44. path: /srv/CA
  45. state: directory
  46. - name: Generate the CA Certificate template
  47. template:
  48. src: templates/ca-cert.tmpl.j2
  49. dest: /srv/CA/ca-cert.tmpl
  50. - name: Generate the ROOT CA private key
  51. command: |
  52. certtool --generate-privkey \
  53. --outfile {{ domain }}-rootCA.key
  54. args:
  55. chdir: /srv/CA
  56. creates: "/srv/CA/{{ domain }}-rootCA.key"
  57. - name: Generate the ROOT CA Certificate
  58. command: |
  59. certtool --generate-self-signed \
  60. --template ca-cert.tmpl \
  61. --load-privkey {{ domain }}-rootCA.key \
  62. --outfile {{ domain }}-rootCA.crt
  63. args:
  64. chdir: /srv/CA
  65. creates: "/srv/CA/{{ domain }}-rootCA.crt"
  66. - name: Add our ROOT CA as trusted
  67. copy:
  68. remote_src: yes
  69. src: "/srv/CA/{{ domain }}-rootCA.crt"
  70. dest: /usr/local/share/ca-certificates/
  71. notify:
  72. - Update CA Certificates
  73. - name: Create the LDAP TLS store
  74. file:
  75. path: /etc/ldap/ssl
  76. owner: openldap
  77. group: openldap
  78. state: directory
  79. - name: Generate the LDAP Certificate template
  80. template:
  81. src: templates/ldap-cert.tmpl.j2
  82. dest: /srv/CA/ldap-cert.tmpl
  83. - name: Generate the LDAP private key
  84. command: |
  85. certtool --generate-privkey \
  86. --outfile {{ domain }}.key
  87. args:
  88. chdir: /etc/ldap/ssl
  89. creates: "/etc/ldap/ssl/{{ domain }}.key"
  90. - name: Generate the LDAP Certificate
  91. command: |
  92. certtool --generate-certificate \
  93. --template /srv/CA/ldap-cert.tmpl \
  94. --load-privkey {{ domain }}.key \
  95. --outfile {{ domain }}.crt \
  96. --load-ca-privkey /srv/CA/{{ domain }}-rootCA.key
  97. --load-ca-certificate /srv/CA/{{ domain }}-rootCA.crt
  98. args:
  99. chdir: /etc/ldap/ssl
  100. creates: "/etc/ldap/ssl/{{ domain }}.crt"
  101. - name: Set the correct ownership on the LDAP cert/key pair
  102. file:
  103. path: "/etc/ldap/ssl/{{ item }}"
  104. owner: openldap
  105. group: openldap
  106. with_items:
  107. - "{{ domain }}.key"
  108. - "{{ domain }}.crt"
  109. - name: Create the custom_ldifs store
  110. file:
  111. path: /etc/ldap/custom_ldifs
  112. owner: openldap
  113. group: openldap
  114. state: directory
  115. - name: Create the olcSSL.ldif file (LDAP TLS Configuration)
  116. template:
  117. src: templates/olcSSL.ldif.j2
  118. dest: /etc/ldap/custom_ldifs/olcSSL.ldif
  119. owner: openldap
  120. group: openldap
  121. notify:
  122. - Apply olcSSL.ldif
  123. - Restart slapd
  124. - name: Add an apt key by id from a keyserver
  125. apt_key:
  126. keyserver: keys.gnupg.net
  127. id: A94DE63F2EDB5F0DC0785EBBD744D55EACDA69FF
  128. - name: Add the Fusiondirectory repo
  129. apt_repository:
  130. repo: "{{ item }}"
  131. state: present
  132. with_items:
  133. - 'deb http://repos.fusiondirectory.org/fusiondirectory-current/debian-jessie jessie main'
  134. - 'deb http://repos.fusiondirectory.org/fusiondirectory-extra/debian-jessie jessie main'
  135. - name: Install FusionDirectory, dependencies and plugins
  136. apt:
  137. name: "{{ item }}"
  138. update_cache: yes
  139. state: present
  140. with_items:
  141. - apache2
  142. - libapache2-mod-php
  143. - php-ldap
  144. - php-intl
  145. - php-pear
  146. - php-mbstring
  147. - fusiondirectory
  148. - fusiondirectory-schema
  149. - fusiondirectory-plugin-ldapdump
  150. - fusiondirectory-plugin-ldapmanager
  151. - fusiondirectory-plugin-dsa
  152. - fusiondirectory-plugin-dsa-schema
  153. - fusiondirectory-plugin-systems
  154. - fusiondirectory-plugin-systems-schema
  155. notify:
  156. - Apply FusionDirectory Schema
  157. - Apply FusionDirectory Plugins Schema
  158. - name: Calculate FusionDirectory Configuration hash
  159. stat:
  160. path: /var/cache/fusiondirectory/class.cache
  161. get_md5: yes
  162. register: fd_config_hash
  163. - name: Generate the Initial FusionDirectory configuration
  164. template:
  165. src: templates/fd-init-config.ldif.j2
  166. dest: /etc/ldap/custom_ldifs/fd-init-config.ldif
  167. notify:
  168. - Initialize FusionDirectory Configuration
  169. - name: Migrate FusionDirectory Object Classes
  170. template:
  171. src: templates/fd-migrate-object-classes.ldif.j2
  172. dest: /etc/ldap/custom_ldifs/fd-migrate-object-classes.ldif
  173. notify:
  174. - Migrate Object Classes
  175. - name: Create an empty ldap.conf file
  176. file:
  177. path: /etc/ldap/ldap.conf
  178. state: touch
  179. notify:
  180. - Generate FusionDirectory SuperUser and OUs
  181. - name: Set FusionDirectory SuperUser Password
  182. command: |
  183. true
  184. notify:
  185. - Set SuperUser Password
  186. no_log: True
  187. - name: Migrate FusionDirectory Defaults ACLs
  188. template:
  189. src: templates/fd-migrate-default-acl.ldif.j2
  190. dest: /etc/ldap/custom_ldifs/fd-migrate-default-acl.ldif
  191. notify:
  192. - Migrate Default ACLs
  193. - name: Fix Permissions for the FusionDirectory Configuration
  194. template:
  195. src: templates/fusiondirectory.conf.j2
  196. dest: /etc/fusiondirectory/fusiondirectory.conf
  197. notify:
  198. - Fix FusionDirectory Configuration Permisions
  199. - name: Apply FusionDirectory Service Accounts ACL
  200. template:
  201. src: templates/fd-service_accounts_acl.ldif.j2
  202. dest: /etc/ldap/custom_ldifs/fd-service_accounts_acl.ldif
  203. notify:
  204. - Apply Service Accounts ACL
  205. - name: Create a .well-known directory
  206. file:
  207. path: /var/www/html/.well-known
  208. state: directory
  209. owner: www-data
  210. group: www-data
  211. - name: Deploy the Apache VirtualHosts for FusionDirectory
  212. template:
  213. src: "templates/fd-vhost{{ item }}.j2"
  214. dest: "/etc/apache2/sites-available/{{domain}}{{ item }}"
  215. with_items:
  216. - ".conf"
  217. - "-ssl.conf"
  218. notify:
  219. - Enable the Apache HTTP VirtualHost
  220. - Disable the Default Apache VirtualHost
  221. - Restart Apache