62-agent-installation.yml 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. ---
  2. # Configure the agent installation artifacts for SNO.
  3. # Mostly the same as 52-coreos-installer.yml, but some changes.
  4. - name: Prepare the files required for a SNO installation using agent install.
  5. hosts: workstation.lab.example.com
  6. become: no
  7. gather_subset: min
  8. tasks:
  9. - name: Check the dependency status.
  10. ansible.builtin.stat:
  11. path: "{{ ansible_facts['user_dir'] }}/{{ item }}"
  12. get_attributes: no
  13. get_checksum: no
  14. get_mime: no
  15. register: dependencies
  16. loop:
  17. - install-pull-secret
  18. - .ssh/openshift.pub
  19. - ca/ca-cert.pem
  20. - mirror/working-dir/cluster-resources/idms-oc-mirror.yaml
  21. - Downloads/rhcos-418.94.202501221327-0-live.x86_64.iso
  22. - ansible.builtin.assert:
  23. that:
  24. - dependencies.results[0].stat.exists
  25. - dependencies.results[1].stat.exists
  26. - dependencies.results[2].stat.exists
  27. - dependencies.results[3].stat.exists
  28. - dependencies.results[4].stat.exists
  29. fail_msg: |
  30. ERROR: Either pull secret, SSH keypair, CA certificate, RHCOS ISO, or mirror artifacts are missing.
  31. Ensure all the relevant preceding tasks have been completed:
  32. - Quay prerequisites,
  33. - Quay deployment,
  34. - oc-mirror prerequisites,
  35. - oc-mirror execution,
  36. - coreos-installer prerequisites
  37. Exiting.
  38. success_msg: "OK, dependencies exist."
  39. - name: Check whether someone fiddled with installation before.
  40. ansible.builtin.stat:
  41. path: "{{ ansible_facts['user_dir'] }}/agent/.openshift_install.log"
  42. register: install_log
  43. - name: Warn if installation log was found.
  44. ansible.builtin.pause:
  45. prompt: |
  46. WARNING: Found .openshift_install.log in the cluster working directory. This usually
  47. means there were previous attempts of creating installation artifacts.
  48. If you want to recreate the cluster working directory from scratch, run this
  49. playbook with the variable "recreate_cluster_dir" set to any value like this:
  50. ansible-playbook -e recreate_cluster_dir=yes ./52-coreos-installer.yml
  51. Continuing in 5 seconds unless you interrupt execution.
  52. seconds: 5
  53. when:
  54. - install_log.stat.exists
  55. - recreate_cluster_dir is not defined
  56. - name: Load the dependencies as facts.
  57. ansible.builtin.set_fact:
  58. pull_secret: "{{ lookup('ansible.builtin.file', ansible_facts['user_dir'] + '/install-pull-secret') }}"
  59. public_key: "{{ lookup('ansible.builtin.file', ansible_facts['user_dir'] + '/.ssh/openshift.pub') }}"
  60. lab_ca_cert: "{{ lookup('ansible.builtin.file', ansible_facts['user_dir'] + '/ca/ca-cert.pem') }}"
  61. content_sources: "{{ lookup('ansible.builtin.file', ansible_facts['user_dir'] + '/mirror/working-dir/cluster-resources/idms-oc-mirror.yaml')
  62. | ansible.builtin.from_yaml_all }}"
  63. - name: Set the fact determining installation type (required for templating).
  64. ansible.builtin.set_fact:
  65. install_type: agent
  66. install_host: master02.ocp4.example.com
  67. - name: Collect facts from the target machine (must be reachable for that).
  68. delegate_to: "{{ install_host }}"
  69. delegate_facts: yes
  70. ansible.builtin.setup:
  71. gather_subset: min,interfaces
  72. - name: Ensure install-config is there.
  73. ansible.builtin.template:
  74. src: templates/install-config-template.yaml.j2
  75. dest: "{{ ansible_facts['user_dir'] }}/install-config-agent.yaml"
  76. mode: 0644
  77. owner: student
  78. group: student
  79. register: updated_install_config
  80. - name: Ensure agent-config is there.
  81. ansible.builtin.template:
  82. src: templates/agent-config-template.yaml.j2
  83. dest: "{{ ansible_facts['user_dir'] }}/agent-config-sno.yaml"
  84. mode: 0644
  85. owner: student
  86. group: student
  87. register: updated_agent_config
  88. - name: Remove the installation directory if so required.
  89. ansible.builtin.file:
  90. path: "{{ ansible_facts['user_dir'] }}/agent"
  91. state: absent
  92. when:
  93. - recreate_cluster_dir is defined
  94. - recreate_cluster_dir
  95. - name: Ensure the presence of installation directory.
  96. ansible.builtin.file:
  97. path: "{{ ansible_facts['user_dir'] }}/agent"
  98. state: directory
  99. mode: 0755
  100. - name: Also, ensure that the right install-config.yaml file is in there.
  101. ansible.builtin.copy:
  102. src: "{{ ansible_facts['user_dir'] }}/install-config-agent.yaml"
  103. remote_src: yes
  104. dest: "{{ ansible_facts['user_dir'] }}/agent/install-config.yaml"
  105. mode: 0644
  106. register: published_install_config
  107. when:
  108. - (not install_log.stat.exists) or (recreate_cluster_dir is defined) or updated_install_config.changed or updated_agent_config.changed
  109. - name: The same, but for agent-config.yaml.
  110. ansible.builtin.copy:
  111. src: "{{ ansible_facts['user_dir'] }}/agent-config-sno.yaml"
  112. remote_src: yes
  113. dest: "{{ ansible_facts['user_dir'] }}/agent/agent-config.yaml"
  114. mode: 0644
  115. register: published_agent_config
  116. when:
  117. - (not install_log.stat.exists) or (recreate_cluster_dir is defined) or updated_install_config.changed or updated_agent_config.changed
  118. - name: This block will only execute if install-config or agent-config files were published.
  119. block:
  120. - name: Ensure the presence of customization directory.
  121. ansible.builtin.file:
  122. path: "{{ ansible_facts['user_dir'] }}/agent/openshift"
  123. state: directory
  124. mode: 0755
  125. - name: Render chrony customizations in home directory.
  126. ansible.builtin.template:
  127. src: templates/chrony-customization.bu.j2
  128. dest: "{{ ansible_facts['user_dir'] }}/chrony-{{ item }}.bu"
  129. mode: 0644
  130. owner: student
  131. group: student
  132. loop:
  133. - master
  134. - worker
  135. - name: Publish chrony customizations in manifests directory.
  136. ansible.builtin.command:
  137. cmd: butane ./chrony-{{ item }}.bu -o ./agent/openshift/99_chrony_{{ item }}.yaml
  138. chdir: "{{ ansible_facts['user_dir'] }}"
  139. creates: agent/openshift/99_chrony_{{ item }}.yaml
  140. loop:
  141. - master
  142. - worker
  143. - name: Ensure the agent image cache directory exists.
  144. ansible.builtin.file:
  145. path: "{{ ansible_facts['user_dir'] }}/.cache/agent/image_cache"
  146. state: directory
  147. mode: 0755
  148. - name: Ensure that the agent ISO and all other artifacts are gone if anything was updated.
  149. ansible.builtin.file:
  150. path: "{{ ansible_facts['user_dir'] }}/agent/{{ item }}"
  151. state: absent
  152. loop:
  153. - agent.x86_64.iso
  154. - auth
  155. - rendezvousIP
  156. - .openshift_install.log
  157. - .openshift_install_state.json
  158. when: published_install_config.changed or published_agent_config.changed
  159. - name: Check whether the ISO is there.
  160. ansible.builtin.stat:
  161. path: "{{ ansible_facts['user_dir'] }}/agent/agent.x86_64.iso"
  162. get_attributes: no
  163. get_checksum: no
  164. get_mime: no
  165. register: agent_iso
  166. - name: Ensure that CoreOS ISO is a link to the downloaded one in Downloads.
  167. ansible.builtin.file:
  168. path: "{{ ansible_facts['user_dir'] }}/.cache/agent/image_cache/coreos-x86_64.iso"
  169. state: hard
  170. src: "{{ ansible_facts['user_dir'] }}/Downloads/rhcos-418.94.202501221327-0-live.x86_64.iso"
  171. - name: Create agent installation ISO.
  172. ansible.builtin.command:
  173. cmd: openshift-install-fips agent create image
  174. chdir: "{{ ansible_facts['user_dir'] }}/agent"
  175. when: not agent_iso.stat.exists
  176. #- name: Copy the ISO file to target machine and write it to /dev/sdb
  177. # hosts: master02.ocp4.example.com
  178. # gather_subset: min
  179. # become: yes
  180. # tasks:
  181. # - name: Copy the ISO file to master01.
  182. # ansible.builtin.copy:
  183. # src: /home/student/agent/agent.x86_64.iso
  184. # dest: /root/agent.x86_64.iso
  185. # mode: 0644
  186. # register: copied_iso
  187. #
  188. # # TODO: ensure /dev/sdb1 exists and is bootable
  189. #
  190. # - name: Write the ISO to /dev/sdb1 if it was changed.
  191. # ansible.builtin.command:
  192. # cmd: dd if=/root/agent.x86_64.iso of=/dev/sdb1 conv=sync bs=4k
  193. # when: copied_iso.changed
  194. # register: wrote_iso
  195. #
  196. # - name: Wipe the filesystem of /dev/sda if ISO was written to /dev/sdb1.
  197. # ansible.builtin.command:
  198. # cmd: wipefs -af /dev/sda
  199. # when: wrote_iso.changed
  200. # register: wiped_fs
  201. #
  202. # - name: Reboot the machine if filesystem was wiped.
  203. # ansible.builtin.command:
  204. # cmd: reboot
  205. # ignore_errors: yes
  206. # when: wiped_fs.changed
  207. ...