-
Notifications
You must be signed in to change notification settings - Fork 76
/
13_ignite_control_plane.yml
74 lines (65 loc) · 2.49 KB
/
13_ignite_control_plane.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
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
---
- name: Install cluster with kubeadm
vars_files:
- vars/k8s_cluster.yml
hosts: masters[0]
tasks:
- name: Perform k8s setup
when: k8s_installed is not defined
block:
- name: Start kubeadm install # noqa no-changed-when # noqa command-instead-of-shell
ansible.builtin.shell: kubeadm init --config /tmp/kubeadm-config.yaml --upload-certs
become: true
- name: Get information on generated certificate
community.crypto.x509_certificate_info:
path: /etc/kubernetes/pki/ca.crt
register: cert
become: true
- name: Set fact for certificate hash
ansible.builtin.set_fact:
kubehash: "sha256:{{ cert.public_key_fingerprints.sha256 | replace(':', '') }}"
- name: Create kube directory
ansible.builtin.file:
path: /home/kube/.kube
state: directory
mode: "0755"
- name: Copy kubeconfig
ansible.builtin.copy:
src: /etc/kubernetes/admin.conf
dest: /home/kube/.kube/config
remote_src: true
owner: "{{ ansible_user_id }}"
group: "{{ ansible_user_id }}"
mode: "0755"
become: true
- name: Fetch kubeconfig file
ansible.builtin.slurp:
src: /etc/kubernetes/admin.conf
register: kube_master
become: true
- name: Set kubeconfig as fact
ansible.builtin.set_fact:
kubeconfig: "{{ kube_master['content'] | b64decode }}"
- name: Set a flag if cluster setup is successful
ansible.builtin.set_fact:
k8s_installed: true
- name: Verify cluster has been initialized
vars_files:
- vars/k8s_cluster.yml
hosts: vm_host
tasks:
- name: Save kubeconfig as file
ansible.builtin.copy:
content: "{{ hostvars[groups['masters'][0]]['kubeconfig'] }}"
dest: "{{ workspace_directory.base_path }}/clusters/{{ k8s.cluster_name | default('k8s-test', true) }}/admin.kubeconfig"
mode: "0755"
- name: Wait for control-plane pods to be up and running
kubernetes.core.k8s:
state: present
api_version: v1
kind: Pod
namespace: kube-system
label_selectors: tier = control-plane
kubeconfig: "{{ workspace_directory.base_path }}/clusters/{{ k8s.cluster_name | default('k8s-test', true) }}/admin.kubeconfig"
wait: true
when: hostvars[groups['masters'][0]].k8s_installed is not defined