65-agent-ipi-multinode.yml 8.3 KB

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