diff options
Diffstat (limited to 'edge/sample/roles')
-rw-r--r-- | edge/sample/roles/clusterForm_common/tasks/main.yml | 127 | ||||
-rw-r--r-- | edge/sample/roles/clusterForm_master/tasks/main.yml | 72 | ||||
-rw-r--r-- | edge/sample/roles/clusterForm_slave(s)/tasks/main.yml | 12 | ||||
-rw-r--r-- | edge/sample/roles/clusterTear_common/tasks/main.yml | 21 |
4 files changed, 232 insertions, 0 deletions
diff --git a/edge/sample/roles/clusterForm_common/tasks/main.yml b/edge/sample/roles/clusterForm_common/tasks/main.yml new file mode 100644 index 0000000..a690d28 --- /dev/null +++ b/edge/sample/roles/clusterForm_common/tasks/main.yml @@ -0,0 +1,127 @@ +# Copyright (c) Authors of Clover +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 + +- name: Checking dependencies for Docker + shell: docker --version + register: doc_ver + ignore_errors: true + failed_when: false + +- name: Removing unsupported version of Docker (if any) + apt: + name: "{{ item }}" + state: absent + with_items: + - 'docker' + - 'docker-engine' + - 'docker-ce' + - 'docker.io' + when: doc_ver.stdout.find('18.04.0-ce') == -1 + +- name: Adding GPG key for Docker + apt_key: + url: https://download.docker.com/linux/debian/gpg + state: present + when: doc_ver.stdout.find('18.04.0-ce') == -1 + +- name: Updating sources.list.d directory + shell: echo "deb [arch=armhf] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") $(lsb_release -cs) edge" | \ tee /etc/apt/sources.list.d/docker.list + when: doc_ver.stdout.find('18.04.0-ce') == -1 + +- name: Installing Docker 18.04.0 + apt: + name: docker-ce=18.04.0~ce~3-0~raspbian + update_cache: yes + when: doc_ver.stdout.find('18.04.0-ce') == -1 + +- name: Adding user 'pi' to the 'docker' group + shell: usermod pi -aG docker + when: doc_ver.stdout.find('18.04.0-ce') == -1 + +- name: Removing docker from apt sources to prevent upgrade + file: + path: /etc/apt/sources.list.d/docker.list + state: absent + +- name: Turning off swap + shell: dphys-swapfile swapoff && dphys-swapfile uninstall && update-rc.d dphys-swapfile remove + +- name: Checking cgroup dependencies + shell: cat /boot/cmdline.txt + register: boot + +- name: Enabling cpuset cgroup + shell: sed -i 's/$/ cgroup_enable=cpuset/' /boot/cmdline.txt + args: + warn: false + when: boot.stdout.find('cgroup_enable=cpuset') == -1 + +- name: Enabling memory cgroup (1/2) + shell: sed -i 's/$/ cgroup_memory=1/' /boot/cmdline.txt + args: + warn: false + when: boot.stdout.find('cgroup_memory=1') == -1 + +- name: Enabling memory cgroup (2/2) + shell: sed -i 's/$/ cgroup_enable=memory/' /boot/cmdline.txt + args: + warn: false + when: boot.stdout.find('cgroup_enable=memory') == -1 + +- name: Rebooting + shell: sleep 2 && reboot + async: 1 + poll: 0 + ignore_errors: true + when: boot.stdout.find('cgroup_enable=cpuset') == -1 or boot.stdout.find('cgroup_memory=1') == -1 or boot.stdout.find('cgroup_enable=memory') == -1 + +- name: Waiting for host(s) to come online + wait_for_connection: + delay: 30 + when: boot.stdout.find('cgroup_enable=cpuset') == -1 or boot.stdout.find('cgroup_memory=1') == -1 or boot.stdout.find('cgroup_enable=memory') == -1 + +- name: Checking dependencies for Kubernetes + shell: kubeadm version + register: kube_ver + ignore_errors: true + failed_when: false + +- name: Removing unsupported version of Kubernetes (if any) + apt: + name: "{{ item }}" + state: absent + autoremove: yes + with_items: + - 'kubeadm' + - 'kubectl' + - 'kubelet' + when: kube_ver.stdout.find('v1.10.2') == -1 + +- name: Adding GPG key for kubernetes + apt_key: + url: https://packages.cloud.google.com/apt/doc/apt-key.gpg + state: present + when: kube_ver.stdout.find('v1.10.2') == -1 + +- name: Updating sources.list.d directory + shell: echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list + when: kube_ver.stdout.find('v1.10.2') == -1 + +- name: Installing kubeadm, kubectl and kubelet version 1.10.2-00 + apt: + name: "{{ item }}" + update_cache: true + with_items: + - 'kubeadm=1.10.2-00' + - 'kubectl=1.10.2-00' + - 'kubelet=1.10.2-00' + when: kube_ver.stdout.find('v1.10.2') == -1 + +- name: Removing kubernetes from apt sources to prevent upgrade + file: + path: /etc/apt/sources.list.d/kubernetes.list + state: absent diff --git a/edge/sample/roles/clusterForm_master/tasks/main.yml b/edge/sample/roles/clusterForm_master/tasks/main.yml new file mode 100644 index 0000000..9137d7f --- /dev/null +++ b/edge/sample/roles/clusterForm_master/tasks/main.yml @@ -0,0 +1,72 @@ +# Copyright (c) Authors of Clover +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 + +- name: Resetting kubeadm on master + shell: kubeadm reset + +- name: Removing KUBELET_NETWORK_ARGS flag in the kubadm config file + shell: sed -i '/KUBELET_NETWORK_ARGS=/d' /etc/systemd/system/kubelet.service.d/10-kubeadm.conf + args: + warn: false + +- name: Removing redundant config files (1/3) + file: + path: /home/pi/.kube + state: absent + +- name: Removing redundant config files (2/3) + file: + path: /home/pi/join.sh + state: absent + +- name: Removing redundant config files (3/3) + file: + path: /home/pi/kubelog.txt + state: absent + +- name: Initializing kubeadm + shell: kubeadm init --token-ttl=0 --pod-network-cidr 10.244.0.0/16 --apiserver-advertise-address={{ ansible_default_ipv4.address }} > kubelog.txt + +- name: Scraping the join token + shell: cat kubelog.txt | grep 'kubeadm join' > join.sh && sed "s/^[ \t]*//" -i join.sh + args: + warn: false + become: false + +- name: Fetching the joining script + fetch: + src: /home/pi/join.sh + dest: ./ + flat: yes + become: false + +- name: Making a .kube directory in home + file: + path: /home/pi/.kube + state: directory + become: false + +- name: Copying admin config file to .kube directory + copy: + src: /etc/kubernetes/admin.conf + dest: /home/pi/.kube/config + remote_src: yes + +- name: Changing user and group ownership of the config file + shell: chown $(id -u):$(id -g) /home/pi/.kube/config + args: + warn: false + +- name: Installing Flannel + shell: curl -sSL https://rawgit.com/coreos/flannel/v0.10.0/Documentation/kube-flannel.yml | sed "s/amd64/arm/g" | kubectl create -f - + args: + warn: false + become: false + +- name: Pause a minute for system containers to spin up + pause: + minutes: 1 diff --git a/edge/sample/roles/clusterForm_slave(s)/tasks/main.yml b/edge/sample/roles/clusterForm_slave(s)/tasks/main.yml new file mode 100644 index 0000000..206e86c --- /dev/null +++ b/edge/sample/roles/clusterForm_slave(s)/tasks/main.yml @@ -0,0 +1,12 @@ +# Copyright (c) Authors of Clover +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 + +- name: Resetting kubeadm on slaves + shell: kubeadm reset + +- name: Join the cluster, slaves! + script: join.sh diff --git a/edge/sample/roles/clusterTear_common/tasks/main.yml b/edge/sample/roles/clusterTear_common/tasks/main.yml new file mode 100644 index 0000000..64b1320 --- /dev/null +++ b/edge/sample/roles/clusterTear_common/tasks/main.yml @@ -0,0 +1,21 @@ +# Copyright (c) Authors of Clover +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 + +- name: Resetting kubeadm + shell: kubeadm reset + +- name: Deleting the .kube config directory + file: + path: /home/pi/.kube + state: absent + when: "'master' in group_names" + +- name: Rebooting + shell: sleep 2 && reboot + async: 1 + poll: 0 + ignore_errors: true |