From 9e07d971d762742dcfe697f3decffd5e3fef6c3d Mon Sep 17 00:00:00 2001 From: longns1 Date: Fri, 19 Jul 2024 10:14:18 +0700 Subject: [PATCH] add k3s_service_exec_start_pre_vars for the k3s service --- defaults/main.yml | 13 +++++++++++++ templates/k3s.service.j2 | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/defaults/main.yml b/defaults/main.yml index d0766d5..44fbf86 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -107,6 +107,19 @@ k3s_service_env_vars: {} # the target as this role will not populate this file. k3s_service_env_file: false +# Additional ExecStartPre commands for the k3s service in systemd +# This dictionary can be used to specify additional ExecStartPre commands +# for the k3s service. These commands will be executed before the main +# service starts. For example, the command below removes the +# cpu_manager_state file if it exists. +# +# Usage example: +# k3s_service_exec_start_pre_vars: +# - "-/usr/bin/rm -f /var/lib/kubelet/cpu_manager_state" +# +# Note: The "-" prefix before the command ensures that systemd ignores +# any errors that occur when executing the command. +k3s_service_exec_start_pre_vars: {} ## # Server Configuration diff --git a/templates/k3s.service.j2 b/templates/k3s.service.j2 index 040d72f..2b2547c 100644 --- a/templates/k3s.service.j2 +++ b/templates/k3s.service.j2 @@ -29,6 +29,11 @@ EnvironmentFile={{ k3s_service_env_file }} ExecStartPre=/bin/sh -xc '! /usr/bin/systemctl is-enabled --quiet nm-cloud-setup.service' ExecStartPre=-/sbin/modprobe br_netfilter ExecStartPre=-/sbin/modprobe overlay +{% if k3s_service_exec_start_pre_vars is defined and k3s_service_exec_start_pre_vars is iterable %} +{% for exec_start_pre_var in k3s_service_exec_start_pre_vars %} +ExecStartPre={{ exec_start_pre_var }} +{% endfor %} +{% endif %} {% filter regex_replace('\s+', ' ') %} {% filter replace('\n', ' ') %} ExecStart={{ k3s_install_dir }}/k3s