provision_password.yml 6.0 KB

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