edit_iso_config.yml 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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: Include control_plane_common vars
  16. include_vars: ../../control_plane_common/vars/main.yml
  17. tags: install
  18. - name: Include provision_cobbler vars
  19. include_vars: ../../provision_cobbler/vars/main.yml
  20. tags: install
  21. - name: Random phrase generation
  22. command: openssl rand -base64 12
  23. changed_when: false
  24. register: generate_random_phrase
  25. tags: install
  26. no_log: true
  27. - name: Encrypt login password
  28. command: openssl passwd -1 -salt {{ generate_random_phrase.stdout }} {{ provision_password }}
  29. no_log: true
  30. changed_when: false
  31. register: encrypt_login_pass
  32. tags: install
  33. - name: Create a tmp iso directory
  34. file:
  35. path: "{{ tmp_iso_dir }}"
  36. state: directory
  37. mode: "{{ file_permission }}"
  38. tags: install
  39. - name: Copy files to tmp folder
  40. command: rsync -AHPSXav {{ iso_mount_path }} {{ tmp_iso_dir }}
  41. changed_when: true
  42. tags: install
  43. - block:
  44. - block:
  45. - name: Set centos kickstart file name
  46. set_fact:
  47. idrac_kickstart_file: "{{ idrac_centos_ks }}"
  48. tags: install
  49. - name: Remove the kickstart file if exists
  50. file:
  51. path: "{{ role_path }}/files/{{ idrac_kickstart_file }}"
  52. state: absent
  53. tags: install
  54. - name: Create the centos kickstart file
  55. copy:
  56. src: "{{ role_path }}/files/temp_centos7.cfg"
  57. dest: "{{ role_path }}/files/{{ idrac_kickstart_file }}"
  58. mode: "{{ file_permission }}"
  59. tags: install
  60. - name: Configure kickstart file centos - nic
  61. lineinfile:
  62. path: "{{ role_path }}/files/{{ idrac_kickstart_file }}"
  63. insertafter: '^network --bootproto=dhcp --device=link --onboot=on --activate'
  64. line: 'network --bootproto=dhcp --device={{ item }} --onboot=on --activate'
  65. tags: install
  66. with_items: "{{ centos_host_nic }}"
  67. when: provision_os == os_supported_centos
  68. - block:
  69. - name: Set rocky kickstart file name
  70. set_fact:
  71. idrac_kickstart_file: "{{ idrac_rocky_ks }}"
  72. tags: install
  73. - name: Remove the kickstart file if exists
  74. file:
  75. path: "{{ role_path }}/files/{{ idrac_kickstart_file }}"
  76. state: absent
  77. tags: install
  78. - name: Create the rocky kickstart file
  79. copy:
  80. src: "{{ role_path }}/files/temp_rocky8.cfg"
  81. dest: "{{ role_path }}/files/{{ idrac_kickstart_file }}"
  82. mode: "{{ file_permission }}"
  83. tags: install
  84. - name: Configure kickstart file rocky - nic
  85. lineinfile:
  86. path: "{{ role_path }}/files/{{ idrac_kickstart_file }}"
  87. insertafter: '^network --bootproto=dhcp --device=link --onboot=on --activate'
  88. line: 'network --bootproto=dhcp --device={{ item }} --onboot=on --activate'
  89. tags: install
  90. with_items: "{{ rocky_host_nic }}"
  91. when: provision_os == os_supported_rocky
  92. - name: Configure kickstart file - Password
  93. replace:
  94. path: "{{ role_path }}/files/{{ idrac_kickstart_file }}"
  95. regexp: '^rootpw --iscrypted ks_password'
  96. replace: 'rootpw --iscrypted {{ encrypt_login_pass.stdout }}'
  97. no_log: true
  98. tags: install
  99. - name: Configure kickstart file - timezone
  100. replace:
  101. path: "{{ role_path }}/files/{{ idrac_kickstart_file }}"
  102. regexp: '^timezone --utc ks_timezone'
  103. replace: 'timezone --utc {{ timezone }}'
  104. tags: install
  105. - name: Configure kickstart file - language
  106. replace:
  107. path: "{{ role_path }}/files/{{ idrac_kickstart_file }}"
  108. regexp: '^lang ks_language'
  109. replace: 'lang {{ language }}'
  110. tags: install
  111. - name: Copy kickstart file to iso mount path
  112. copy:
  113. src: "{{ role_path }}/files/{{ idrac_kickstart_file }}"
  114. dest: "{{ tmp_iso_dir }}{{ idrac_kickstart_file }}"
  115. mode: preserve
  116. tags: install
  117. - name: Remove ^M characters
  118. command: dos2unix {{ tmp_iso_dir }}{{ idrac_kickstart_file }}
  119. changed_when: false
  120. failed_when: false
  121. - name: Edit isolinux.cfg
  122. replace:
  123. path: "{{ tmp_iso_dir }}{{ isolinux_cfg_path }}"
  124. regexp: "{{ item.regexp }}"
  125. replace: "{{ item.replace }}"
  126. with_items:
  127. - { regexp: "append initrd=initrd.img", replace: "append initrd=initrd.img ks=cdrom:/{{ idrac_kickstart_file }}" }
  128. - { regexp: "rd.live.check quiet", replace: "" }
  129. tags: install
  130. - name: Edit grub.cfg
  131. replace:
  132. path: "{{ tmp_iso_dir }}{{ grub_cfg_path }}"
  133. regexp: "{{ item.regexp }}"
  134. replace: "{{ item.replace }}"
  135. with_items:
  136. - { regexp: "timeout=60", replace: "timeout=5" }
  137. - { regexp: "kernel /images/pxeboot/vmlinuz", replace: "kernel /images/pxeboot/vmlinuz ks=cdrom:/{{ idrac_kickstart_file }}" }
  138. - { regexp: "linuxefi /images/pxeboot/vmlinuz", replace: "linuxefi /images/pxeboot/vmlinuz ks=cdrom:/{{ idrac_kickstart_file }}" }
  139. - { regexp: "rd.live.check quiet", replace: "" }
  140. tags: install
  141. when:
  142. - provision_os == os_supported_rocky or
  143. provision_os == os_supported_centos
  144. - block:
  145. - name: Set leap kickstart file name
  146. set_fact:
  147. idrac_kickstart_file: "{{ idrac_leap_ks }}"
  148. tags: install
  149. - name: Create the leap kickstart file
  150. copy:
  151. src: "{{ role_path }}/files/temp_leap15.xml"
  152. dest: "{{ role_path }}/files/{{ idrac_kickstart_file }}"
  153. mode: "{{ file_permission }}"
  154. tags: install
  155. - name: Configure kickstart file - Password
  156. replace:
  157. path: "{{ role_path }}/files/{{ idrac_kickstart_file }}"
  158. regexp: ' <user_password>ks_password</user_password>'
  159. replace: ' <user_password>{{ encrypt_login_pass.stdout }}</user_password>'
  160. no_log: true
  161. tags: install
  162. - name: Configure kickstart file - timezone
  163. replace:
  164. path: "{{ role_path }}/files/{{ idrac_kickstart_file }}"
  165. regexp: ' <timezone>ks_timezone</timezone>'
  166. replace: ' <timezone>{{ timezone }}</timezone>'
  167. tags: install
  168. - name: Copy kickstart file to iso mount path
  169. copy:
  170. src: "{{ role_path }}/files/{{ idrac_kickstart_file }}"
  171. dest: "/tmp/leap/{{ idrac_kickstart_file }}"
  172. mode: preserve
  173. tags: install
  174. - name: Edit grub.cfg
  175. replace:
  176. path: "{{ tmp_iso_dir }}{{ grub_cfg_path }}"
  177. regexp: "{{ item.regexp }}"
  178. replace: "{{ item.replace }}"
  179. with_items:
  180. - { regexp: " timeout=60", replace: " timeout=5" }
  181. tags: install
  182. when: provision_os == os_supported_leap