ansible-playbooks/k8s/roles/kubernetes-worker/tasks/main.yml

25 lines
674 B
YAML

- name: Generate join token on the master node
command: kubeadm token create --print-join-command
register: join_command
delegate_to: "{{ groups['master'][0] }}"
run_once: true
changed_when: false
- name: Set join token as a fact
set_fact:
join_token: "{{ join_command.stdout }}"
run_once: true
- name: Check if node is already joined
command: kubectl get nodes
register: kubectl_nodes
ignore_errors: yes
changed_when: false
delegate_to: "{{ groups['master'][0] }}"
run_once: true
- name: Join worker node to the cluster
command: "{{ join_token }}"
when: >
join_token is defined and
inventory_hostname not in kubectl_nodes.stdout