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