provision_password.yml 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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/cblr/links/centos-x86_64/'
  52. replace: url --url http://{{ hpc_ip }}/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/cblr/links/rocky-x86_64/'
  74. replace: url --url http://{{ hpc_ip }}/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/cblr/links/leap-x86_64/'
  96. replace: ' install: http://{{ hpc_ip }}/cblr/links/leap-x86_64/'
  97. tags: install
  98. when: provision_os == os_supported_leap
  99. - name: Random phrase generation
  100. command: openssl rand -base64 12
  101. changed_when: false
  102. register: prompt_random_phrase
  103. tags: install
  104. no_log: true
  105. - name: Set random phrase
  106. set_fact:
  107. random_phrase: "{{ prompt_random_phrase.stdout }}"
  108. tags: install
  109. no_log: true
  110. - name: Login password
  111. command: openssl passwd -1 -salt {{ random_phrase }} {{ provision_password }}
  112. no_log: true
  113. changed_when: false
  114. register: login_pass
  115. tags: install
  116. - name: Assign password
  117. replace:
  118. path: "{{ role_path }}/files/settings.yaml"
  119. regexp: '^default_password_crypted: password'
  120. replace: 'default_password_crypted: {{ login_pass.stdout }}'
  121. no_log: true
  122. tags: install
  123. - name: Configure kickstart file for {{ provision_os }}
  124. block:
  125. - name: Configure kickstart file - Password
  126. replace:
  127. path: "{{ role_path }}/files/{{ cobbler_kickstart_file }}"
  128. regexp: '^rootpw --iscrypted ks_password'
  129. replace: 'rootpw --iscrypted {{ login_pass.stdout }}'
  130. no_log: true
  131. tags: install
  132. - name: Configure kickstart file - timezone
  133. replace:
  134. path: "{{ role_path }}/files/{{ cobbler_kickstart_file }}"
  135. regexp: '^timezone --utc ks_timezone'
  136. replace: 'timezone --utc {{ timezone }}'
  137. tags: install
  138. - name: Configure kickstart file - language
  139. replace:
  140. path: "{{ role_path }}/files/{{ cobbler_kickstart_file }}"
  141. regexp: '^lang ks_language'
  142. replace: 'lang {{ language }}'
  143. tags: install
  144. when:
  145. - provision_os != os_supported_leap
  146. - name: Configure kickstart file for {{ provision_os }}
  147. block:
  148. - name: Configure kickstart file - Password
  149. replace:
  150. path: "{{ role_path }}/files/{{ cobbler_kickstart_file }}"
  151. regexp: '^ <user_password>ks_password</user_password>'
  152. replace: ' <user_password>{{ login_pass.stdout }}</user_password>'
  153. no_log: true
  154. tags: install
  155. - name: Configure kickstart file - timezone
  156. replace:
  157. path: "{{ role_path }}/files/{{ cobbler_kickstart_file }}"
  158. regexp: '^ <timezone>ks_timezone</timezone>'
  159. replace: ' <timezone>{{ timezone }}</timezone>'
  160. tags: install
  161. when: provision_os == os_supported_leap
  162. - name: Remove ^M characters
  163. command: dos2unix {{ role_path }}/files/{{ cobbler_kickstart_file }}
  164. changed_when: false
  165. failed_when: false