install_389ds.yml 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. # Copyright 2022 Dell Inc. or its subsidiaries. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. ---
  15. - name: Initialize ds389_status
  16. set_fact:
  17. ds389_status: false
  18. - name: Fetch hostname
  19. command: hostname
  20. register: new_serv_hostname
  21. changed_when: false
  22. - name: Set fact for server hostname
  23. set_fact:
  24. server_hostname_ms: "{{ new_serv_hostname.stdout }}"
  25. - name: Check password policy in 389-ds
  26. command: dsconf -w {{ ms_directory_manager_password }} -D "cn=Directory Manager" ldap://{{ server_hostname_ms }} pwpolicy get
  27. changed_when: true
  28. failed_when: false
  29. no_log: true
  30. register: ds389_pwpolicy_check
  31. - name: Check ds389_status admin authentication
  32. shell: set -o pipefail && echo {{ ms_kerberos_admin_password }} | kinit {{ ms_ipa_admin_username }}
  33. changed_when: false
  34. failed_when: false
  35. no_log: true
  36. register: ds389_status_authentication
  37. - name: Gathering service facts
  38. service_facts:
  39. - name: Modify ds389_status
  40. set_fact:
  41. ds389_status: true
  42. when:
  43. - ds389_status_authentication.rc == 0
  44. - ds389_pwpolicy_search_key in ds389_pwpolicy_check.stdout
  45. - "'sssd.service' in ansible_facts.services"
  46. - sssd_install_search_key in ansible_facts.services['sssd.service'].state
  47. - block:
  48. - name: Install 389-ds
  49. zypper:
  50. name: "{{ ds389_packages }}"
  51. state: present
  52. - name: Check ldap instance is running or not
  53. command: dsctl {{ ldap_instance }} status
  54. changed_when: false
  55. failed_when: false
  56. register: ldap1_status
  57. - name: Create the ldap1.inf file
  58. copy:
  59. src: "{{ role_path }}/files/temp_ldap1.inf"
  60. dest: "{{ ldap1_config_path }}"
  61. mode: "{{ file_mode }}"
  62. when: ldap1_search_key in ldap1_status.stdout
  63. - name: Configure ldap1.inf with domain name
  64. lineinfile:
  65. path: "{{ ldap1_config_path }}"
  66. regexp: "^suffix = dc=omnia,dc=test"
  67. line: "suffix = dc={{ domain_name.split('.')[0] }},dc={{ domain_name.split('.')[1] }}"
  68. when: ldap1_search_key in ldap1_status.stdout
  69. - name: Configure ldap1.inf with directory manager password
  70. lineinfile:
  71. path: "{{ ldap1_config_path }}"
  72. regexp: "^root_password = password"
  73. line: "root_password = {{ ms_directory_manager_password }}"
  74. no_log: true
  75. when: ldap1_search_key in ldap1_status.stdout
  76. - name: Creating 389 directory server instance
  77. shell: dscreate -v from-file {{ ldap1_config_path }} | tee {{ ldap1_output_path }}
  78. changed_when: true
  79. when: ldap1_search_key in ldap1_status.stdout
  80. - name: Remove the ldap1.inf
  81. file:
  82. path: "{{ ldap1_config_path }}"
  83. state: absent
  84. - name: Start dirsrv service
  85. systemd:
  86. name: "dirsrv@{{ ldap_instance }}.service"
  87. state: started
  88. enabled: yes
  89. - name: Create the dsrc file
  90. copy:
  91. src: "{{ role_path }}/files/temp_dsrc"
  92. dest: "{{ dsrc_path }}"
  93. mode: "{{ file_mode }}"
  94. - name: Configure dsrc file with domain name
  95. lineinfile:
  96. path: "{{ dsrc_path }}"
  97. regexp: "^basedn = dc=omnia,dc=test"
  98. line: "basedn = dc={{ domain_name.split('.')[0] }},dc={{ domain_name.split('.')[1] }}"
  99. - name: Permit traffic in default zone for ldap and ldaps service
  100. firewalld:
  101. service: "{{ item }}"
  102. permanent: yes
  103. state: enabled
  104. with_items: "{{ ldap_services }}"
  105. - name: Reload firewalld
  106. command: firewall-cmd --reload
  107. changed_when: true
  108. - name: Install kerberos packages
  109. zypper:
  110. name: "{{ kerberos_packages }}"
  111. state: present
  112. - name: Check kerberos principal is created or not
  113. stat:
  114. path: "{{ kerberos_principal_path }}"
  115. register: principal_status
  116. - name: Create the kerberos conf file
  117. copy:
  118. src: "{{ role_path }}/files/temp_krb5.conf"
  119. dest: "{{ kerberos_conf_path }}"
  120. mode: "{{ file_mode }}"
  121. when: not principal_status.stat.exists
  122. - name: Configure kerberos conf file with domain name
  123. replace:
  124. path: "{{ kerberos_conf_path }}"
  125. regexp: "omnia.test"
  126. replace: "{{ domain_name }}"
  127. when: not principal_status.stat.exists
  128. - name: Configure kerberos conf file with realm name
  129. replace:
  130. path: "{{ kerberos_conf_path }}"
  131. regexp: "OMNIA.TEST"
  132. replace: "{{ realm_name }}"
  133. when: not principal_status.stat.exists
  134. - name: Configure kerberos conf file with hostname
  135. replace:
  136. path: "{{ kerberos_conf_path }}"
  137. regexp: "hostname"
  138. replace: "{{ short_hostname.stdout }}"
  139. when: not principal_status.stat.exists
  140. - block:
  141. - name: Setting up the kerberos database
  142. command: "kdb5_util -r {{ realm_name }} -P {{ ms_directory_manager_password }} create -s"
  143. no_log: true
  144. changed_when: true
  145. register: setting_database
  146. environment:
  147. PATH: "{{ ansible_env.PATH }}:{{ kerberos_env_path }}"
  148. when: not principal_status.stat.exists
  149. rescue:
  150. - name: Setting up the kerberos database failed
  151. fail:
  152. msg: "Error: {{ setting_database.stderr }}"
  153. - name: Start krb5kdc and kadmind services
  154. systemd:
  155. name: "{{ item }}"
  156. state: started
  157. enabled: yes
  158. with_items:
  159. - krb5kdc
  160. - kadmind
  161. - block:
  162. - name: Create admin principal
  163. command: kadmin.local -q "ank -pw {{ ms_kerberos_admin_password }} admin"
  164. no_log: true
  165. changed_when: true
  166. register: create_admin_principal
  167. environment:
  168. PATH: "{{ ansible_env.PATH }}:{{ kerberos_env_path }}"
  169. rescue:
  170. - name: Create admin principal failed
  171. fail:
  172. msg: "Error: {{ create_admin_principal.stderr }}"
  173. - block:
  174. - name: Authenticate as admin
  175. shell: set -o pipefail && echo {{ ms_kerberos_admin_password }} | kinit admin
  176. no_log: true
  177. changed_when: false
  178. register: authenticate_admin
  179. rescue:
  180. - name: Authenticate as admin failed
  181. fail:
  182. msg: "Error: {{ authenticate_admin.stderr }}"
  183. - name: Install sssd packages
  184. zypper:
  185. name: "{{ sssd_packages }}"
  186. state: present
  187. - name: Stop and disable nscd
  188. systemd:
  189. name: nscd
  190. state: stopped
  191. enabled: no
  192. when: "'nscd.service' in ansible_facts.services"
  193. - name: Check admin group in 389-ds
  194. command: dsidm {{ ldap_instance }} group list
  195. register: check_admin_group
  196. changed_when: false
  197. - name: Create admin group in 389-ds
  198. shell: set -o pipefail && echo {{ admin_group_name }} | dsidm {{ ldap_instance }} group create
  199. changed_when: true
  200. when: admin_group_name not in check_admin_group.stdout
  201. - name: Create the sssd.conf file
  202. copy:
  203. src: "{{ role_path }}/files/temp_sssd.conf"
  204. dest: "{{ sssd_config_path }}"
  205. mode: "{{ sssd_file_mode }}"
  206. - name: Configure sssd.conf with domain name
  207. replace:
  208. path: "{{ sssd_config_path }}"
  209. regexp: "dc=omnia,dc=test"
  210. replace: "dc={{ domain_name.split('.')[0] }},dc={{ domain_name.split('.')[1] }}"
  211. - name: Start sssd service
  212. systemd:
  213. name: sssd
  214. state: started
  215. enabled: yes
  216. - block:
  217. - name: Configure password policy in 389-ds
  218. command: dsconf -w {{ ms_directory_manager_password }} -D "cn=Directory Manager" ldap://{{ server_hostname_ms }} pwpolicy set --pwdlockoutduration {{ lockout_duration }} --pwdmaxfailures {{ max_failures }} --pwdresetfailcount {{ failure_reset_interval }}
  219. no_log: true
  220. changed_when: true
  221. register: configure_pwpolicy
  222. rescue:
  223. - name: Configure password policy in 389-ds failed
  224. fail:
  225. msg: "Error: {{ configure_pwpolicy.stderr }}"
  226. when: not ds389_status