57 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			YAML
		
	
	
	
			
		
		
	
	
			57 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			YAML
		
	
	
	
---
 | 
						||
- name: 更新Nomad服务器配置,添加hcp1作为peer
 | 
						||
  hosts: nomad_servers
 | 
						||
  become: yes
 | 
						||
  vars:
 | 
						||
    hcp1_ip: "100.97.62.111"
 | 
						||
    bootstrap_expect: 8
 | 
						||
  
 | 
						||
  tasks:
 | 
						||
    - name: 备份原配置文件
 | 
						||
      copy:
 | 
						||
        src: /etc/nomad.d/nomad.hcl
 | 
						||
        dest: /etc/nomad.d/nomad.hcl.bak
 | 
						||
        remote_src: yes
 | 
						||
        backup: yes
 | 
						||
    
 | 
						||
    - name: 添加hcp1到retry_join列表
 | 
						||
      lineinfile:
 | 
						||
        path: /etc/nomad.d/nomad.hcl
 | 
						||
        regexp: '^  retry_join = \['
 | 
						||
        line: '  retry_join = ["{{ hcp1_ip }}",'
 | 
						||
        backup: yes
 | 
						||
    
 | 
						||
    - name: 更新bootstrap_expect为8
 | 
						||
      lineinfile:
 | 
						||
        path: /etc/nomad.d/nomad.hcl
 | 
						||
        regexp: '^  bootstrap_expect = \d+'
 | 
						||
        line: '  bootstrap_expect = {{ bootstrap_expect }}'
 | 
						||
        backup: yes
 | 
						||
    
 | 
						||
    - name: 重启Nomad服务
 | 
						||
      systemd:
 | 
						||
        name: nomad
 | 
						||
        state: restarted
 | 
						||
        enabled: yes
 | 
						||
    
 | 
						||
    - name: 等待Nomad服务启动
 | 
						||
      wait_for:
 | 
						||
        port: 4646
 | 
						||
        host: "{{ ansible_host }}"
 | 
						||
        timeout: 30
 | 
						||
    
 | 
						||
    - name: 检查Nomad服务状态
 | 
						||
      systemd:
 | 
						||
        name: nomad
 | 
						||
      register: nomad_status
 | 
						||
    
 | 
						||
    - name: 显示Nomad服务状态
 | 
						||
      debug:
 | 
						||
        msg: "Nomad服务状态: {{ nomad_status.status.ActiveState }}"
 | 
						||
 | 
						||
 | 
						||
 | 
						||
 | 
						||
 | 
						||
 |