From ef43cde91660f6a7e84569a14960af5951bbc0bb Mon Sep 17 00:00:00 2001 From: Urs Rudolph Date: Sun, 8 Mar 2026 11:50:43 +0100 Subject: [PATCH] Fixed Errors from wrong version --- group_vars/all.yml | 4 +-- roles/common/tasks/main.yml | 63 +++++++++++++++++++++++++++++++------ roles/master/tasks/main.yml | 3 ++ 3 files changed, 59 insertions(+), 11 deletions(-) diff --git a/group_vars/all.yml b/group_vars/all.yml index 3408ef3..c24b741 100644 --- a/group_vars/all.yml +++ b/group_vars/all.yml @@ -4,8 +4,8 @@ ansible_user: mastermito # ansible-vault encrypt_string 'your_password' --name 'vault_ssh_password' # then put the result here. # For now, we expect these variables to be defined, e.g. in a vault file or extra vars. -# ansible_password: "{{ vault_ssh_password }}" -# ansible_become_password: "{{ vault_become_password }}" +ansible_password: "{{ vault_ssh_password }}" +ansible_become_password: "{{ vault_ssh_password }}" # Kubernetes Version k8s_version: "1.28.0-00" diff --git a/roles/common/tasks/main.yml b/roles/common/tasks/main.yml index d93dfbf..e6f4403 100644 --- a/roles/common/tasks/main.yml +++ b/roles/common/tasks/main.yml @@ -1,4 +1,13 @@ --- +- name: Wait for APT lock + shell: | + while fuser /var/lib/dpkg/lock-frontend >/dev/null 2>&1; do + echo "Waiting for other software managers to finish..." + sleep 5 + done + register: apt_lock_wait + changed_when: false + - name: Update apt cache apt: update_cache: yes @@ -8,6 +17,26 @@ apt: upgrade: dist +- name: Check if cloud-init exists + stat: + path: /etc/cloud/cloud.cfg + register: cloud_init_cfg + +- name: Prevent cloud-init from changing hostname + copy: + dest: /etc/cloud/cloud.cfg.d/99-preserve-hostname.cfg + content: "preserve_hostname: true" + when: cloud_init_cfg.stat.exists + +- name: Set hostname + command: "hostnamectl set-hostname {{ inventory_hostname }}" + +- name: Update /etc/hosts with inventory hostname + lineinfile: + path: /etc/hosts + regexp: '^127\.0\.1\.1' + line: "127.0.1.1 {{ inventory_hostname }}" + - name: Install required system packages apt: name: @@ -22,16 +51,32 @@ command: swapoff -a when: ansible_swaptotal_mb > 0 -- name: Disable swap in dphys-swapfile - lineinfile: - path: /etc/dphys-swapfile - regexp: '^CONF_SWAPSIZE=' - line: 'CONF_SWAPSIZE=0' - notify: restart kubelet +- name: Disable swap in /etc/fstab + replace: + path: /etc/fstab + regexp: '^([^#].*?\sswap\s+.*)$' + replace: '# \1' + +- name: Stop and disable dphys-swapfile service (if exists) + service: + name: dphys-swapfile + state: stopped + enabled: no + failed_when: false + when: ansible_distribution == 'Raspbian' + +- name: Determine cmdline.txt location + stat: + path: /boot/firmware/cmdline.txt + register: cmdline_firmware + +- name: Set cmdline path + set_fact: + cmdline_path: "{{ '/boot/firmware/cmdline.txt' if cmdline_firmware.stat.exists else '/boot/cmdline.txt' }}" - name: Enable cgroup features in cmdline.txt replace: - path: /boot/cmdline.txt + path: "{{ cmdline_path }}" regexp: '^((?!.*\bcgroup_enable=cpuset cgroup_enable=memory cgroup_memory=1\b).*)$' replace: '\1 cgroup_enable=cpuset cgroup_enable=memory cgroup_memory=1' register: cgroup_update @@ -100,13 +145,13 @@ - name: Download Kubernetes GPG key get_url: - url: https://pkgs.k8s.io/core:/stable:/v1.35/deb/Release.key + url: "https://pkgs.k8s.io/core:/stable:/v{{ k8s_version | regex_search('^[0-9]+\\.[0-9]+') }}/deb/Release.key" dest: /etc/apt/keyrings/kubernetes-apt-keyring.asc mode: '0644' - name: Add Kubernetes apt repository apt_repository: - repo: "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.asc] https://pkgs.k8s.io/core:/stable:/v1.35/deb/ /" + repo: "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.asc] https://pkgs.k8s.io/core:/stable:/v{{ k8s_version | regex_search('^[0-9]+\\.[0-9]+') }}/deb/ /" state: present filename: kubernetes diff --git a/roles/master/tasks/main.yml b/roles/master/tasks/main.yml index bc75027..ffce079 100644 --- a/roles/master/tasks/main.yml +++ b/roles/master/tasks/main.yml @@ -1,4 +1,7 @@ --- +- name: Pre-pull Kubernetes images + command: kubeadm config images pull + - name: Initialize Kubernetes Control Plane command: kubeadm init --pod-network-cidr=10.244.0.0/16 args: