52-coreos-installer.yml 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. ---
  2. # Perform the tasks involved with installing SNO using coreos-installer.
  3. - name: Prepare the files required for a SNO installation using coreos-installer.
  4. hosts: workstation.lab.example.com
  5. become: no
  6. gather_subset: min
  7. tasks:
  8. - name: Check the dependency status.
  9. ansible.builtin.stat:
  10. path: "{{ ansible_facts['user_dir'] }}/{{ item }}"
  11. get_attributes: no
  12. get_checksum: no
  13. get_mime: no
  14. register: dependencies
  15. loop:
  16. - install-pull-secret
  17. - .ssh/openshift.pub
  18. - ca/ca-cert.pem
  19. - mirror/working-dir/cluster-resources/idms-oc-mirror.yaml
  20. - Downloads/rhcos-418.94.202501221327-0-live.x86_64.iso
  21. - ansible.builtin.assert:
  22. that:
  23. - dependencies.results[0].stat.exists
  24. - dependencies.results[1].stat.exists
  25. - dependencies.results[2].stat.exists
  26. - dependencies.results[3].stat.exists
  27. - dependencies.results[4].stat.exists
  28. fail_msg: |
  29. ERROR: Either pull secret, SSH keypair, CA certificate, RHCOS ISO, or mirror artifacts are missing.
  30. Ensure all the relevant preceding tasks have been completed:
  31. - Quay prerequisites,
  32. - Quay deployment,
  33. - oc-mirror prerequisites,
  34. - oc-mirror execution,
  35. - coreos-installer prerequisites
  36. Exiting.
  37. success_msg: "OK, dependencies exist."
  38. - name: Check whether someone fiddled with installation before.
  39. ansible.builtin.stat:
  40. path: "{{ ansible_facts['user_dir'] }}/embed/.openshift_install.log"
  41. register: install_log
  42. - name: Warn if installation log was found.
  43. ansible.builtin.pause:
  44. prompt: |
  45. WARNING: Found .openshift_install.log in the cluster working directory. This usually
  46. means there were previous attempts of creating installation artifacts.
  47. If you want to recreate the cluster working directory from scratch, run this
  48. playbook with the variable "recreate_cluster_dir" set to any value like this:
  49. ansible-playbook -e recreate_cluster_dir=yes ./52-coreos-installer.yml
  50. Continuing in 5 seconds unless you interrupt execution.
  51. seconds: 5
  52. when:
  53. - install_log.stat.exists
  54. - recreate_cluster_dir is not defined
  55. - name: Load the dependencies as facts.
  56. ansible.builtin.set_fact:
  57. pull_secret: "{{ lookup('ansible.builtin.file', ansible_facts['user_dir'] + '/install-pull-secret') }}"
  58. public_key: "{{ lookup('ansible.builtin.file', ansible_facts['user_dir'] + '/.ssh/openshift.pub') }}"
  59. lab_ca_cert: "{{ lookup('ansible.builtin.file', ansible_facts['user_dir'] + '/ca/ca-cert.pem') }}"
  60. content_sources: "{{ lookup('ansible.builtin.file', ansible_facts['user_dir'] + '/mirror/working-dir/cluster-resources/idms-oc-mirror.yaml')
  61. | ansible.builtin.from_yaml_all }}"
  62. - name: Ensure install-config is there.
  63. ansible.builtin.template:
  64. src: templates/install-config-embed.yaml.j2
  65. dest: "{{ ansible_facts['user_dir'] }}/install-config-embed.yaml"
  66. mode: 0644
  67. owner: student
  68. group: student
  69. - name: Remove the installation directory if so required.
  70. ansible.builtin.file:
  71. path: "{{ ansible_facts['user_dir'] }}/embed"
  72. state: absent
  73. when:
  74. - recreate_cluster_dir is defined
  75. - recreate_cluster_dir
  76. - name: Ensure the presence of installation directory.
  77. ansible.builtin.file:
  78. path: "{{ ansible_facts['user_dir'] }}/embed"
  79. state: directory
  80. mode: 0755
  81. - name: Also, ensure that the right install-config.yaml file is in there.
  82. ansible.builtin.copy:
  83. src: "{{ ansible_facts['user_dir'] }}/install-config-embed.yaml"
  84. remote_src: yes
  85. dest: "{{ ansible_facts['user_dir'] }}/embed/install-config.yaml"
  86. mode: 0644
  87. register: published_install_config
  88. when:
  89. - (not install_log.stat.exists) or (recreate_cluster_dir is defined)
  90. - name: Create installation manifests if install config was published.
  91. ansible.builtin.command:
  92. cmd: openshift-install-fips create manifests
  93. chdir: "{{ ansible_facts['user_dir'] }}/embed"
  94. when: published_install_config.changed
  95. - name: Render chrony customizations in home directory.
  96. ansible.builtin.template:
  97. src: templates/chrony-customization.bu.j2
  98. dest: "{{ ansible_facts['user_dir'] }}/chrony-{{ item }}.bu"
  99. mode: 0644
  100. owner: student
  101. group: student
  102. loop:
  103. - master
  104. - worker
  105. - name: Publish chrony customizations in manifests directory.
  106. ansible.builtin.command:
  107. cmd: butane ./chrony-{{ item }}.bu -o ./embed/openshift/99_chrony_{{ item }}.yaml
  108. chdir: "{{ ansible_facts['user_dir'] }}"
  109. creates: embed/openshift/99_chrony_{{ item }}.yaml
  110. loop:
  111. - master
  112. - worker
  113. when: published_install_config.changed
  114. - name: Everything should be set by now, so create SNO install config.
  115. ansible.builtin.command:
  116. cmd: openshift-install-fips create single-node-ignition-config
  117. chdir: "{{ ansible_facts['user_dir'] }}/embed"
  118. when: published_install_config.changed
  119. register: recreated_sno_cfg
  120. - name: Ensure custom ISO is gone if anything was changed.
  121. ansible.builtin.file:
  122. path: "{{ ansible_facts['user_dir'] }}/sno-embedded-cfg.iso"
  123. state: absent
  124. when:
  125. - recreated_sno_cfg is defined
  126. - recreated_sno_cfg.changed
  127. - name: Embed install config in the ISO.
  128. ansible.builtin.command:
  129. cmd: coreos-installer iso ignition embed -fi ./embed/bootstrap-in-place-for-live-iso.ign -o sno-embedded-cfg.iso {{ ansible_facts['user_dir'] }}/Downloads/rhcos-418.94.202501221327-0-live.x86_64.iso
  130. chdir: "{{ ansible_facts['user_dir'] }}"
  131. when:
  132. - recreated_sno_cfg is defined
  133. - recreated_sno_cfg.changed
  134. - name: Copy the ISO file to target machine and write it to /dev/sdb
  135. hosts: master01.ocp4.example.com
  136. gather_subset: min
  137. become: yes
  138. tasks:
  139. - name: Copy the ISO file to master01.
  140. ansible.builtin.copy:
  141. src: /home/student/sno-embedded-cfg.iso
  142. dest: /root/sno-embedded-cfg.iso
  143. mode: 0644
  144. register: copied_iso
  145. - name: Write the ISO to /dev/sdb if it was changed.
  146. ansible.builtin.command:
  147. cmd: dd if=/root/sno-embedded-cfg.iso of=/dev/sdb conv=sync bs=4k
  148. when: copied_iso.changed
  149. register: wrote_iso
  150. - name: Wipe the filesystem of /dev/sda if ISO was written to /dev/sdb.
  151. ansible.builtin.command:
  152. cmd: wipefs -af /dev/sda
  153. when: wrote_iso.changed
  154. register: wiped_fs
  155. - name: Reboot the machine if filesystem was wiped.
  156. ansible.builtin.command:
  157. cmd: reboot
  158. ignore_errors: yes
  159. when: wiped_fs.changed
  160. ...