34 lines
922 B
YAML
34 lines
922 B
YAML
- name: Check if cluster initialized
|
|
stat:
|
|
path: /etc/kubernetes/admin.conf
|
|
register: k8s_admin_conf
|
|
|
|
- name: Initialize cluster
|
|
shell: kubeadm init --apiserver-advertise-address={{ control_plane_endpoint }} --pod-network-cidr={{ pod_network_cidr }}
|
|
when: not k8s_admin_conf.stat.exists
|
|
register: kubeadm_init
|
|
|
|
- name: Create kube dir
|
|
file:
|
|
path: /root/.kube
|
|
state: directory
|
|
|
|
- name: Copy admin.conf
|
|
copy:
|
|
src: /etc/kubernetes/admin.conf
|
|
dest: /root/.kube/config
|
|
remote_src: yes
|
|
|
|
- name: Install flannel
|
|
shell: kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml
|
|
environment:
|
|
KUBECONFIG: /etc/kubernetes/admin.conf
|
|
|
|
- name: Generate join command
|
|
shell: kubeadm token create --print-join-command
|
|
register: join_command_raw
|
|
|
|
- name: Set join command fact
|
|
set_fact:
|
|
join_command: "{{ join_command_raw.stdout }}"
|