install_389ds.yml 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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: Gathering service facts
  47. service_facts:
  48. - name: Modify ds389_status
  49. set_fact:
  50. ds389_status: true
  51. when:
  52. - ds389_status_authentication.rc == 0
  53. - ldap1_install_search_key in ldap1_status.stdout.split(' ')[3]
  54. - "'sssd.service' in ansible_facts.services"
  55. - sssd_install_search_key in ansible_facts.services['sssd.service'].state
  56. - block:
  57. - name: Install 389-ds
  58. zypper:
  59. name: "{{ ds389_packages }}"
  60. state: present
  61. - name: Check ldap instance is running or not
  62. command: dsctl {{ ldap_instance }} status
  63. changed_when: false
  64. failed_when: false
  65. register: ldap1_status
  66. - name: Create the ldap1.inf file
  67. copy:
  68. src: "{{ role_path }}/files/temp_ldap1.inf"
  69. dest: "{{ ldap1_config_path }}"
  70. mode: "{{ file_mode }}"
  71. when: ldap1_search_key in ldap1_status.stdout
  72. - name: Configure ldap1.inf with domain name
  73. lineinfile:
  74. path: "{{ ldap1_config_path }}"
  75. regexp: "^suffix = dc=omnia,dc=test"
  76. line: "suffix = dc={{ domain_name.split('.')[0] }},dc={{ domain_name.split('.')[1] }}"
  77. when: ldap1_search_key in ldap1_status.stdout
  78. - name: Configure ldap1.inf with directory manager password
  79. lineinfile:
  80. path: "{{ ldap1_config_path }}"
  81. regexp: "^root_password = password"
  82. line: "root_password = {{ directory_manager_password }}"
  83. no_log: true
  84. when: ldap1_search_key in ldap1_status.stdout
  85. - name: Creating 389 directory server instance
  86. shell: dscreate -v from-file {{ ldap1_config_path }} | tee {{ ldap1_output_path }}
  87. changed_when: true
  88. when: ldap1_search_key in ldap1_status.stdout
  89. - name: Remove the ldap1.inf
  90. file:
  91. path: "{{ ldap1_config_path }}"
  92. state: absent
  93. - name: Start dirsrv service
  94. systemd:
  95. name: "dirsrv@{{ ldap_instance }}.service"
  96. state: started
  97. enabled: yes
  98. - name: Create the dsrc file
  99. copy:
  100. src: "{{ role_path }}/files/temp_dsrc"
  101. dest: "{{ dsrc_path }}"
  102. mode: "{{ file_mode }}"
  103. - name: Configure dsrc file with domain name
  104. lineinfile:
  105. path: "{{ dsrc_path }}"
  106. regexp: "^basedn = dc=omnia,dc=test"
  107. line: "basedn = dc={{ domain_name.split('.')[0] }},dc={{ domain_name.split('.')[1] }}"
  108. - name: Start and enable firewalld
  109. service:
  110. name: firewalld
  111. state: started
  112. enabled: yes
  113. - name: Permit traffic in default zone for ldap and ldaps service
  114. firewalld:
  115. service: "{{ item }}"
  116. permanent: yes
  117. state: enabled
  118. with_items: "{{ ldap_services }}"
  119. - name: Reload firewalld
  120. command: firewall-cmd --reload
  121. changed_when: true
  122. - name: Stop and disable firewalld
  123. service:
  124. name: firewalld
  125. state: stopped
  126. enabled: no
  127. - name: Install kerberos packages
  128. zypper:
  129. name: "{{ kerberos_packages }}"
  130. state: present
  131. - name: Check kerberos principal is created or not
  132. stat:
  133. path: "{{ kerberos_principal_path }}"
  134. register: principal_status
  135. - name: Create the kerberos conf file
  136. copy:
  137. src: "{{ role_path }}/files/temp_krb5.conf"
  138. dest: "{{ kerberos_conf_path }}"
  139. mode: "{{ file_mode }}"
  140. when: not principal_status.stat.exists
  141. - name: Configure kerberos conf file with domain name
  142. replace:
  143. path: "{{ kerberos_conf_path }}"
  144. regexp: "omnia.test"
  145. replace: "{{ domain_name }}"
  146. when: not principal_status.stat.exists
  147. - name: Configure kerberos conf file with realm name
  148. replace:
  149. path: "{{ kerberos_conf_path }}"
  150. regexp: "OMNIA.TEST"
  151. replace: "{{ realm_name }}"
  152. when: not principal_status.stat.exists
  153. - name: Configure kerberos conf file with hostname
  154. replace:
  155. path: "{{ kerberos_conf_path }}"
  156. regexp: "hostname"
  157. replace: "{{ server_hostname_short }}"
  158. when: not principal_status.stat.exists
  159. - block:
  160. - name: Setting up the kerberos database
  161. command: "kdb5_util -r {{ realm_name }} -P {{ directory_manager_password }} create -s"
  162. no_log: true
  163. changed_when: true
  164. register: setting_database
  165. environment:
  166. PATH: "{{ ansible_env.PATH }}:{{ kerberos_env_path }}"
  167. when: not principal_status.stat.exists
  168. rescue:
  169. - name: Setting up the kerberos database failed
  170. fail:
  171. msg: "Error: {{ setting_database.stderr }}"
  172. - name: Start krb5kdc and kadmind services
  173. systemd:
  174. name: "{{ item }}"
  175. state: started
  176. enabled: yes
  177. with_items:
  178. - krb5kdc
  179. - kadmind
  180. - block:
  181. - name: Create admin principal
  182. command: kadmin.local -q "ank -pw {{ kerberos_admin_password }} {{ ipa_admin_username }}"
  183. no_log: true
  184. changed_when: true
  185. register: create_admin_principal
  186. environment:
  187. PATH: "{{ ansible_env.PATH }}:{{ kerberos_env_path }}"
  188. rescue:
  189. - name: Create admin principal failed
  190. fail:
  191. msg: "Error: {{ create_admin_principal.stderr }}"
  192. - block:
  193. - name: Authenticate as admin
  194. shell: set -o pipefail && echo {{ kerberos_admin_password }} | kinit {{ ipa_admin_username }}
  195. no_log: true
  196. changed_when: false
  197. register: authenticate_admin
  198. rescue:
  199. - name: Authenticate as admin failed
  200. fail:
  201. msg: "Error: {{ authenticate_admin.stderr }}"
  202. - name: Install sssd packages
  203. zypper:
  204. name: "{{ sssd_packages }}"
  205. state: present
  206. - name: Stop and disable nscd
  207. systemd:
  208. name: nscd
  209. state: stopped
  210. enabled: no
  211. when: "'nscd.service' in ansible_facts.services"
  212. - name: Check admin group in 389-ds
  213. command: dsidm {{ ldap_instance }} group list
  214. register: check_admin_group
  215. changed_when: false
  216. - name: Create admin group in 389-ds
  217. shell: set -o pipefail && echo {{ admin_group_name }} | dsidm {{ ldap_instance }} group create
  218. changed_when: true
  219. when: admin_group_name not in check_admin_group.stdout
  220. - name: Create the sssd.conf file
  221. copy:
  222. src: "{{ role_path }}/files/temp_sssd.conf"
  223. dest: "{{ sssd_config_path }}"
  224. mode: "{{ sssd_file_mode }}"
  225. - name: Configure sssd.conf with domain name
  226. replace:
  227. path: "{{ sssd_config_path }}"
  228. regexp: "dc=omnia,dc=test"
  229. replace: "dc={{ domain_name.split('.')[0] }},dc={{ domain_name.split('.')[1] }}"
  230. - name: Start sssd service
  231. systemd:
  232. name: sssd
  233. state: started
  234. enabled: yes
  235. when: not ds389_status
  236. - block:
  237. - name: Configure password policy in 389-ds
  238. 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'] }}
  239. changed_when: true
  240. no_log: true
  241. when: hostvars['127.0.0.1']['enable_secure_login_node']
  242. register: configure_pwpolicy
  243. rescue:
  244. - name: Configure password policy in 389-ds failed
  245. fail:
  246. msg: "Error: {{ configure_pwpolicy.stderr }}"