config.yml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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: Write /etc/containers/registries.conf
  64. copy:
  65. content: "{{ registries_conf.contents.source.split(',')[1] | urldecode }}"
  66. mode: "{{ '0' ~ registries_conf.mode }}"
  67. dest: "{{ registries_conf.path }}"
  68. register: update_registries
  69. - name: Restart the CRI-O service
  70. systemd:
  71. name: "crio"
  72. state: restarted
  73. when: update_registries is changed
  74. - name: Get cluster pull-secret
  75. command: >
  76. oc get secret pull-secret
  77. --config={{ openshift_node_kubeconfig_path }}
  78. --namespace=openshift-config
  79. --output=jsonpath='{.data.\.dockerconfigjson}'
  80. delegate_to: localhost
  81. register: oc_get
  82. until:
  83. - oc_get.stdout != ''
  84. retries: 36
  85. delay: 5
  86. - name: Write pull-secret to file
  87. copy:
  88. content: "{{ oc_get.stdout | b64decode }}"
  89. dest: "{{ temp_dir.path }}/pull-secret.json"
  90. - name: Get cluster release image
  91. command: >
  92. oc get clusterversion
  93. --config={{ openshift_node_kubeconfig_path }}
  94. --output=jsonpath='{.items[0].status.desired.image}'
  95. delegate_to: localhost
  96. register: oc_get
  97. until:
  98. - oc_get.stdout is defined
  99. - oc_get.stdout != ''
  100. retries: 36
  101. delay: 5
  102. - name: Set l_release_image fact
  103. set_fact:
  104. l_release_image: "{{ oc_get.stdout }}"
  105. - import_tasks: proxy.yml
  106. - block:
  107. - name: Pull release image
  108. command: "podman pull --tls-verify={{ openshift_node_tls_verify }} --authfile {{ temp_dir.path }}/pull-secret.json {{ l_release_image }}"
  109. - name: Get machine controller daemon image from release image
  110. command: "podman run --rm {{ l_release_image }} image machine-config-operator"
  111. register: release_image_mcd
  112. environment:
  113. http_proxy: "{{ http_proxy | default('')}}"
  114. https_proxy: "{{https_proxy | default('')}}"
  115. no_proxy: "{{ no_proxy | default('')}}"
  116. - block:
  117. - name: Pull MCD image
  118. command: "podman pull --tls-verify={{ openshift_node_tls_verify }} --authfile {{ temp_dir.path }}/pull-secret.json {{ release_image_mcd.stdout }}"
  119. - name: Apply ignition manifest
  120. command: "podman run {{ podman_mounts }} {{ podman_flags }} {{ mcd_command }}"
  121. vars:
  122. podman_flags: "--privileged --rm --entrypoint=/usr/bin/machine-config-daemon -ti {{ release_image_mcd.stdout }}"
  123. podman_mounts: "-v /:/rootfs -v /var/run/dbus:/var/run/dbus -v /run/systemd:/run/systemd"
  124. mcd_command: "start --node-name {{ ansible_nodename | lower }} --once-from {{ temp_dir.path }}/bootstrap.ign --skip-reboot"
  125. - name: Remove temp directory
  126. file:
  127. path: "{{ temp_dir.path }}"
  128. state: absent
  129. - name: Reboot the host and wait for it to come back
  130. reboot:
  131. # reboot_timeout: 600 # default, 10 minutes
  132. environment:
  133. http_proxy: "{{ http_proxy | default('')}}"
  134. https_proxy: "{{ https_proxy | default('')}}"
  135. no_proxy: "{{ no_proxy | default('')}}"
  136. rescue:
  137. - fail:
  138. msg: "Ignition apply failed"
  139. - name: Approve node-bootstrapper CSR
  140. shell: >
  141. count=0;
  142. for csr in `oc --config={{ openshift_node_kubeconfig_path }} get csr --no-headers \
  143. | grep " system:serviceaccount:openshift-machine-config-operator:node-bootstrapper " \
  144. | cut -d " " -f1`;
  145. do
  146. oc --config={{ openshift_node_kubeconfig_path }} describe csr/$csr \
  147. | grep " system:node:{{ hostvars[item].ansible_nodename | lower }}$";
  148. if [ $? -eq 0 ];
  149. then
  150. oc --config={{ openshift_node_kubeconfig_path }} adm certificate approve ${csr};
  151. if [ $? -eq 0 ];
  152. then
  153. count=$((count+1));
  154. fi;
  155. fi;
  156. done;
  157. exit $((!count));
  158. loop: "{{ ansible_play_batch }}"
  159. delegate_to: localhost
  160. run_once: true
  161. register: oc_get
  162. until:
  163. - oc_get is success
  164. retries: 6
  165. delay: 5
  166. - name: Approve node CSR
  167. shell: >
  168. count=0;
  169. for csr in `oc --config={{ openshift_node_kubeconfig_path }} get csr --no-headers \
  170. | grep " system:node:{{ hostvars[item].ansible_nodename | lower }} " \
  171. | cut -d " " -f1`;
  172. do
  173. oc --config={{ openshift_node_kubeconfig_path }} adm certificate approve ${csr};
  174. if [ $? -eq 0 ];
  175. then
  176. count=$((count+1));
  177. fi;
  178. done;
  179. exit $((!count));
  180. loop: "{{ ansible_play_batch }}"
  181. delegate_to: localhost
  182. run_once: true
  183. register: oc_get
  184. until:
  185. - oc_get is success
  186. retries: 6
  187. delay: 5
  188. - name: Wait for nodes to report ready
  189. command: >
  190. oc get node {{ hostvars[item].ansible_nodename | lower }}
  191. --config={{ openshift_node_kubeconfig_path }}
  192. --output=jsonpath='{.status.conditions[?(@.type=="Ready")].status}'
  193. loop: "{{ ansible_play_batch }}"
  194. delegate_to: localhost
  195. run_once: true
  196. register: oc_get
  197. until:
  198. - oc_get.stdout == "True"
  199. retries: 36
  200. delay: 5