config.yml 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. ---
  2. #### Disable SWAP #####
  3. # https://docs.openshift.com/container-platform/3.4/admin_guide/overcommit.html#disabling-swap-memory
  4. # swapoff is a custom module that comments out swap entries in
  5. # /etc/fstab and runs swapoff -a, if necessary.
  6. - name: Disable swap
  7. swapoff: {}
  8. # The atomic-openshift-node service will set this parameter on
  9. # startup, but if the network service is restarted this setting is
  10. # lost. Reference: https://bugzilla.redhat.com/show_bug.cgi?id=1372388
  11. - name: Enable IP Forwarding
  12. sysctl:
  13. name: net.ipv4.ip_forward
  14. value: 1
  15. sysctl_file: "/etc/sysctl.d/99-openshift.conf"
  16. reload: yes
  17. # The base OS RHEL with "Minimal" installation option is
  18. # enabled firewalld serivce by default, it denies unexpected 10250 port.
  19. # Reference: https://bugzilla.redhat.com/show_bug.cgi?id=1740439
  20. - name: Disable firewalld service
  21. systemd:
  22. name: "firewalld.service"
  23. enabled: false
  24. register: service_status
  25. failed_when:
  26. - service_status is failed
  27. - not ('Could not find the requested service' in service_status.msg)
  28. - name: Setting sebool container_manage_cgroup
  29. seboolean:
  30. name: container_manage_cgroup
  31. state: yes
  32. persistent: yes
  33. - name: Create temp directory
  34. tempfile:
  35. state: directory
  36. register: temp_dir
  37. - name: Wait for bootstrap endpoint to show up
  38. uri:
  39. url: "{{ openshift_node_bootstrap_endpoint }}"
  40. validate_certs: false
  41. delay: 10
  42. retries: 60
  43. register: result
  44. until:
  45. - result.status is defined
  46. - result.status == 200
  47. - name: Fetch bootstrap ignition file locally
  48. uri:
  49. url: "{{ openshift_node_bootstrap_endpoint }}"
  50. dest: "{{ temp_dir.path }}/bootstrap.ign"
  51. validate_certs: false
  52. register: bootstrap_ignition
  53. # registries.conf is listed twice in the config, the second one is the right one
  54. - name: Extract the last registries.conf file from bootstrap.ign
  55. set_fact:
  56. registries_conf: >
  57. {{
  58. bootstrap_ignition.json.storage.files
  59. | selectattr('path', 'match', '/etc/containers/registries.conf')
  60. | list
  61. | last
  62. }}
  63. - name: Check data URL encoding and extract source data
  64. set_fact:
  65. base64encoded: "{{ registries_conf.contents.source.split(',')[0].endswith('base64') }}"
  66. source_data: "{{ registries_conf.contents.source.split(',')[1] }}"
  67. - name: Write /etc/containers/registries.conf
  68. copy:
  69. content: "{{ (source_data | b64decode) if base64encoded else (source_data | urldecode) }}"
  70. mode: "{{ '0' ~ registries_conf.mode }}"
  71. dest: "{{ registries_conf.path }}"
  72. register: update_registries
  73. - name: Restart the CRI-O service
  74. systemd:
  75. name: "crio"
  76. state: restarted
  77. when: update_registries is changed
  78. - name: Get cluster pull-secret
  79. command: >
  80. oc get secret pull-secret
  81. --kubeconfig={{ openshift_node_kubeconfig_path }}
  82. --namespace=openshift-config
  83. --output=jsonpath='{.data.\.dockerconfigjson}'
  84. delegate_to: localhost
  85. register: oc_get
  86. until:
  87. - oc_get.stdout != ''
  88. retries: 36
  89. delay: 5
  90. - name: Write pull-secret to file
  91. copy:
  92. content: "{{ oc_get.stdout | b64decode }}"
  93. dest: "{{ temp_dir.path }}/pull-secret.json"
  94. - name: Get cluster release image
  95. command: >
  96. oc get clusterversion
  97. --kubeconfig={{ openshift_node_kubeconfig_path }}
  98. --output=jsonpath='{.items[0].status.desired.image}'
  99. delegate_to: localhost
  100. register: oc_get
  101. until:
  102. - oc_get.stdout != ''
  103. retries: 36
  104. delay: 5
  105. - name: Set l_release_image fact
  106. set_fact:
  107. l_release_image: "{{ oc_get.stdout }}"
  108. - import_tasks: proxy.yml
  109. - block:
  110. - name: Pull release image
  111. command: "podman pull --tls-verify={{ openshift_node_tls_verify }} --authfile {{ temp_dir.path }}/pull-secret.json {{ l_release_image }}"
  112. register: podman_pull
  113. until:
  114. podman_pull.stdout != ''
  115. retries: 12
  116. delay: 10
  117. - name: Get machine controller daemon image from release image
  118. command: "podman run --rm {{ l_release_image }} image machine-config-operator"
  119. register: release_image_mcd
  120. environment:
  121. http_proxy: "{{ http_proxy | default('')}}"
  122. https_proxy: "{{https_proxy | default('')}}"
  123. no_proxy: "{{ no_proxy | default('')}}"
  124. - block:
  125. - name: Pull MCD image
  126. command: "podman pull --tls-verify={{ openshift_node_tls_verify }} --authfile {{ temp_dir.path }}/pull-secret.json {{ release_image_mcd.stdout }}"
  127. register: podman_pull
  128. until:
  129. podman_pull.stdout != ''
  130. retries: 12
  131. delay: 10
  132. - name: Apply ignition manifest
  133. command: "podman run {{ podman_mounts }} {{ podman_flags }} {{ mcd_command }}"
  134. vars:
  135. podman_flags: "--privileged --rm --entrypoint=/usr/bin/machine-config-daemon -ti {{ release_image_mcd.stdout }}"
  136. podman_mounts: "-v /:/rootfs -v /var/run/dbus:/var/run/dbus -v /run/systemd:/run/systemd"
  137. mcd_command: "start --node-name {{ ansible_nodename | lower }} --once-from {{ temp_dir.path }}/bootstrap.ign --skip-reboot"
  138. - name: Remove temp directory
  139. file:
  140. path: "{{ temp_dir.path }}"
  141. state: absent
  142. - name: Reboot the host and wait for it to come back
  143. reboot:
  144. # reboot_timeout: 600 # default, 10 minutes
  145. environment:
  146. http_proxy: "{{ http_proxy | default('')}}"
  147. https_proxy: "{{ https_proxy | default('')}}"
  148. no_proxy: "{{ no_proxy | default('')}}"
  149. rescue:
  150. - fail:
  151. msg: "Ignition apply failed"
  152. - block:
  153. - name: Approve node CSRs
  154. oc_csr_approve:
  155. kubeconfig: "{{ openshift_node_kubeconfig_path }}"
  156. nodename: "{{ ansible_nodename | lower }}"
  157. delegate_to: localhost
  158. rescue:
  159. - import_tasks: gather_debug.yml
  160. - name: DEBUG - Failed to approve node CSRs
  161. fail:
  162. msg: "Failed to approve node-bootstrapper CSR"
  163. - block:
  164. - name: Wait for node to report ready
  165. command: >
  166. oc get node {{ ansible_nodename | lower }}
  167. --kubeconfig={{ openshift_node_kubeconfig_path }}
  168. --output=jsonpath='{.status.conditions[?(@.type=="Ready")].status}'
  169. delegate_to: localhost
  170. register: oc_get
  171. until:
  172. - oc_get.stdout == "True"
  173. retries: 36
  174. delay: 5
  175. changed_when: false
  176. rescue:
  177. - import_tasks: gather_debug.yml
  178. - name: DEBUG - Node failed to report ready
  179. fail:
  180. msg: "Node failed to report ready"