edit_iso_config.yml 7.2 KB

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