---
- name: 启动所有Nomad服务器形成集群
  hosts: nomad_servers
  become: yes
  
  tasks:
    - name: 检查Nomad服务状态
      systemd:
        name: nomad
      register: nomad_status
    
    - name: 启动Nomad服务（如果未运行）
      systemd:
        name: nomad
        state: started
        enabled: yes
      when: nomad_status.status.ActiveState != "active"
    
    - name: 等待Nomad服务启动
      wait_for:
        port: 4646
        host: "{{ ansible_host }}"
        timeout: 30
    
    - name: 显示Nomad服务状态
      debug:
        msg: "{{ inventory_hostname }} Nomad服务状态: {{ nomad_status.status.ActiveState }}"






