-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbase.yaml
More file actions
191 lines (168 loc) · 4.71 KB
/
base.yaml
File metadata and controls
191 lines (168 loc) · 4.71 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
---
- hosts: all
become: true
gather_facts: yes
handlers:
- name: docker status
service: name=docker state=started
- name: kubelet status
service: name=kubelet state=started
tasks:
- name: Remove existing Docker Kubernetes packages
apt:
name: "{{ packages }}"
state: absent
update_cache: yes
vars:
packages:
- docker.io
- kubelet
- kubeadm
- kubectl
- kubernetes-cni
- docker-ce
- name: Recursively remove directory
ansible.builtin.file:
path: "{{ item }}"
state: absent
with_items:
- /root/.kube
- /etc/cni/net.d
- /etc/kubernetes
- /var/lib/etcd
- /var/lib/kubelet
- /var/run/kubernetes
- /var/lib/cni
- /opt/cni
- name: Iptables flush filter
ansible.builtin.iptables:
flush: yes
- name: Just force systemd to reread configs (2.4 and above)
ansible.builtin.systemd:
daemon_reload: yes
- name: Install packages that allow apt to be used over HTTPS
apt:
name: "{{ packages }}"
state: present
update_cache: yes
vars:
packages:
- apt-transport-https
- ca-certificates
- curl
- lsb-release
- gnupg
- software-properties-common
- wget
- name: Install Linux Headers for the kernelversion
apt:
name: linux-headers-{{ ansible_kernel }}
state: present
update_cache: true
- name: Add an apt signing key for Docker
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present
- name: Add an apt signing key for Kubernetes
apt_key:
url: https://packages.cloud.google.com/apt/doc/apt-key.gpg
state: present
- name: Adding apt repository for Kubernetes
apt_repository:
repo: deb https://apt.kubernetes.io/ kubernetes-xenial main
state: present
filename: kubernetes.list
- name: Add apt repository for stable version
apt_repository:
repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable
state: present
- name: Install docker and its dependecies
apt:
name: "{{ packages }}"
state: present
update_cache: yes
vars:
packages:
- etcd-client
- vim
- build-essential
- bash-completion
- binutils
- apparmor-utils
- docker-ce
- docker-ce-cli
- "kubelet={{ kube_version }}-00"
- "kubeadm={{ kube_version }}-00"
- "kubectl={{ kube_version }}-00"
- kubernetes-cni=0.8.7-00
notify:
- docker status
- name: Create new directory for Docker
ansible.builtin.file:
path: /etc/systemd/system/docker.service.d
state: directory
recurse: yes
- name: Add vagrant user to docker group
user:
name: vagrant
group: docker
- name: Remove swapfile from /etc/fstab
mount:
name: "{{ item }}"
fstype: swap
state: absent
with_items:
- swap
- none
- name: Disable swap
command: swapoff -a
when: ansible_swaptotal_mb > 0
- name: Deploy Docker daemon.json.
copy:
src: daemon.json
dest: /etc/docker/daemon.json
- name: Enable service docker
ansible.builtin.systemd:
name: docker
enabled: yes
- name: Restart kubelet and docker daemon
service:
name: "{{ item }}"
daemon_reload: yes
state: restarted
with_items:
- docker
- kubelet
notify:
- docker status
- kubelet status
- name: Remove useless packages from the cache
apt:
autoclean: yes
- name: Remove dependencies that are no longer required
apt:
autoremove: yes
- name: Create new directory for installer scripts
ansible.builtin.file:
path: "{{ item }}"
state: directory
recurse: yes
with_items:
- /etc/k8s-scripts
- /etc/k8s-init-scripts
- name: Copy Initialization Scripts
ansible.builtin.copy:
remote_src: yes
src: "{{ item.src }}"
dest: "{{ item.dest }}"
mode: '0755'
with_items:
- { src: /vagrant/master.yaml, dest: /etc/k8s-scripts/master.yaml }
- { src: /vagrant/worker.yaml, dest: /etc/k8s-scripts/worker.yaml }
- { src: /vagrant/set-custom-rc.sh, dest: /etc/k8s-init-scripts/set-custom-rc.sh }
- { src: /vagrant/approve-nodes.sh, dest: /etc/k8s-init-scripts/approve-nodes.sh }
- { src: /vagrant/kubeadm-config.yaml, dest: /etc/k8s-init-scripts/kubeadm-config.yaml }
- { src: /vagrant/metallb-config.yaml, dest: /etc/k8s-init-scripts/metallb-config.yaml }
- { src: /vagrant/enable-olm.sh, dest: /etc/k8s-init-scripts/enable-olm.sh }
- name: Pull Kubernetes images
shell: kubeadm config images pull