blob: 8051d137a16e38cc8abf606428bac348d8fec369 [file] [log] [blame]
Mohammed Naser336caf42022-03-11 17:56:45 -05001# Copyright (c) 2022 VEXXHOST, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15- name: Add repository keys
16 ansible.builtin.copy:
17 src: apt-key.gpg
18 dest: /usr/share/keyrings/kubernetes-archive-keyring.gpg
Mohammed Naser511c3fa2022-03-17 17:54:10 -040019 owner: root
20 group: root
21 mode: 0644
Mohammed Naser336caf42022-03-11 17:56:45 -050022 when:
23 - kubernetes_repo_url == _kubernetes_upstream_apt_repository
24
25- name: Add repository
26 ansible.builtin.apt_repository:
Mohammed Naser511c3fa2022-03-17 17:54:10 -040027 repo:
28 deb
29 {% if kubernetes_repo_url == _kubernetes_upstream_apt_repository %}[signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg]{% endif %}
30 {{ kubernetes_repo_url }}
31 kubernetes-xenial
32 main
Mohammed Naser336caf42022-03-11 17:56:45 -050033 state: present
34
35- name: Setup version pins
36 ansible.builtin.template:
37 src: apt-preferences.j2
38 dest: /etc/apt/preferences.d/kubernetes
39 mode: 0644
40
41- name: Install packages
42 ansible.builtin.apt:
43 name:
Mohammed Naserb19a6312023-01-19 02:43:40 +000044 - "cri-tools={{ kubernetes_cri_tools_version }}-00"
Mohammed Naser336caf42022-03-11 17:56:45 -050045 - "kubeadm={{ kubernetes_version }}-00"
46 - "kubectl={{ kubernetes_version }}-00"
47 - "kubelet={{ kubernetes_version }}-00"
48 state: present
49
Tadas Sutkaitis06159252023-02-20 17:15:42 +020050- name: Create crictl config
51 ansible.builtin.template:
52 src: crictl.yaml.j2
53 dest: /etc/crictl.yaml
54 owner: root
55 mode: 0644
56
Mohammed Naser336caf42022-03-11 17:56:45 -050057- name: Enable kernel modules on-boot
58 ansible.builtin.template:
59 src: modules-load.conf.j2
60 dest: /etc/modules-load.d/k8s.conf
Mohammed Naser511c3fa2022-03-17 17:54:10 -040061 owner: root
62 group: root
63 mode: 0644
Mohammed Naser336caf42022-03-11 17:56:45 -050064
65- name: Enable kernel modules in runtime
66 community.general.modprobe:
67 name: "{{ item }}"
68 state: present
69 loop: "{{ kubernetes_kernel_modules }}"
70
71- name: Configure sysctl values
72 ansible.posix.sysctl:
73 name: "{{ item.name }}"
74 value: "{{ item.value }}"
75 state: present
76 loop: "{{ kubernetes_sysctls }}"
77
78- name: Check swap status
79 ansible.builtin.command: /sbin/swapon -s
80 changed_when: false
81 register: _swapon
82
83- name: Disable swap
84 ansible.builtin.command: /sbin/swapoff -a
85 ignore_errors: "{{ ansible_check_mode }}"
86 when:
87 - _swapon.stdout
88
89- name: Remove swapfile from /etc/fstab
90 ansible.posix.mount:
91 name: "{{ item }}"
92 fstype: swap
93 state: absent
94 with_items:
95 - swap
96 - none
97
Tadas Sutkaitis4770f552023-02-20 17:41:37 +020098- name: Create noswap systemd service config file
99 ansible.builtin.copy:
100 src: noswap.service
101 dest: /etc/systemd/system/noswap.service
102 owner: root
103 group: root
104 mode: 0644
105 notify: Enable noswap service
106
Mohammed Naser336caf42022-03-11 17:56:45 -0500107- name: Configure short hostname
108 ansible.builtin.hostname:
109 name: "{{ inventory_hostname_short }}"
110
111- name: Ensure hostname inside hosts file
112 ansible.builtin.lineinfile:
113 path: /etc/hosts
114 regexp: '^127\.0\.1\.1'
115 line: 127.0.1.1 {{ inventory_hostname }} {{ inventory_hostname_short }}
116
117- name: Setup control plane
118 when: inventory_hostname in groups[kubernetes_control_plane_group]
119 ansible.builtin.include_tasks: control-plane.yml
120
121- name: Setup nodes
122 when: inventory_hostname not in groups[kubernetes_control_plane_group]
123 ansible.builtin.include_tasks: nodes.yml
124
125- name: Add labels to control plane nodes
126 delegate_to: "{{ groups[kubernetes_control_plane_group][0] }}"
127 kubernetes.core.k8s:
128 state: patched
129 kind: Node
130 name: "{{ inventory_hostname_short }}"
131 definition:
132 metadata:
Mohammed Nasera98799e2022-05-19 21:54:20 -0400133 labels: "{{ kubernetes_control_plane_labels }}"
Mohammed Naser336caf42022-03-11 17:56:45 -0500134 when:
135 - inventory_hostname in groups['controllers']
136
137- name: Add labels to compute nodes
138 delegate_to: "{{ groups[kubernetes_control_plane_group][0] }}"
139 kubernetes.core.k8s:
140 state: patched
141 kind: Node
142 name: "{{ inventory_hostname_short }}"
143 definition:
144 metadata:
Mohammed Nasera98799e2022-05-19 21:54:20 -0400145 labels: "{{ kubernetes_compute_node_labels }}"
Mohammed Naser336caf42022-03-11 17:56:45 -0500146 when:
147 - inventory_hostname in groups['computes']