edit_iso_config.yml 4.8 KB

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