edit_iso_config.yml 7.1 KB

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