provision_password.yml 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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: Remove old user
  16. file:
  17. path: "{{ role_path }}/files/.users.digest"
  18. state: absent
  19. tags: install
  20. when: not provision_os_change
  21. - name: Create a new user
  22. file:
  23. path: "{{ role_path }}/files/.users.digest"
  24. state: touch
  25. mode: "{{ user_mode }}"
  26. tags: install
  27. when: not provision_os_change
  28. - name: Cobbler UI password
  29. set_fact:
  30. encrypt_password: "{{ cobbler_password | hash('sha3_256') }}"
  31. no_log: true
  32. tags: install
  33. when: not provision_os_change
  34. - name: Copy cobbler password to cobbler config file
  35. shell: printf "%s:%s:%s\n" "{{ username }}" "Cobbler" "{{ encrypt_password }}" > "{{ role_path }}/files/.users.digest"
  36. changed_when: false
  37. no_log: true
  38. tags: install
  39. when: not provision_os_change
  40. - name: Kickstart configuration - centos
  41. block:
  42. - name: Create the kickstart file
  43. copy:
  44. src: "{{ role_path }}/files/temp_centos7.ks"
  45. dest: "{{ role_path }}/files/{{ cobbler_kickstart_file }}"
  46. mode: 0775
  47. tags: install
  48. - name: Configure kickstart file - IP
  49. replace:
  50. path: "{{ role_path }}/files/{{ cobbler_kickstart_file }}"
  51. regexp: '^url --url http://ip:port/cblr/links/centos-x86_64/'
  52. replace: url --url http://{{ hpc_ip }}:{{ http_port }}/cblr/links/centos-x86_64/
  53. tags: install
  54. - name: Configure kickstart file - nic
  55. lineinfile:
  56. path: "{{ role_path }}/files/{{ cobbler_kickstart_file }}"
  57. insertafter: '^network --bootproto=dhcp --device=link --onboot=on --activate'
  58. line: 'network --bootproto=dhcp --device={{ item }} --onboot=on --activate'
  59. tags: install
  60. with_items: "{{ centos_host_nic }}"
  61. when: provision_os == os_supported_centos
  62. - name: Kickstart configuration - rocky
  63. block:
  64. - name: Create the kickstart file
  65. copy:
  66. src: "{{ role_path }}/files/temp_rocky8.ks"
  67. dest: "{{ role_path }}/files/{{ cobbler_kickstart_file }}"
  68. mode: 0775
  69. tags: install
  70. - name: Configure kickstart file - IP
  71. replace:
  72. path: "{{ role_path }}/files/{{ cobbler_kickstart_file }}"
  73. regexp: '^url --url http://ip:port/cblr/links/rocky-x86_64/'
  74. replace: url --url http://{{ hpc_ip }}:{{ http_port }}/cblr/links/rocky-x86_64/
  75. tags: install
  76. - name: Configure kickstart file - nic
  77. lineinfile:
  78. path: "{{ role_path }}/files/{{ cobbler_kickstart_file }}"
  79. insertafter: '^network --bootproto=dhcp --device=link --onboot=on --activate'
  80. line: 'network --bootproto=dhcp --device={{ item }} --onboot=on --activate'
  81. tags: install
  82. with_items: "{{ rocky_host_nic }}"
  83. when: provision_os == os_supported_rocky
  84. - name: Kickstart configuration - leap
  85. block:
  86. - name: Create the kickstart file
  87. copy:
  88. src: "{{ role_path }}/files/temp_leap15.xml"
  89. dest: "{{ role_path }}/files/{{ cobbler_kickstart_file }}"
  90. mode: 0775
  91. tags: install
  92. - name: Configure kickstart file - IP
  93. replace:
  94. path: "{{ role_path }}/files/{{ cobbler_kickstart_file }}"
  95. regexp: '^ install: http://ip:port/cblr/links/leap-x86_64/'
  96. replace: ' install: http://{{ hpc_ip }}:{{ http_port }}/cblr/links/leap-x86_64/'
  97. tags: install
  98. - name: Configure kickstart file leap - nic
  99. lineinfile:
  100. path: "{{ role_path }}/files/{{ cobbler_kickstart_file }}"
  101. insertafter: ' </interface>'
  102. line: >4
  103. <interface>
  104. <bootproto>dhcp</bootproto>
  105. <name>{{ item }}</name>
  106. <startmode>auto</startmode>
  107. </interface>
  108. tags: install
  109. with_items: "{{ centos_host_nic }}"
  110. - name: Remove blank lines
  111. lineinfile:
  112. path: "{{ role_path }}/files/{{ cobbler_kickstart_file }}"
  113. regexp: '^\s*$'
  114. state: absent
  115. changed_when: false
  116. tags: install
  117. when: provision_os == os_supported_leap
  118. - name: Random phrase generation
  119. command: openssl rand -base64 12
  120. changed_when: false
  121. register: prompt_random_phrase
  122. tags: install
  123. no_log: true
  124. - name: Set random phrase
  125. set_fact:
  126. random_phrase: "{{ prompt_random_phrase.stdout }}"
  127. tags: install
  128. no_log: true
  129. - name: Login password
  130. command: openssl passwd -1 -salt {{ random_phrase }} {{ provision_password }}
  131. no_log: true
  132. changed_when: false
  133. register: login_pass
  134. tags: install
  135. - name: Assign password
  136. replace:
  137. path: "{{ role_path }}/files/settings.yaml"
  138. regexp: '^default_password_crypted: password'
  139. replace: 'default_password_crypted: {{ login_pass.stdout }}'
  140. no_log: true
  141. tags: install
  142. - name: Configure kickstart file for {{ provision_os }}
  143. block:
  144. - name: Configure kickstart file - Password
  145. replace:
  146. path: "{{ role_path }}/files/{{ cobbler_kickstart_file }}"
  147. regexp: '^rootpw --iscrypted ks_password'
  148. replace: 'rootpw --iscrypted {{ login_pass.stdout }}'
  149. no_log: true
  150. tags: install
  151. - name: Configure kickstart file - timezone
  152. replace:
  153. path: "{{ role_path }}/files/{{ cobbler_kickstart_file }}"
  154. regexp: '^timezone --utc ks_timezone'
  155. replace: 'timezone --utc {{ timezone }}'
  156. tags: install
  157. - name: Configure kickstart file - language
  158. replace:
  159. path: "{{ role_path }}/files/{{ cobbler_kickstart_file }}"
  160. regexp: '^lang ks_language'
  161. replace: 'lang {{ language }}'
  162. tags: install
  163. when:
  164. - provision_os != os_supported_leap
  165. - name: Configure kickstart file for {{ provision_os }}
  166. block:
  167. - name: Configure kickstart file - Password
  168. replace:
  169. path: "{{ role_path }}/files/{{ cobbler_kickstart_file }}"
  170. regexp: '^ <user_password>ks_password</user_password>'
  171. replace: ' <user_password>{{ login_pass.stdout }}</user_password>'
  172. no_log: true
  173. tags: install
  174. - name: Configure kickstart file - timezone
  175. replace:
  176. path: "{{ role_path }}/files/{{ cobbler_kickstart_file }}"
  177. regexp: '^ <timezone>ks_timezone</timezone>'
  178. replace: ' <timezone>{{ timezone }}</timezone>'
  179. tags: install
  180. when: provision_os == os_supported_leap
  181. - name: Remove ^M characters
  182. command: dos2unix {{ role_path }}/files/{{ cobbler_kickstart_file }}
  183. changed_when: false
  184. failed_when: false