-
Notifications
You must be signed in to change notification settings - Fork 1
/
worker.yml
32 lines (28 loc) · 964 Bytes
/
worker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
---
- hosts: purpose_kube_worker
become: yes
vars:
master_dns: "kube1.home"
tasks:
- name: retrieve a token
command: kubeadm token create --ttl 2h
register: token_to_join
run_once: true
delegate_to: "{{master_dns}}"
environment:
KUBECONFIG: "/etc/kubernetes/admin.conf"
- name: join cluster
command:
cmd: "kubeadm join {{master_dns}}:6443 --token {{token_to_join.stdout}} --discovery-token-unsafe-skip-ca-verification"
creates: "/etc/kubernetes/pki/ca.crt"
- name: list nodes
command: "kubectl get nodes -o custom-columns=NAME:.metadata.name"
register: running_nodes
delegate_to: "{{master_dns}}"
environment:
KUBECONFIG: "/etc/kubernetes/admin.conf"
changed_when: false
- fail:
msg: "Could not find node {{ansible_hostname}} in the cluster."
when: ansible_hostname not in running_nodes.stdout_lines
run_once: true