62-agent-installation.yml 9.4 KB

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