You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.3 KiB

  1. ---
  2. - name: Set kubeadm_discovery_address
  3. set_fact:
  4. kubeadm_discovery_address: >-
  5. {%- if "127.0.0.1" in kube_apiserver_endpoint or "localhost" in kube_apiserver_endpoint -%}
  6. {{ first_kube_master }}:{{ kube_apiserver_port }}
  7. {%- else -%}
  8. {{ kube_apiserver_endpoint | regex_replace('https://', '') }}
  9. {%- endif %}
  10. tags:
  11. - facts
  12. - name: Upload certificates so they are fresh and not expired
  13. command: >-
  14. {{ bin_dir }}/kubeadm init phase
  15. --config {{ kube_config_dir }}/kubeadm-config.yaml
  16. upload-certs
  17. --upload-certs
  18. register: kubeadm_upload_cert
  19. when:
  20. - inventory_hostname == groups['kube-master']|first
  21. - name: Parse certificate key if not set
  22. set_fact:
  23. kubeadm_certificate_key: "{{ hostvars[groups['kube-master'][0]]['kubeadm_upload_cert'].stdout_lines[-1] | trim }}"
  24. run_once: yes
  25. when:
  26. - hostvars[groups['kube-master'][0]]['kubeadm_upload_cert'] is defined
  27. - hostvars[groups['kube-master'][0]]['kubeadm_upload_cert'] is not skipped
  28. - name: Create kubeadm ControlPlane config
  29. template:
  30. src: "kubeadm-controlplane.{{ kubeadmConfig_api_version }}.yaml.j2"
  31. dest: "{{ kube_config_dir }}/kubeadm-controlplane.yaml"
  32. mode: 0640
  33. backup: yes
  34. when:
  35. - inventory_hostname != groups['kube-master']|first
  36. - not kubeadm_already_run.stat.exists
  37. - name: Wait for k8s apiserver
  38. wait_for:
  39. host: "{{ kubeadm_discovery_address.split(':')[0] }}"
  40. port: "{{ kubeadm_discovery_address.split(':')[1] }}"
  41. timeout: 180
  42. - name: check already run
  43. debug:
  44. msg: "{{ kubeadm_already_run.stat.exists }}"
  45. - name: Joining control plane node to the cluster.
  46. shell: >-
  47. if [ -f /etc/kubernetes/manifests/kube-apiserver.yaml ]; then
  48. {{ bin_dir }}/kubeadm reset -f --cert-dir {{ kube_cert_dir }};
  49. fi &&
  50. {{ bin_dir }}/kubeadm join
  51. --config {{ kube_config_dir }}/kubeadm-controlplane.yaml
  52. --ignore-preflight-errors=all
  53. register: kubeadm_join_control_plane
  54. retries: 3
  55. until: kubeadm_join_control_plane is succeeded
  56. when:
  57. - inventory_hostname != groups['kube-master']|first
  58. - kubeadm_already_run is not defined or not kubeadm_already_run.stat.exists
  59. environment:
  60. PATH: "{{ bin_dir }}:{{ ansible_env.PATH }}"
  61. - name: Set secret_changed to false to avoid extra token rotation
  62. set_fact:
  63. secret_changed: false