- name: Configure DNS and NTP on yndx-client
  hosts: yndx-client.practicumsuperstore.ru
  become: yes
  tasks:
    - name: Stop and disable systemd-resolved
      systemd:
        name: systemd-resolved
        state: stopped
        enabled: no

    - name: Remove existing resolv.conf
      file:
        path: /etc/resolv.conf
        state: absent

    - name: Create new resolv.conf pointing to internal DNS
      copy:
        content: |
          nameserver 10.10.1.200
        dest: /etc/resolv.conf
        owner: root
        group: root
        mode: '0644'

    - name: Install chrony
      apt:
        name: chrony
        state: present
        update_cache: yes

    - name: Configure chrony to use yndx-dns as NTP server
      copy:
        content: |
          server 10.10.1.200 iburst
        dest: /etc/chrony/chrony.conf
        owner: root
        group: root
        mode: '0644'

    - name: Restart chrony
      systemd:
        name: chrony
        state: restarted
        enabled: yes