SWITCH: 从 Ansible 切换到 Terraform 管理 Nomad 配置
Infrastructure CI/CD / Validate Infrastructure (push) Failing after 19s Details
Infrastructure CI/CD / Plan Infrastructure (push) Has been skipped Details
Infrastructure CI/CD / Apply Infrastructure (push) Has been skipped Details
Simple Test / test (push) Successful in 5s Details

- 创建 nomad-config Terraform 模块
- 声明式管理 Nomad 节点配置
- 更新 GitOps 工作流使用 Terraform
- 避免配置漂移,确保主客观统一
- 目标: 通过 IaC 修复 5个异常节点
This commit is contained in:
Houzhong Xu 2025-10-09 13:15:57 +00:00
parent ea85f807d0
commit 45f93cc68c
No known key found for this signature in database
GPG Key ID: B44BEB1438F1B46F
4 changed files with 109 additions and 4 deletions

View File

@ -21,11 +21,17 @@ jobs:
sudo apt update sudo apt update
sudo apt install -y ansible sudo apt install -y ansible
- name: Deploy Nomad Configurations - name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: "1.5.0"
- name: Deploy Nomad Configurations with Terraform
run: | run: |
echo "修复 Nomad 节点配置..." echo "使用 Terraform 管理 Nomad 配置..."
cd ansible terraform init
ansible-playbook -i inventory/hosts.yml fix-nomad-nodes.yml --limit "ch4,hcp1,warden,ash1d" -v terraform plan -out=tfplan
terraform apply -auto-approve tfplan
- name: Verify Deployment - name: Verify Deployment
run: | run: |

View File

@ -0,0 +1,51 @@
terraform {
required_providers {
nomad = {
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 = ""
}
}
}
#
output "nomad_nodes" {
value = local.nomad_nodes
description = "Nomad 节点配置信息"
}

View File

@ -0,0 +1,21 @@
variable "nomad_address" {
description = "Nomad 集群地址"
type = string
default = "http://semaphore.tailnet-68f9.ts.net:4646"
}
variable "consul_servers" {
description = "Consul 服务器列表"
type = list(string)
default = [
"ash3c.tailnet-68f9.ts.net:8500",
"ch4.tailnet-68f9.ts.net:8500",
"warden.tailnet-68f9.ts.net:8500"
]
}
variable "datacenter" {
description = "Nomad 数据中心"
type = string
default = "dc1"
}

27
nomad-terraform.tf Normal file
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 = "./infrastructure/opentofu/modules/nomad-config"
nomad_address = "http://semaphore.tailnet-68f9.ts.net:4646"
datacenter = "dc1"
}
#
output "nomad_nodes_info" {
value = module.nomad_config.nomad_nodes
}