install_389ds.yml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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: Modify ds389_status
  38. set_fact:
  39. ds389_status: true
  40. when:
  41. - ds389_status_authentication.rc == 0
  42. - ds389_pwpolicy_search_key in ds389_pwpolicy_check.stdout
  43. - block:
  44. - name: Install 389-ds
  45. zypper:
  46. name: "{{ ds389_packages }}"
  47. state: present
  48. - name: Create the ldap1.inf file
  49. copy:
  50. src: "{{ role_path }}/files/temp_ldap1.inf"
  51. dest: "{{ ldap1_config_path }}"
  52. mode: "{{ file_mode }}"
  53. - name: Configure ldap1.inf with domain name
  54. lineinfile:
  55. path: "{{ ldap1_config_path }}"
  56. regexp: "^suffix = dc=omnia,dc=test"
  57. line: "suffix = dc={{ domain_name.split('.')[0] }},dc={{ domain_name.split('.')[1] }}"
  58. - name: Configure ldap1.inf with directory manager password
  59. lineinfile:
  60. path: "{{ ldap1_config_path }}"
  61. regexp: "^root_password = password"
  62. line: "root_password = {{ ms_directory_manager_password }}"
  63. - name: Check ldap instance is running or not
  64. command: dsctl {{ ldap_instance }} status
  65. changed_when: false
  66. failed_when: false
  67. register: ldap1_status
  68. - name: Creating 389 directory server instance
  69. shell: dscreate -v from-file {{ ldap1_config_path }} | tee {{ ldap1_output_path }}
  70. changed_when: true
  71. when: ldap1_search_key in ldap1_status.stdout
  72. - name: Remove the ldap1.inf
  73. file:
  74. path: "{{ ldap1_config_path }}"
  75. state: absent
  76. - name: Start dirsrv service
  77. systemd:
  78. name: "dirsrv@{{ ldap_instance }}.service"
  79. state: started
  80. enabled: yes
  81. - name: Create the dsrc file
  82. copy:
  83. src: "{{ role_path }}/files/temp_dsrc"
  84. dest: "{{ dsrc_path }}"
  85. mode: "{{ file_mode }}"
  86. - name: Configure dsrc file with domain name
  87. lineinfile:
  88. path: "{{ dsrc_path }}"
  89. regexp: "^basedn = dc=omnia,dc=test"
  90. line: "basedn = dc={{ domain_name.split('.')[0] }},dc={{ domain_name.split('.')[1] }}"
  91. - name: Permit traffic in default zone for ldap and ldaps service
  92. firewalld:
  93. service: "{{ item }}"
  94. permanent: yes
  95. state: enabled
  96. with_items: "{{ ldap_services }}"
  97. - name: Reload firewalld service
  98. systemd:
  99. name: firewalld
  100. state: reloaded
  101. - name: Install kerberos packages
  102. zypper:
  103. name: "{{ kerberos_packages }}"
  104. state: present
  105. - name: Check kerberos principal is created or not
  106. stat:
  107. path: "{{ kerberos_principal_path }}"
  108. register: principal_status
  109. - name: Create the kerberos conf file
  110. copy:
  111. src: "{{ role_path }}/files/temp_krb5.conf"
  112. dest: "{{ kerberos_conf_path }}"
  113. mode: "{{ file_mode }}"
  114. - name: Configure kerberos conf file with domain name
  115. replace:
  116. path: "{{ kerberos_conf_path }}"
  117. regexp: "omnia.test"
  118. replace: "{{ domain_name }}"
  119. - name: Configure kerberos conf file with realm name
  120. replace:
  121. path: "{{ kerberos_conf_path }}"
  122. regexp: "OMNIA.TEST"
  123. replace: "{{ realm_name }}"
  124. - name: Configure kerberos conf file with hostname
  125. replace:
  126. path: "{{ kerberos_conf_path }}"
  127. regexp: "hostname"
  128. replace: "{{ short_hostname.stdout }}"
  129. - block:
  130. - name: Setting up the kerberos database
  131. command: "kdb5_util -r {{ realm_name }} -P {{ ms_directory_manager_password }} create -s"
  132. no_log: true
  133. changed_when: true
  134. register: setting_database
  135. environment:
  136. PATH: "{{ ansible_env.PATH }}:{{ kerberos_env_path }}"
  137. when: not principal_status.stat.exists
  138. rescue:
  139. - name: Setting up the kerberos database failed
  140. fail:
  141. msg: "Error: {{ setting_database.stderr }}"
  142. - name: Start krb5kdc and kadmind services
  143. systemd:
  144. name: "{{ item }}"
  145. state: started
  146. enabled: yes
  147. with_items:
  148. - krb5kdc
  149. - kadmind
  150. - block:
  151. - name: Create admin principal
  152. command: kadmin.local -q "ank -pw {{ ms_kerberos_admin_password }} admin"
  153. no_log: true
  154. changed_when: true
  155. register: create_admin_principal
  156. environment:
  157. PATH: "{{ ansible_env.PATH }}:{{ kerberos_env_path }}"
  158. rescue:
  159. - name: Create admin principal failed
  160. fail:
  161. msg: "Error: {{ create_admin_principal.stderr }}"
  162. - name: Authenticate as admin
  163. shell: set -o pipefail && echo {{ ms_kerberos_admin_password }} | kinit admin
  164. no_log: true
  165. changed_when: false
  166. - name: Configure password policy in 389-ds
  167. 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 }}
  168. changed_when: true
  169. when: not ds389_status