---
- name: Install k8s Prerequisites
  apt:
    pkg:
    - libraspberrypi-bin
    - apt-transport-https
    - curl
    - ca-certificates

- name: google key
  ansible.builtin.apt_key:
    url: https://packages.cloud.google.com/apt/doc/apt-key.gpg
    state: present

- name: Install google key for k8s
  get_url:
    url: https://packages.cloud.google.com/apt/doc/apt-key.gpg
    dest: /usr/share/keyrings/kubernetes-archive-keyring.gpg
    mode: 0644

- name: devel:kubic:libcontainers:stable.list
  ansible.builtin.apt_repository:
    repo: "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main"
    #repo: "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-yakkety main"
    #repo: "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-hirsute main"
    state: present
    filename: kubernetes

- name: Install k8s
  apt:
    pkg:
      - kubelet
      - kubeadm
      - kubectl

- name: Hold kubelet to prevent inadvertent updates
  dpkg_selections:
    name: kubelet
    selection: hold

- name: Hold kubeadm to prevent inadvertent updates
  dpkg_selections:
    name: kubeadm
    selection: hold

- name: Hold kubectl to prevent inadvertent updates
  dpkg_selections:
    name: kubectl
    selection: hold

- name: Enable cri-o service
  ansible.builtin.service:
    name: crio
    enabled: yes
    state: started
