summaryrefslogtreecommitdiff
path: root/roles/kubernetes/kubeadm/worker/tasks/main.yml
blob: 835967b805613518273f951f06ce34f4e15c6622 (plain) (blame)
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
32
33
34
35
36
37
38
39
---
- name: generate kubeadm.config
  template:
    src: kubeadm.config.j2
    dest: /etc/kubernetes/kubeadm.config
    mode: 0600
  changed_when: False

- name: join kubernetes worker node and store log
  block:
  - name: join kubernetes worker node
    command: "kubeadm join --config /etc/kubernetes/kubeadm.config"
    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

  - name: dump error output of kubeadm join to log file
    when: kubeadm_join.changed and kubeadm_join.stderr
    copy:
      content: "{{ kubeadm_join.stderr }}\n"
      dest: /etc/kubernetes/kubeadm-join.errors

- name: wait for new worker node to register
  delegate_to: "{{ groups['_kubernetes_primary_controlplane_node_'] | first }}"
  check_mode: no
  command: "kubectl --kubeconfig /etc/kubernetes/admin.conf get nodes -o name {{ kubernetes_node_name }}"
  changed_when: False
  register: kubectl_node_get
  until: kubectl_node_get.rc == 0
  retries: 30
  delay: 2