mgmt/deployment/ansible/playbooks/deploy-nomad-config.yml

65 lines
1.5 KiB
YAML

---
- name: 部署Nomad配置到所有节点
hosts: nomad_cluster
become: yes
tasks:
- name: 检查节点类型
set_fact:
node_type: "{{ 'server' if inventory_hostname in groups['nomad_servers'] else 'client' }}"
- name: 部署Nomad服务器配置文件
template:
src: nomad-server.hcl.j2
dest: /etc/nomad.d/nomad.hcl
backup: yes
owner: root
group: root
mode: '0644'
when: node_type == 'server'
- name: 部署Nomad客户端配置文件
get_url:
url: "https://gitea.tailnet-68f9.ts.net/ben/mgmt/raw/branch/main/nomad-configs/nodes/{{ inventory_hostname }}.hcl"
dest: /etc/nomad.d/nomad.hcl
backup: yes
owner: root
group: root
mode: '0644'
when: node_type == 'client'
- name: 重启Nomad服务
systemd:
name: nomad
state: restarted
enabled: yes
- name: 等待Nomad服务启动
wait_for:
port: 4646
host: "{{ ansible_host }}"
timeout: 30
when: node_type == 'server'
- name: 等待Nomad客户端服务启动
wait_for:
port: 4646
host: "{{ ansible_host }}"
timeout: 30
when: node_type == 'client'
- name: 显示Nomad服务状态
systemd:
name: nomad
register: nomad_status
- name: 显示服务状态
debug:
msg: "{{ inventory_hostname }} ({{ node_type }}) Nomad服务状态: {{ nomad_status.status.ActiveState }}"