install_389ds.yml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. - name: Check ldap instance is running or not
  35. command: dsctl {{ ldap_instance }} status
  36. changed_when: false
  37. failed_when: false
  38. register: ldap1_status
  39. - name: Check ds389_status admin authentication
  40. shell: set -o pipefail && echo {{ kerberos_admin_password }} | kinit {{ ipa_admin_username }}
  41. changed_when: false
  42. failed_when: false
  43. no_log: true
  44. register: ds389_status_authentication
  45. - name: Modify ds389_status
  46. set_fact:
  47. ds389_status: true
  48. when:
  49. - ds389_status_authentication.rc == 0
  50. - ldap1_install_search_key in ldap1_status.stdout.split(' ')[3]
  51. - block:
  52. - name: Install 389-ds
  53. zypper:
  54. name: "{{ ds389_packages }}"
  55. state: present
  56. - name: Create the ldap1.inf file
  57. copy:
  58. src: "{{ role_path }}/files/temp_ldap1.inf"
  59. dest: "{{ ldap1_config_path }}"
  60. mode: "{{ file_mode }}"
  61. - name: Configure ldap1.inf with domain name
  62. lineinfile:
  63. path: "{{ ldap1_config_path }}"
  64. regexp: "^suffix = dc=omnia,dc=test"
  65. line: "suffix = dc={{ domain_name.split('.')[0] }},dc={{ domain_name.split('.')[1] }}"
  66. - name: Configure ldap1.inf with directory manager password
  67. lineinfile:
  68. path: "{{ ldap1_config_path }}"
  69. regexp: "^root_password = password"
  70. line: "root_password = {{ directory_manager_password }}"
  71. - name: Check ldap instance is running or not
  72. command: dsctl {{ ldap_instance }} status
  73. changed_when: false
  74. failed_when: false
  75. register: ldap1_status
  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: Start and enable firewalld
  100. service:
  101. name: firewalld
  102. state: started
  103. enabled: yes
  104. - name: Permit traffic in default zone for ldap and ldaps service
  105. firewalld:
  106. service: "{{ item }}"
  107. permanent: yes
  108. state: enabled
  109. with_items: "{{ ldap_services }}"
  110. - name: Reload firewalld
  111. command: firewall-cmd --reload
  112. changed_when: true
  113. - name: Stop and disable firewalld
  114. service:
  115. name: firewalld
  116. state: stopped
  117. enabled: no
  118. - name: Install kerberos packages
  119. zypper:
  120. name: "{{ kerberos_packages }}"
  121. state: present
  122. - name: Check kerberos principal is created or not
  123. stat:
  124. path: "{{ kerberos_principal_path }}"
  125. register: principal_status
  126. - name: Create the kerberos conf file
  127. copy:
  128. src: "{{ role_path }}/files/temp_krb5.conf"
  129. dest: "{{ kerberos_conf_path }}"
  130. mode: "{{ file_mode }}"
  131. - name: Configure kerberos conf file with domain name
  132. replace:
  133. path: "{{ kerberos_conf_path }}"
  134. regexp: "omnia.test"
  135. replace: "{{ domain_name }}"
  136. - name: Configure kerberos conf file with realm name
  137. replace:
  138. path: "{{ kerberos_conf_path }}"
  139. regexp: "OMNIA.TEST"
  140. replace: "{{ realm_name }}"
  141. - name: Configure kerberos conf file with hostname
  142. replace:
  143. path: "{{ kerberos_conf_path }}"
  144. regexp: "hostname"
  145. replace: "{{ server_hostname_short }}"
  146. - block:
  147. - name: Setting up the kerberos database
  148. command: "kdb5_util -r {{ realm_name }} -P {{ directory_manager_password }} create -s"
  149. no_log: true
  150. changed_when: true
  151. register: setting_database
  152. environment:
  153. PATH: "{{ ansible_env.PATH }}:{{ kerberos_env_path }}"
  154. when: not principal_status.stat.exists
  155. rescue:
  156. - name: Setting up the kerberos database failed
  157. fail:
  158. msg: "Error: {{ setting_database.stderr }}"
  159. - name: Start krb5kdc and kadmind services
  160. systemd:
  161. name: "{{ item }}"
  162. state: started
  163. enabled: yes
  164. with_items:
  165. - krb5kdc
  166. - kadmind
  167. - block:
  168. - name: Create admin principal
  169. command: kadmin.local -q "ank -pw {{ kerberos_admin_password }} {{ ipa_admin_username }}"
  170. no_log: true
  171. changed_when: true
  172. register: create_admin_principal
  173. environment:
  174. PATH: "{{ ansible_env.PATH }}:{{ kerberos_env_path }}"
  175. rescue:
  176. - name: Create admin principal failed
  177. fail:
  178. msg: "Error: {{ create_admin_principal.stderr }}"
  179. - name: Authenticate as admin
  180. shell: set -o pipefail && echo {{ kerberos_admin_password }} | kinit {{ ipa_admin_username }}
  181. no_log: true
  182. changed_when: false
  183. when: not ds389_status
  184. - name: Configure password policy in 389-ds
  185. 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'] }}
  186. changed_when: true
  187. when: hostvars['127.0.0.1']['enable_secure_login_node']