---
- name: 直接复制正确的 HashiCorp APT 源配置
  hosts: nomad_cluster
  become: yes
  
  tasks:
    - name: 备份现有的 HashiCorp APT 源配置（如果存在）
      copy:
        src: "/etc/apt/sources.list.d/hashicorp.list"
        dest: "/etc/apt/sources.list.d/hashicorp.list.backup-{{ ansible_date_time.epoch }}"
        remote_src: yes
      ignore_errors: yes
      
    - name: 创建正确的 HashiCorp APT 源配置
      copy:
        content: "deb [trusted=yes] http://apt.releases.hashicorp.com bookworm main\n"
        dest: "/etc/apt/sources.list.d/hashicorp.list"
        owner: root
        group: root
        mode: '0644'
        
    - name: 更新 APT 缓存
      apt:
        update_cache: yes
      ignore_errors: yes
      
    - name: 验证配置
      command: cat /etc/apt/sources.list.d/hashicorp.list
      register: config_check
      changed_when: false
      
    - name: 显示配置内容
      debug:
        msg: "HashiCorp APT 源配置: {{ config_check.stdout }}"