2018-05-09 16:19:11 +02:00
|
|
|
---
|
|
|
|
- include_tasks: setup-RedHat.yml
|
|
|
|
when: ansible_os_family == 'RedHat'
|
|
|
|
|
|
|
|
- include_tasks: setup-Debian.yml
|
|
|
|
when: ansible_os_family == 'Debian'
|
|
|
|
|
|
|
|
- name: Ensure depdencies are installed.
|
|
|
|
package: name=curl state=present
|
|
|
|
|
|
|
|
- name: Install Kubernetes packages.
|
|
|
|
package:
|
|
|
|
name: "{{ item.name | default(item) }}"
|
|
|
|
state: "{{ item.state | default('present') }}"
|
|
|
|
notify: restart kubelet
|
|
|
|
with_items: "{{ kubernetes_packages }}"
|
|
|
|
|
2018-05-09 18:15:30 +02:00
|
|
|
- name: Allow kubelet to run with swap enabled (if configured).
|
|
|
|
lineinfile:
|
|
|
|
path: /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
|
|
|
|
line: 'Environment="KUBELET_EXTRA_ARGS=--fail-swap-on=false"'
|
|
|
|
regexp: 'Environment="KUBELET_EXTRA_ARGS=--fail-swap-on.+'
|
|
|
|
insertafter: '^Environment='
|
|
|
|
state: present
|
|
|
|
when: kubernetes_allow_swap
|
|
|
|
|
2018-05-09 16:19:11 +02:00
|
|
|
- name: Ensure kubelet is started and enabled at boot.
|
|
|
|
service:
|
|
|
|
name: kubelet
|
|
|
|
state: started
|
|
|
|
enabled: yes
|
|
|
|
|
2018-05-09 18:15:30 +02:00
|
|
|
- name: Check if Kubernetes has already been initialized.
|
|
|
|
stat:
|
|
|
|
path: /etc/kubernetes/admin.conf
|
|
|
|
register: kubernetes_init_stat
|
|
|
|
|
2018-05-09 16:19:11 +02:00
|
|
|
- name: Initialize the Kubernetes master with kubeadm init.
|
|
|
|
command: >
|
|
|
|
kubeadm init
|
|
|
|
--pod-network-cidr=10.0.1.0/16
|
|
|
|
--apiserver-advertise-address={{ ansible_default_ipv4.address }}
|
|
|
|
--kubernetes-version stable-1.10
|
|
|
|
--ignore-preflight-errors=all
|
|
|
|
register: kubeadmin_init
|
2018-05-09 16:35:24 +02:00
|
|
|
failed_when: False
|
2018-05-09 18:15:30 +02:00
|
|
|
when: kubernetes_init_stat.stat.exists == False
|
2018-05-09 16:19:11 +02:00
|
|
|
|
|
|
|
- name: Print the init output to screen.
|
|
|
|
debug: var=kubeadmin_init.stdout
|
2018-05-09 18:15:30 +02:00
|
|
|
when: kubernetes_init_stat.stat.exists == False
|
|
|
|
|
|
|
|
- name: Ensure .kube directory exists.
|
|
|
|
file:
|
|
|
|
path: ~/.kube
|
|
|
|
state: directory
|
|
|
|
|
|
|
|
- name: Symlink the kubectl admin.conf to ~/.kube/conf.
|
|
|
|
file:
|
|
|
|
src: /etc/kubernetes/admin.conf
|
|
|
|
dest: ~/.kube/config
|
|
|
|
state: link
|
|
|
|
|
|
|
|
- name: Configure Flannel networking.
|
|
|
|
command: "{{ item }}"
|
|
|
|
with_items:
|
|
|
|
- kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
|
|
|
|
- kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/k8s-manifests/kube-flannel-rbac.yml
|
2018-05-09 16:19:11 +02:00
|
|
|
|
2018-05-09 18:15:30 +02:00
|
|
|
# TODO: Check if taint exists with something like `kubectl describe nodes`
|
|
|
|
# instead of using kubernetes_init_stat.stat.exists check.
|
|
|
|
- name: Allow pods on master node (if configured).
|
|
|
|
command: "kubectl taint nodes --all node-role.kubernetes.io/master-"
|
|
|
|
when:
|
|
|
|
- kubernetes_allow_pods_on_master
|
|
|
|
- kubernetes_init_stat.stat.exists == False
|
2018-05-09 16:21:39 +02:00
|
|
|
|
2018-05-09 21:51:36 +02:00
|
|
|
- name: Check if Kubernetes Dashboard UI service already exists.
|
|
|
|
shell: kubectl get services --namespace kube-system | grep -q kubernetes-dashboard
|
|
|
|
changed_when: False
|
|
|
|
register: kubernetes_dashboard_service
|
|
|
|
when: kubernetes_enable_web_ui
|
|
|
|
|
2018-05-09 18:15:30 +02:00
|
|
|
- name: Enable the Kubernetes Web Dashboard UI (if configured).
|
|
|
|
command: "kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml"
|
2018-05-09 21:51:36 +02:00
|
|
|
when:
|
|
|
|
- kubernetes_enable_web_ui
|
|
|
|
- kubernetes_dashboard_service is failed
|