Решение ошибки mkdir -p
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# K3s Server Configuration
|
||||
server_ip = "reg.benadis.org" # Replace with your server IP
|
||||
worker_ips = [ # Replace with your worker IPs
|
||||
"worker1.benadis.org",
|
||||
# "worker1.benadis.org",
|
||||
"worker2.benadis.org"
|
||||
]
|
||||
ssh_user = "root" # Replace with your SSH username
|
||||
@@ -10,7 +10,7 @@ replace_url = "reg.benadis.org" # Optional: URL to replace in kubeconfig, le
|
||||
|
||||
# Cluster Configuration
|
||||
domain = "reg.benadis.org" # Your domain name
|
||||
k3s_version = "latest" # K3s version to install
|
||||
k3s_version = "v1.32.3+k3s1" # K3s version to install
|
||||
k3s_channel = "stable" # K3s release channel
|
||||
kubeconfig_path = "./k3s.yaml" # Where to save kubeconfig
|
||||
node_token_path = "./tmp/node-token" # Where to save node token
|
||||
|
||||
@@ -35,7 +35,7 @@ variable "domain" {
|
||||
variable "k3s_version" {
|
||||
description = "Version of K3s to install"
|
||||
type = string
|
||||
default = "v1.27.3+k3s1"
|
||||
default = "v1.32.3+k3s1"
|
||||
}
|
||||
|
||||
variable "k3s_channel" {
|
||||
@@ -47,7 +47,7 @@ variable "k3s_channel" {
|
||||
variable "kubeconfig_path" {
|
||||
description = "Path where to save the kubeconfig file locally"
|
||||
type = string
|
||||
default = "~/.kube/config"
|
||||
default = "./k3s.yaml"
|
||||
}
|
||||
|
||||
variable "node_token_path" {
|
||||
|
||||
@@ -13,8 +13,8 @@ terraform {
|
||||
}
|
||||
|
||||
locals {
|
||||
ssh_config_path = "${path.module}/ssh_config"
|
||||
temporary_dir = "/tmp/k3s-terraform"
|
||||
temporary_dir = "/tmp"
|
||||
ssh_config_path = "${local.temporary_dir}/ssh_config"
|
||||
server_kubeconfig = "${local.temporary_dir}/k3s.yaml"
|
||||
node_token_path = "${local.temporary_dir}/node-token"
|
||||
worker_count = length(var.worker_ips)
|
||||
@@ -32,7 +32,16 @@ resource "null_resource" "setup_ssh_config" {
|
||||
|
||||
provisioner "local-exec" {
|
||||
command = <<-EOT
|
||||
mkdir -p ${dirname(local.ssh_config_path)}
|
||||
# Check if directory exists, create only if it doesn't
|
||||
SSH_CONFIG_DIR=$(dirname "${local.ssh_config_path}")
|
||||
if [ ! -d "$SSH_CONFIG_DIR" ]; then
|
||||
echo "Creating directory $SSH_CONFIG_DIR"
|
||||
mkdir -p "$SSH_CONFIG_DIR"
|
||||
else
|
||||
echo "Directory $SSH_CONFIG_DIR already exists"
|
||||
fi
|
||||
|
||||
# Create SSH config file
|
||||
cat > ${local.ssh_config_path} << 'EOF'
|
||||
Host ${var.server_ip}
|
||||
User ${var.ssh_user}
|
||||
@@ -87,7 +96,7 @@ resource "null_resource" "install_k3s_server" {
|
||||
}
|
||||
|
||||
inline = [
|
||||
"mkdir -p ${local.temporary_dir}",
|
||||
"if [ ! -d \"${local.temporary_dir}\" ]; then mkdir -p ${local.temporary_dir}; else echo \"Directory ${local.temporary_dir} already exists\"; fi",
|
||||
"curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=${var.k3s_version} INSTALL_K3S_CHANNEL=${var.k3s_channel} sh -s - server ${var.k3s_extra_server_args}",
|
||||
"until systemctl is-active --quiet k3s; do echo 'Waiting for k3s to start...'; sleep 5; done",
|
||||
"echo 'K3s server installation complete'"
|
||||
@@ -133,7 +142,8 @@ resource "null_resource" "get_k3s_config" {
|
||||
}
|
||||
|
||||
inline = [
|
||||
"mkdir -p ${local.temporary_dir}",
|
||||
"if [ ! -d \"${local.temporary_dir}\" ]; then mkdir -p ${local.temporary_dir}; else echo \"Directory ${local.temporary_dir} already exists\"; fi",
|
||||
"if [ ! -d \"$(dirname ${local.server_kubeconfig})\" ]; then mkdir -p $(dirname ${local.server_kubeconfig}); else echo \"Directory $(dirname ${local.server_kubeconfig}) already exists\"; fi",
|
||||
"sudo cp /etc/rancher/k3s/k3s.yaml ${local.server_kubeconfig}",
|
||||
"sudo chmod 644 ${local.server_kubeconfig}"
|
||||
]
|
||||
@@ -141,7 +151,20 @@ resource "null_resource" "get_k3s_config" {
|
||||
|
||||
# Download kubeconfig to local machine
|
||||
provisioner "local-exec" {
|
||||
command = "mkdir -p ${dirname(var.kubeconfig_path)} && scp -F ${local.ssh_config_path} ${var.ssh_user}@${var.server_ip}:${local.server_kubeconfig} ${var.kubeconfig_path}"
|
||||
command = <<-EOT
|
||||
# Check if directory exists, create only if it doesn't
|
||||
KUBECONFIG_DIR=$(dirname "${var.kubeconfig_path}")
|
||||
if [ ! -d "$KUBECONFIG_DIR" ]; then
|
||||
echo "Creating directory $KUBECONFIG_DIR"
|
||||
mkdir -p "$KUBECONFIG_DIR"
|
||||
else
|
||||
echo "Directory $KUBECONFIG_DIR already exists"
|
||||
fi
|
||||
|
||||
# Copy the kubeconfig file
|
||||
scp -F ${local.ssh_config_path} ${var.ssh_user}@${var.server_ip}:${local.server_kubeconfig} ${var.kubeconfig_path}
|
||||
EOT
|
||||
interpreter = ["bash", "-c"]
|
||||
}
|
||||
|
||||
# Update server URL in kubeconfig if needed
|
||||
@@ -177,7 +200,7 @@ resource "null_resource" "get_k3s_token" {
|
||||
}
|
||||
|
||||
inline = [
|
||||
"mkdir -p ${local.temporary_dir}",
|
||||
"if [ ! -d \"$(dirname ${local.node_token_path})\" ]; then mkdir -p $(dirname ${local.node_token_path}); else echo \"Directory $(dirname ${local.node_token_path}) already exists\"; fi",
|
||||
"sudo cat /var/lib/rancher/k3s/server/node-token > ${local.node_token_path}",
|
||||
"sudo chmod 644 ${local.node_token_path}"
|
||||
]
|
||||
@@ -185,7 +208,20 @@ resource "null_resource" "get_k3s_token" {
|
||||
|
||||
# Download node token to local machine
|
||||
provisioner "local-exec" {
|
||||
command = "mkdir -p ${dirname(var.node_token_path)} && scp -F ${local.ssh_config_path} ${var.ssh_user}@${var.server_ip}:${local.node_token_path} ${var.node_token_path}"
|
||||
command = <<-EOT
|
||||
# Check if directory exists, create only if it doesn't
|
||||
TOKEN_DIR=$(dirname "${var.node_token_path}")
|
||||
if [ ! -d "$TOKEN_DIR" ]; then
|
||||
echo "Creating directory $TOKEN_DIR"
|
||||
mkdir -p "$TOKEN_DIR"
|
||||
else
|
||||
echo "Directory $TOKEN_DIR already exists"
|
||||
fi
|
||||
|
||||
# Copy the node token file
|
||||
scp -F ${local.ssh_config_path} ${var.ssh_user}@${var.server_ip}:${local.node_token_path} ${var.node_token_path}
|
||||
EOT
|
||||
interpreter = ["bash", "-c"]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,7 +248,7 @@ resource "null_resource" "copy_token_to_workers" {
|
||||
}
|
||||
|
||||
inline = [
|
||||
"mkdir -p ${local.temporary_dir}"
|
||||
"if [ ! -d \"${local.temporary_dir}\" ]; then mkdir -p ${local.temporary_dir}; fi"
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user