install_389ds.yml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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: Fetch the short hostname
  23. command: hostname -s
  24. register: short_hostname
  25. changed_when: false
  26. - name: Set fact for server hostname
  27. set_fact:
  28. server_hostname_fqdn: "{{ new_serv_hostname.stdout }}"
  29. server_hostname_short: "{{ short_hostname.stdout }}"
  30. directory_manager_password: "{{ hostvars['127.0.0.1']['directory_manager_password'] }}"
  31. kerberos_admin_password: "{{ hostvars['127.0.0.1']['kerberos_admin_password'] }}"
  32. domain_name: "{{ hostvars['127.0.0.1']['domain_name'] }}"
  33. realm_name: "{{ hostvars['127.0.0.1']['realm_name'] }}"
  34. no_log: true
  35. - name: Check ldap instance is running or not
  36. command: dsctl {{ ldap_instance }} status
  37. changed_when: false
  38. failed_when: false
  39. register: ldap1_status
  40. - name: Check ds389_status admin authentication
  41. shell: set -o pipefail && echo {{ kerberos_admin_password }} | kinit {{ ipa_admin_username }}
  42. changed_when: false
  43. failed_when: false
  44. no_log: true
  45. register: ds389_status_authentication
  46. - name: Modify ds389_status
  47. set_fact:
  48. ds389_status: true
  49. when:
  50. - ds389_status_authentication.rc == 0
  51. - ldap1_install_search_key in ldap1_status.stdout.split(' ')[3]
  52. - block:
  53. - name: Install 389-ds
  54. zypper:
  55. name: "{{ ds389_packages }}"
  56. state: present
  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. - name: Configure ldap1.inf with domain name
  63. lineinfile:
  64. path: "{{ ldap1_config_path }}"
  65. regexp: "^suffix = dc=omnia,dc=test"
  66. line: "suffix = dc={{ domain_name.split('.')[0] }},dc={{ domain_name.split('.')[1] }}"
  67. - name: Configure ldap1.inf with directory manager password
  68. lineinfile:
  69. path: "{{ ldap1_config_path }}"
  70. regexp: "^root_password = password"
  71. line: "root_password = {{ directory_manager_password }}"
  72. no_log: true
  73. - name: Check ldap instance is running or not
  74. command: dsctl {{ ldap_instance }} status
  75. changed_when: false
  76. failed_when: false
  77. register: ldap1_status
  78. - name: Creating 389 directory server instance
  79. shell: dscreate -v from-file {{ ldap1_config_path }} | tee {{ ldap1_output_path }}
  80. changed_when: true
  81. when: ldap1_search_key in ldap1_status.stdout
  82. - name: Remove the ldap1.inf
  83. file:
  84. path: "{{ ldap1_config_path }}"
  85. state: absent
  86. - name: Start dirsrv service
  87. systemd:
  88. name: "dirsrv@{{ ldap_instance }}.service"
  89. state: started
  90. enabled: yes
  91. - name: Create the dsrc file
  92. copy:
  93. src: "{{ role_path }}/files/temp_dsrc"
  94. dest: "{{ dsrc_path }}"
  95. mode: "{{ file_mode }}"
  96. - name: Configure dsrc file with domain name
  97. lineinfile:
  98. path: "{{ dsrc_path }}"
  99. regexp: "^basedn = dc=omnia,dc=test"
  100. line: "basedn = dc={{ domain_name.split('.')[0] }},dc={{ domain_name.split('.')[1] }}"
  101. - name: Start and enable firewalld
  102. service:
  103. name: firewalld
  104. state: started
  105. enabled: yes
  106. - name: Permit traffic in default zone for ldap and ldaps service
  107. firewalld:
  108. service: "{{ item }}"
  109. permanent: yes
  110. state: enabled
  111. with_items: "{{ ldap_services }}"
  112. - name: Reload firewalld
  113. command: firewall-cmd --reload
  114. changed_when: true
  115. - name: Stop and disable firewalld
  116. service:
  117. name: firewalld
  118. state: stopped
  119. enabled: no
  120. - name: Install kerberos packages
  121. zypper:
  122. name: "{{ kerberos_packages }}"
  123. state: present
  124. - name: Check kerberos principal is created or not
  125. stat:
  126. path: "{{ kerberos_principal_path }}"
  127. register: principal_status
  128. - name: Create the kerberos conf file
  129. copy:
  130. src: "{{ role_path }}/files/temp_krb5.conf"
  131. dest: "{{ kerberos_conf_path }}"
  132. mode: "{{ file_mode }}"
  133. - name: Configure kerberos conf file with domain name
  134. replace:
  135. path: "{{ kerberos_conf_path }}"
  136. regexp: "omnia.test"
  137. replace: "{{ domain_name }}"
  138. - name: Configure kerberos conf file with realm name
  139. replace:
  140. path: "{{ kerberos_conf_path }}"
  141. regexp: "OMNIA.TEST"
  142. replace: "{{ realm_name }}"
  143. - name: Configure kerberos conf file with hostname
  144. replace:
  145. path: "{{ kerberos_conf_path }}"
  146. regexp: "hostname"
  147. replace: "{{ server_hostname_short }}"
  148. - block:
  149. - name: Setting up the kerberos database
  150. command: "kdb5_util -r {{ realm_name }} -P {{ directory_manager_password }} create -s"
  151. no_log: true
  152. changed_when: true
  153. register: setting_database
  154. environment:
  155. PATH: "{{ ansible_env.PATH }}:{{ kerberos_env_path }}"
  156. when: not principal_status.stat.exists
  157. rescue:
  158. - name: Setting up the kerberos database failed
  159. fail:
  160. msg: "Error: {{ setting_database.stderr }}"
  161. - name: Start krb5kdc and kadmind services
  162. systemd:
  163. name: "{{ item }}"
  164. state: started
  165. enabled: yes
  166. with_items:
  167. - krb5kdc
  168. - kadmind
  169. - block:
  170. - name: Create admin principal
  171. command: kadmin.local -q "ank -pw {{ kerberos_admin_password }} {{ ipa_admin_username }}"
  172. no_log: true
  173. changed_when: true
  174. register: create_admin_principal
  175. environment:
  176. PATH: "{{ ansible_env.PATH }}:{{ kerberos_env_path }}"
  177. rescue:
  178. - name: Create admin principal failed
  179. fail:
  180. msg: "Error: {{ create_admin_principal.stderr }}"
  181. - name: Authenticate as admin
  182. shell: set -o pipefail && echo {{ kerberos_admin_password }} | kinit {{ ipa_admin_username }}
  183. no_log: true
  184. changed_when: false
  185. when: not ds389_status
  186. - name: Configure password policy in 389-ds
  187. command: dsconf -w {{ directory_manager_password }} -D "cn=Directory Manager" ldap://{{ server_hostname_fqdn }} pwpolicy set --pwdlockoutduration {{ hostvars['127.0.0.1']['lockout_duration'] }} --pwdmaxfailures {{ hostvars['127.0.0.1']['max_failures'] }} --pwdresetfailcount {{ hostvars['127.0.0.1']['failure_reset_interval'] }}
  188. changed_when: true
  189. no_log: true
  190. when: hostvars['127.0.0.1']['enable_secure_login_node']