-
Notifications
You must be signed in to change notification settings - Fork 0
/
130.configure.yaml
246 lines (213 loc) · 6.18 KB
/
130.configure.yaml
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
---
- name: Gather inventory hostname and IP mappings
hosts: all
vars_files:
- facts/infra.yaml
tasks:
- name: Set facts for hosts entries
set_fact:
hosts_entries: |
{% for host in groups['vms'] %}
{{ hostvars[host]['ansible_host'] }} {{ host }}
{% endfor %}
- name: Set up /etc/hosts
hosts: vms, local
vars_files:
- facts/infra.yaml
tasks:
- name: Remove existing entries for hosts from /etc/hosts
become: yes
lineinfile:
path: /etc/hosts
state: absent
regexp: ".*{{ item.name }}.*"
with_items: "{{ vms }}"
- name: Append new hosts entries to /etc/hosts
become: yes
lineinfile:
path: /etc/hosts
line: "{{ item }}"
state: present
with_items: "{{ hosts_entries.split('\n') }}"
when: item.strip() != ""
- name: Set up Kubernetes VMs
hosts: vms
vars_files:
- facts/infra.yaml
tasks:
- name: Remove IPv6 entries
lineinfile:
path: /etc/hosts
state: absent
regexp: '^::.*'
- name: Append hosts entries to /etc/hosts from inventory
become: yes
lineinfile:
path: /etc/hosts
create: yes
line: "{{ item }}"
state: present
with_items: "{{ hosts_entries.split('\n') }}"
when: item.strip() != ""
- name: Configure main dnf config
ansible.builtin.template:
src: templates/dnf.conf.j2
dest: /etc/dnf/dnf.conf
- name: Configure dnf for a specific repository
ansible.builtin.template:
src: templates/fedora.repo.j2
dest: /etc/yum.repos.d/fedora.repo
vars:
releasever: "{{ ansible_distribution_major_version }}"
basearch: "{{ ansible_architecture }}"
owner: root
group: root
mode: '0644'
- name: Create the Kubernetes repository file
ansible.builtin.template:
src: templates/k8s.repo.j2
dest: /etc/yum.repos.d/kubernetes.repo
owner: root
group: root
mode: '0644'
- name: Update package repositories
dnf:
name: '*'
state: latest
update_cache: yes
- name: Upgrade all packages
dnf:
name: '*'
state: latest
- name: Remove swap config
dnf:
name: "{{ item }}"
state: absent
with_items:
- zram-generator*
- name: Install Container, kubernetes and network tools
dnf:
name: "{{ item }}"
state: present
disable_excludes: "kubernetes"
with_items:
- container*
- kubelet
- kubeadm
- kubectl
- iproute*
- net-tools
- iputils*
- tracer*
- iptables*
- nftables*
- virtiofsd
- kubernetes-cni
- vim
- nfs-utils
- wireguard*
- name: Enable br_netfilter for containerd
copy:
dest: "/etc/modules-load.d/containerd.conf"
content: |
br_netfilter
- name: Enable ip forwarding
copy:
dest: "/etc/sysctl.d/kubernetes.conf"
content: |
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.all.forwarding = 0
net.ipv4.conf.all.rp_filter = 1
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_keepalive_intvl = 60
net.ipv4.tcp_keepalive_probes = 10
net.core.somaxconn = 65535
fs.file-max = 1000000
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_mtu_probing = 1
- name: Enable kubelet service
service:
name: kubelet
enabled: yes
- name: Enable kubelet containerd
service:
name: containerd
enabled: yes
- name: Set hostname to inventory name
hostname:
name: "{{ inventory_hostname }}"
- name: Disable SELinux in the configuration file
replace:
path: /etc/selinux/config
regexp: '^SELINUX='
replace: 'SELINUX=disabled'
- name: Disable SELinux for the current session
command: setenforce 0
when: ansible_selinux.status == "enabled"
- name: Disable swap immediately
command: swapoff -a
- name: Remove swap entry from /etc/fstab
replace:
path: /etc/fstab
regexp: '^\s*([^#\s]+)\s+none\s+swap\s+sw\s+0\s+0\s*$'
replace: '# \1 none swap sw 0 0'
- name: Disable firewalld
become: yes
systemd:
name: firewalld
state: stopped
enabled: no
- name: Ensure mount directory exists
file:
path: /data
state: directory
owner: root
group: root
mode: '0755'
- name: Add fstab entry for 9p filesystem
mount:
path: /data
src: hostshare
fstype: 9p
opts: trans=virtio,version=9p2000.L
state: present
- name: Mount the 9p filesystem
command: mount -a
args:
# - name: Copy wireguard config to {{ inventory_hostname }}
# copy:
# src: config/{{ inventory_hostname }}.conf
# dest: /etc/wireguard/wg0.conf
# mode: '0600'
# - name: Enable wireguard on boot
# service:
# name: wg-quick@wg0
# enabled: yes
# - name: Ensure /etc/resolv.conf has the correct DNS configuration
# ansible.builtin.copy:
# dest: /etc/resolv.conf
# content: |
# nameserver 8.8.8.8
# nameserver 8.8.4.4
# nameserver 127.0.0.53
# options edns0 trust-ad
# search .
- name: Create systemd drop-in directory for containerd service
ansible.builtin.file:
path: /etc/systemd/system/containerd.service.d
state: directory
- name: Create systemd drop-in config file for containerd service
ansible.builtin.template:
src: templates/containerd-proxy.conf.j2
dest: /etc/systemd/system/containerd.service.d/proxy.conf
- name: Reboot the machine
reboot:
msg: "Rebooting after initial setup"
pre_reboot_delay: 0
post_reboot_delay: 30
reboot_timeout: 600
- name: Wait for the machine to come back online
wait_for_connection:
timeout: 300