You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
homelab/install_kubetools.yml

71 lines
2.0 KiB

9 months ago
- name: Install Kube tools (Kubeadm, Kubelet, Kubectl) using OS tools
hosts: all
become: yes
become_method: sudo
become_user: root
tasks:
- name: Install apt tools and accesories
package:
name: "{{ item }}"
9 months ago
state: present
with_items:
- "apt-transport-https"
- "ca-certificates"
- "curl"
- "gpg"
9 months ago
- name: Creates keyrings directory
file:
path: /etc/apt/keyrings
state: directory
mode: '755'
- name: Check if keyring exists
stat:
path: /etc/apt/keyrings/kubernetes-apt-keyring.gpg
register: keyring_file
9 months ago
- name: Install certificate
command: "{{ item }} chdir=/tmp"
with_items:
- "curl -o Release.key -fsSL https://pkgs.k8s.io/core:/stable:/{{ K8S_VERSION }}/deb/Release.key"
9 months ago
- "gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg Release.key"
- "rm Release.key"
when: not keyring_file.stat.exists
- name: Check if apt repo exists
stat:
path: /etc/apt/sources.list.d/kubernetes.list
register: apt_repo
9 months ago
- name: Setup APT repo
copy:
dest: /etc/apt/sources.list.d/kubernetes.list
content: "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/{{ K8S_VERSION }}/deb/ /"
when: not apt_repo.stat.exists
9 months ago
- name: Update cache
apt:
update_cache: yes
- name: Setup tools
package:
name: "{{ item }}"
9 months ago
state: present
with_items:
- "kubelet"
- "kubeadm"
- "kubectl"
9 months ago
- name: Hold packages
dpkg_selections:
name: "{{ item }}"
9 months ago
selection: hold
with_items:
- "kubelet"
- "kubeadm"
- name: ensure /etc/default/kubelet exists
file:
path: /etc/default/kubelet
state: file
- name: Set containerd in extraargs
blockinfile:
dest: /etc/default/kubelet
block: "KUBELET_EXTRA_ARGS=\"--container-runtime-endpoint=unix:///run/containerd/containerd.sock\""
9 months ago
- name: Start kubelet
service:
name: kubelet
enabled: true
state: started