summaryrefslogtreecommitdiff
path: root/roles/kubernetes/kubeadm/control-plane/tasks/main.yml
blob: 65e367ba6ce6041f5193d1e5e3e05bd7e8595b6a (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
---
- name: create direcotry for encryption config
  file:
    name: /etc/kubernetes/encryption
    state: directory
    mode: 0700

- name: install encryption config
  template:
    src: encryption-config.j2
    dest: /etc/kubernetes/encryption/config
    mode: 0600


- name: install primary control-plane node
  when: "'_kubernetes_primary_controlplane_node_' in group_names"
  include_tasks: primary.yml

- name: install secondary control-plane nodes
  when: "'_kubernetes_primary_controlplane_node_' not in group_names"
  include_tasks: secondary.yml


- name: check if control-plane node is tainted (1/2)
  command: "kubectl --kubeconfig /etc/kubernetes/admin.conf get node {{ kubernetes_node_name }} -o json"
  check_mode: no
  register: kubectl_get_node
  changed_when: False

- name: check if control-plane node is tainted (2/2)
  set_fact:
    kube_node_taints: "{% set node_info = kubectl_get_node.stdout | from_json %}{%if node_info.spec.taints is defined %}{{ node_info.spec.taints | map(attribute='key') | list }}{% endif %}"

- name: remove control-plane taint from node
  when:
  - not kubernetes.dedicated_controlplane_nodes
  - "'node-role.kubernetes.io/control-plane' in kube_node_taints"
  command: "kubectl --kubeconfig /etc/kubernetes/admin.conf taint nodes {{ kubernetes_node_name }} node-role.kubernetes.io/control-plane-"

- name: add control-plane taint to node
  when:
  - kubernetes.dedicated_controlplane_nodes
  - "'node-role.kubernetes.io/control-plane' not in kube_node_taints"
  command: "kubectl --kubeconfig /etc/kubernetes/admin.conf taint nodes {{ kubernetes_node_name }} node-role.kubernetes.io/control-plane='':NoSchedule"

- name: prepare kubectl (1/2)
  file:
    name: /root/.kube
    state: directory

- name: prepare kubectl (2/2)
  file:
    dest: /root/.kube/config
    src: /etc/kubernetes/admin.conf
    state: link

- name: add kubectl completion config for shells
  loop:
  - zsh
  - bash
  blockinfile:
    path: "/root/.{{ item }}rc"
    create: yes
    marker: "### {mark} ANSIBLE MANAGED BLOCK for kubectl ###"
    content: |
      source <(kubectl completion {{ item }})


- name: install k9s
  apt:
    name: k9s
    state: present

- name: add k9s completion config for shells
  loop:
  - zsh
  - bash
  blockinfile:
    path: "/root/.{{ item }}rc"
    create: yes
    marker: "### {mark} ANSIBLE MANAGED BLOCK for k9s ###"
    content: |
      source <(k9s completion {{ item }})