blob: 15db72ca32471421c9c46a1bba3cc706f7c4dddd [file] [log] [blame]
pceicicda1d10ac2022-11-10 23:59:17 +00001- hosts: all
2 become: true
3 tasks:
4 - name: Install packages that allow apt to be used over HTTPS
5 apt:
6 name: "{{ packages }}"
7 state: present
8 vars:
9 packages:
10 - apt-transport-https
11 - ca-certificates
12 - curl
13 - gnupg-agent
14 - software-properties-common
15
16 - name: Add the apt signing key for Docker
17 apt_key:
18 url: https://download.docker.com/linux/ubuntu/gpg
19 state: present
20
21 - name: Add the apt repository for the stable Docker version
22 apt_repository:
23 repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable
24 state: present
25
26 - name: Install Docker and its dependencies
27 apt:
28 name: "{{ packages }}"
29 state: present
30 update_cache: yes
31 vars:
32 packages:
33 - docker-ce
34 - docker-ce-cli
35 - containerd.io
36
37 - name: Ensure user group exists
38 group:
39 name: "{{ ansible_user }}"
40
41 - name: Add user to the docker group
42 user:
43 name: "{{ ansible_user }}"
44 groups: docker,{{ ansible_user }}
45 append: yes
46
47 - name: Remove swapfile from /etc/fstab
48 mount:
49 name: "{{ item }}"
50 fstype: swap
51 state: absent
52 with_items:
53 - swap
54 - none
55
56 - name: Disable swap
57 command: swapoff -a
58 when: ansible_swaptotal_mb > 0
59
60 - name: Add the apt signing key for Kubernetes
61 apt_key:
62 url: https://packages.cloud.google.com/apt/doc/apt-key.gpg
63 state: present
64
65 - name: Add the apt repository for Kubernetes
66 apt_repository:
67 repo: deb https://apt.kubernetes.io/ kubernetes-xenial main
68 state: present
69 filename: kubernetes.list
70
71 - name: Install Kubernetes binaries
72 apt:
73 name: "{{ packages }}"
74 update_cache: yes
75 vars:
76 packages:
77 - kubelet=1.19.16-00
78 - kubeadm=1.19.16-00
79 - kubectl=1.19.16-00
80
81 - name: Restart kubelet
82 service:
83 name: kubelet
84 daemon_reload: yes
85 state: restarted
86
87 - name: Making systemd as Cgroup Driver
88 copy:
89 src: daemon.json
90 dest: /etc/docker/daemon.json
91
92 - name: Restaring Docker...
93 service:
94 name: docker
95 state: restarted
96
97 - name: update sysctl param
98 copy:
99 src: k8s.conf
100 dest: /etc/sysctl.d/k8s.conf
101 owner: root
102 group: root
103
104 - name: System reload
105 shell: sysctl --system
106
107 - name: Initialize the Kubernetes cluster
108 become: true
109 command: kubeadm init --pod-network-cidr=10.244.0.0/16
110
111 - name: Setup kubeconfig
112 command: "{{ item }}"
113 with_items:
114 - mkdir -p "$HOME/.kube"
115 - sudo cp /etc/kubernetes/admin.conf "$HOME/.kube/config"
116 - sudo chown "{{ ansible_user }}:{{ ansible_user }}" "$HOME/.kube/config"
117
118 - name: Deploy Flannel
119 become: true
120 command: kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml
121
122 - name: Remove taints from master node
123 become: true
124 command: kubectl taint nodes --all node-role.kubernetes.io/master-
125
126 - name: Create Tiller service account
127 become: true
128 command: kubectl -n kube-system create serviceaccount tiller
129
130 - name: Setup Tiller ClusterBinding
131 become: true
132 command: kubectl create clusterrolebinding tiller --clusterrole=cluster-admin --serviceaccount=kube-system:tiller