62-agent-installation.yml 9.0 KB

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