REMOVE: 删除不再使用的 Terraform 配置文件
Some checks failed
Deploy Nomad Configurations / deploy-nomad (push) Failing after 7m45s
Infrastructure CI/CD / Validate Infrastructure (push) Failing after 2m33s
Infrastructure CI/CD / Plan Infrastructure (push) Has been skipped
Infrastructure CI/CD / Apply Infrastructure (push) Has been skipped
Simple Test / test (push) Failing after 2m48s

- 移除 nomad-terraform.tf 和 test_opentofu_consul.tf 文件
- 更新 Ansible inventory,注释掉不存在的节点 hcp2
- 修改 inventory.ini,确保节点配置的准确性
- 在 nomad-config 模块中添加 null_provider 以支持新配置
- 更新 influxdb1.hcl,添加 Grafana 和 Prometheus 数据卷配置
This commit is contained in:
2025-10-10 13:53:41 +00:00
parent 45f93cc68c
commit eff8d3ec6d
50 changed files with 3683 additions and 239 deletions

View File

@@ -4,48 +4,60 @@ terraform {
source = "hashicorp/nomad"
version = "~> 2.0"
}
}
}
# Nomad 节点配置资源
resource "nomad_node_pool" "default" {
name = "default"
description = "Default node pool for all nodes"
}
# 定义需要修复的节点
locals {
nomad_nodes = {
ch4 = {
address = "ch4.tailnet-68f9.ts.net"
datacenter = "dc1"
node_class = ""
}
hcp1 = {
address = "hcp1.tailnet-68f9.ts.net"
datacenter = "dc1"
node_class = ""
}
warden = {
address = "warden.tailnet-68f9.ts.net"
datacenter = "dc1"
node_class = ""
}
ash1d = {
address = "ash1d.tailnet-68f9.ts.net"
datacenter = "dc1"
node_class = ""
}
ash2e = {
address = "ash2e.tailnet-68f9.ts.net"
datacenter = "dc1"
node_class = ""
null = {
source = "hashicorp/null"
version = "~> 3.0"
}
}
}
# 输出节点信息
output "nomad_nodes" {
value = local.nomad_nodes
description = "Nomad 节点配置信息"
# 测试 onecloud1 服务器配置
resource "null_resource" "deploy_onecloud1_config" {
provisioner "file" {
source = "${path.root}/../../nomad-configs-tofu/onecloud1-server.hcl"
destination = "/tmp/nomad.hcl"
connection {
type = "ssh"
user = "ben"
password = "3131"
host = "onecloud1.tailnet-68f9.ts.net"
timeout = "30s"
}
}
provisioner "remote-exec" {
inline = [
"echo '开始部署 onecloud1 服务器配置'",
"sudo systemctl stop nomad || true",
"sudo mkdir -p /etc/nomad.d",
"sudo cp /tmp/nomad.hcl /etc/nomad.d/nomad.hcl",
"sudo chown nomad:nomad /etc/nomad.d/nomad.hcl",
"sudo systemctl start nomad",
"sudo systemctl enable nomad",
"sleep 15",
"sudo systemctl status nomad --no-pager",
"echo 'onecloud1 服务器配置部署完成'"
]
connection {
type = "ssh"
user = "ben"
password = "3131"
host = "onecloud1.tailnet-68f9.ts.net"
timeout = "30s"
}
}
# 触发器:配置文件变化时重新部署
triggers = {
config_hash = filemd5("${path.root}/../../nomad-configs-tofu/onecloud1-server.hcl")
}
}
# 输出部署状态
output "onecloud1_deployment" {
value = "onecloud1 服务器配置已部署"
description = "onecloud1 节点部署状态"
}

View File

@@ -0,0 +1,44 @@
job "fix-nomad-nodes-v2" {
datacenters = ["dc1"]
type = "batch"
group "node-config" {
count = 1
task "fix-nodes" {
driver = "raw_exec"
config {
command = "/bin/bash"
args = ["-c", <<EOF
echo "开始修复 Nomad 节点配置..."
# 定义需要修复的节点
NODES="ch4 hcp1 warden ash1d"
for node in $NODES; do
echo "修复节点: $node"
# 通过 SSH 重启 Nomad 服务
ssh -o StrictHostKeyChecking=no ben@$node.tailnet-68f9.ts.net "
echo '3131' | sudo -S systemctl restart nomad
echo '3131' | sudo -S systemctl enable nomad
sleep 5
systemctl status nomad --no-pager
" || echo "节点 $node 修复失败"
sleep 2
done
echo "节点修复完成"
EOF
]
}
resources {
cpu = 100
memory = 128
}
}
}
}

View File

@@ -0,0 +1,27 @@
terraform {
required_providers {
nomad = {
source = "hashicorp/nomad"
version = "~> 2.0"
}
}
}
# Nomad Provider 配置
provider "nomad" {
address = "http://semaphore.tailnet-68f9.ts.net:4646"
region = "global"
}
# 使用 Nomad 配置模块
module "nomad_config" {
source = "./modules/nomad-config"
nomad_address = "http://semaphore.tailnet-68f9.ts.net:4646"
datacenter = "dc1"
}
# 输出模块信息
output "nomad_nodes_info" {
value = module.nomad_config.onecloud1_deployment
}