config.yml 5.8 KB

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