blob: cd806b85201e2b33f297abe6ed92ba8085257193 [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:
44 - "containerd"
Mohammed Naserb19a6312023-01-19 02:43:40 +000045 - "cri-tools={{ kubernetes_cri_tools_version }}-00"
Mohammed Naser336caf42022-03-11 17:56:45 -050046 - "kubeadm={{ kubernetes_version }}-00"
47 - "kubectl={{ kubernetes_version }}-00"
48 - "kubelet={{ kubernetes_version }}-00"
49 state: present
50
51- name: Enable kernel modules on-boot
52 ansible.builtin.template:
53 src: modules-load.conf.j2
54 dest: /etc/modules-load.d/k8s.conf
Mohammed Naser511c3fa2022-03-17 17:54:10 -040055 owner: root
56 group: root
57 mode: 0644
Mohammed Naser336caf42022-03-11 17:56:45 -050058
59- name: Enable kernel modules in runtime
60 community.general.modprobe:
61 name: "{{ item }}"
62 state: present
63 loop: "{{ kubernetes_kernel_modules }}"
64
65- name: Configure sysctl values
66 ansible.posix.sysctl:
67 name: "{{ item.name }}"
68 value: "{{ item.value }}"
69 state: present
70 loop: "{{ kubernetes_sysctls }}"
71
72- name: Check swap status
73 ansible.builtin.command: /sbin/swapon -s
74 changed_when: false
75 register: _swapon
76
77- name: Disable swap
78 ansible.builtin.command: /sbin/swapoff -a
79 ignore_errors: "{{ ansible_check_mode }}"
80 when:
81 - _swapon.stdout
82
83- name: Remove swapfile from /etc/fstab
84 ansible.posix.mount:
85 name: "{{ item }}"
86 fstype: swap
87 state: absent
88 with_items:
89 - swap
90 - none
91
92- name: Configure short hostname
93 ansible.builtin.hostname:
94 name: "{{ inventory_hostname_short }}"
95
96- name: Ensure hostname inside hosts file
97 ansible.builtin.lineinfile:
98 path: /etc/hosts
99 regexp: '^127\.0\.1\.1'
100 line: 127.0.1.1 {{ inventory_hostname }} {{ inventory_hostname_short }}
101
102- name: Setup control plane
103 when: inventory_hostname in groups[kubernetes_control_plane_group]
104 ansible.builtin.include_tasks: control-plane.yml
105
106- name: Setup nodes
107 when: inventory_hostname not in groups[kubernetes_control_plane_group]
108 ansible.builtin.include_tasks: nodes.yml
109
110- name: Add labels to control plane nodes
111 delegate_to: "{{ groups[kubernetes_control_plane_group][0] }}"
112 kubernetes.core.k8s:
113 state: patched
114 kind: Node
115 name: "{{ inventory_hostname_short }}"
116 definition:
117 metadata:
Mohammed Nasera98799e2022-05-19 21:54:20 -0400118 labels: "{{ kubernetes_control_plane_labels }}"
Mohammed Naser336caf42022-03-11 17:56:45 -0500119 when:
120 - inventory_hostname in groups['controllers']
121
122- name: Add labels to compute nodes
123 delegate_to: "{{ groups[kubernetes_control_plane_group][0] }}"
124 kubernetes.core.k8s:
125 state: patched
126 kind: Node
127 name: "{{ inventory_hostname_short }}"
128 definition:
129 metadata:
Mohammed Nasera98799e2022-05-19 21:54:20 -0400130 labels: "{{ kubernetes_compute_node_labels }}"
Mohammed Naser336caf42022-03-11 17:56:45 -0500131 when:
132 - inventory_hostname in groups['computes']