- name: Install Kubernetes packages hosts: all become: true tasks: - name: Add Docker signing key ansible.builtin.apt_key: url: https://download.docker.com/linux/ubuntu/gpg state: present - name: Add Docker repository ansible.builtin.apt_repository: repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu noble stable state: present - name: Install required packages ansible.builtin.apt: name: - apt-transport-https - ca-certificates - curl - gpg - containerd.io state: present update_cache: yes ## Questo non รจ nella documentazione! bisogna generare il file di configurazione di containerd ## ed scriverlo nella directory apposita, altrimenti usa un suo default che non va bene. - name: Ensure containerd config directory exists. ansible.builtin.file: path: /etc/containerd state: directory - name: Get defaults from containerd. ansible.builtin.command: containerd config default register: containerd_config_default - name: Create config file ansible.builtin.copy: content: "{{ containerd_config_default.stdout }}" dest: /etc/containerd/config.toml - name: Set SystemdCgroup to true ansible.builtin.replace: path: /etc/containerd/config.toml regexp: '^(\s*)SystemdCgroup\s*=\s*false' replace: '\1SystemdCgroup = true' - name: Restart containerd ansible.builtin.service: name: containerd state: restarted enabled: true ## Importantissimo per la gestione interna della network - name: Enable IPv4 forwarding at runtime ansible.posix.sysctl: name: net.ipv4.ip_forward value: '1' reload: true sysctl_set: yes ## Installa kubectl, kubeadm e kubelet dal repo ufficiale kubernetes - name: Add Kubernetes signing key ansible.builtin.apt_key: url: https://pkgs.k8s.io/core:/stable:/v1.33/deb/Release.key state: present - name: Add Kubernetes repository ansible.builtin.apt_repository: repo: deb [arch=amd64] https://pkgs.k8s.io/core:/stable:/v1.33/deb/ / state: present - name: Install Kubernetes components ansible.builtin.apt: name: - kubelet - kubeadm - kubectl state: present update_cache: true ## Ferma i pacchetti ad una specifica versione - name: Hold Kubernetes packages ansible.builtin.dpkg_selections: name: "{{ item }}" selection: hold loop: - kubelet - kubeadm - kubectl ## Abilita il servizio di kubelet - name: Enable and start kubelet systemd: name: kubelet enabled: true state: started