Consolidated variables in the .env.example and added the worker to a customizable list

This commit is contained in:
2025-07-05 13:22:00 +02:00
parent 6e99cd64f9
commit f6c138c46e
6 changed files with 95 additions and 103 deletions

View File

@ -3,100 +3,96 @@
become: true
tasks:
- name: Ensure apt cache is updated
apt:
update_cache: yes
cache_valid_time: 3600
- 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
apt:
ansible.builtin.apt:
name:
- apt-transport-https
- ca-certificates
- curl
- gpg
- containerd
- 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
## ed scriverlo nella directory apposita, altrimenti usa un suo default che non va bene.
- name: Ensure containerd config directory exists
file:
- name: Ensure containerd config directory exists.
ansible.builtin.file:
path: /etc/containerd
state: directory
mode: '0755'
- name: Generate default containerd config if missing
command: containerd config default
register: containerd_config
when: not lookup('file', '/etc/containerd/config.toml', errors='ignore')
changed_when: false
- name: Get defaults from containerd.
ansible.builtin.command: containerd config default
register: containerd_config_default
- name: Write default containerd config
copy:
content: "{{ containerd_config.stdout }}"
- name: Create config file
ansible.builtin.copy:
content: "{{ containerd_config_default.stdout }}"
dest: /etc/containerd/config.toml
when: containerd_config is defined
- name: Set SystemdCgroup = true in containerd config
replace:
- name: Set SystemdCgroup to true
ansible.builtin.replace:
path: /etc/containerd/config.toml
regexp: '^(\s*SystemdCgroup\s*=\s*)false'
replace: '\1true'
regexp: '^(\s*)SystemdCgroup\s*=\s*false'
replace: '\1SystemdCgroup = true'
- name: Restart containerd
systemd:
ansible.builtin.service:
name: containerd
state: restarted
enabled: yes
enabled: true
## Importantissimo per la gestione interna della network
- name: Enable IPv4 forwarding at runtime
sysctl:
ansible.posix.sysctl:
name: net.ipv4.ip_forward
value: '1'
state: present
reload: yes
reload: true
sysctl_set: yes
## Installa kubectl, kubeadm e kubelet dal repo ufficiale kubernetes
- name: Create /etc/apt/keyrings directory
file:
path: /etc/apt/keyrings
state: directory
mode: '0755'
- name: Add Kubernetes signing key
ansible.builtin.apt_key:
url: https://pkgs.k8s.io/core:/stable:/v1.33/deb/Release.key
state: present
- name: Download and save the Kubernetes APT key
ansible.builtin.shell: |
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.33/deb/Release.key | gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
args:
creates: /etc/apt/keyrings/kubernetes-apt-keyring.gpg
- name: Add Kubernetes APT repository
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:/v1.33/deb/ /
- name: Update apt cache after adding Kubernetes repo
apt:
update_cache: yes
- 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
apt:
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.shell: apt-mark hold kubelet kubeadm kubectl
ansible.builtin.dpkg_selections:
name: "{{ item }}"
selection: hold
loop:
- kubelet
- kubeadm
- kubectl
## Abilita il servizio di kubelet