---
- name: Restart Tailscale to fix DNS issues
  hosts: hcp1,hcp2
  become: yes
  
  tasks:
    - name: Check current DNS configuration
      shell: cat /etc/resolv.conf
      register: dns_before
      
    - name: Display current DNS config
      debug:
        msg: "Current DNS config: {{ dns_before.stdout_lines }}"
    
    - name: Restart tailscaled service
      systemd:
        name: tailscaled
        state: restarted
        
    - name: Wait for tailscale to stabilize
      wait_for:
        timeout: 10
        
    - name: Check DNS configuration after restart
      shell: cat /etc/resolv.conf
      register: dns_after
      
    - name: Display new DNS config
      debug:
        msg: "New DNS config: {{ dns_after.stdout_lines }}"
        
    - name: Test DNS resolution
      shell: nslookup apt.releases.hashicorp.com
      register: dns_test
      ignore_errors: yes
      
    - name: Display DNS test result
      debug:
        msg: "DNS test result: {{ dns_test.stdout_lines }}"