edit_iso_config.yml 7.3 KB

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