--- - name: fetch secrets needed for secondary master run_once: true delegate_to: "{{ groups['_kubernetes_primary_master_'] | first }}" block: - name: fetch list of current nodes command: kubectl --kubeconfig /etc/kubernetes/admin.conf get nodes -o name changed_when: False check_mode: no register: kubectl_node_list - name: save list of current nodes set_fact: kubernetes_current_nodes: "{{ kubectl_node_list.stdout_lines | map('replace', 'node/', '') | list }}" - name: upload certs when: "groups['_kubernetes_masters_'] | difference(kubernetes_current_nodes) | length > 0" command: kubeadm init phase upload-certs --upload-certs check_mode: no register: kubeadm_upload_certs - name: extracting encryption key for certs set_fact: kubeadm_upload_certs_key: "{% if kubeadm_upload_certs.stdout is defined %}{{ kubeadm_upload_certs.stdout_lines | last }}{% endif %}" - name: join kubernetes secondary master node and store log block: - name: join kubernetes secondary master node command: "kubeadm join 127.0.0.1:6443 --node-name {{ inventory_hostname }} --apiserver-bind-port 6442{% if kubernetes_overlay_node_ip is defined %} --apiserver-advertise-address {{ kubernetes_overlay_node_ip }}{% endif %}{% if kubernetes_cri_socket %} --cri-socket {{ kubernetes_cri_socket }}{% endif %} --token '{{ kube_bootstrap_token }}' --discovery-token-ca-cert-hash '{{ kube_bootstrap_ca_cert_hash }}' --control-plane --certificate-key {{ kubeadm_upload_certs_key }}" args: creates: /etc/kubernetes/kubelet.conf register: kubeadm_join always: - name: dump output of kubeadm join to log file when: kubeadm_join is changed # This is not a handler by design to make sure this action runs at this point of the play. copy: # noqa 503 content: "{{ kubeadm_join.stdout }}\n" dest: /etc/kubernetes/kubeadm-join.log # TODO: acutally check if node has registered - name: give the new master(s) a moment to register when: kubeadm_join is changed pause: # noqa 503 seconds: 5