---
- name: Configure NTP with chrony as current provider
  hosts: all
  vars:
    timesync_ntp_servers:
      - hostname: 172.16.123.1
  roles:
    - linux-system-roles.timesync

  pre_tasks:
    - name: Common test setup tasks
      include_tasks: tasks/setup.yml
      vars:
        __timesync_ostree_unsupported: true

    - name: Remove the install ntp
      check_mode: false
      tags: tests::setup
      block:
        - name: Remove ntp
          package:
            name: ntp
            state: absent

        - name: Install chrony
          package:
            name: chrony
            state: present
          register: package_install
          ignore_errors: true  # noqa ignore-errors

        - name: Skip test if no package
          meta: end_play
          when: package_install.failed

        - name: Enable chronyd
          service:
            name: chronyd
            state: started
            enabled: true

  post_tasks:
    - name: Verify chronyd running
      tags: tests::verify
      block:
        - name: Wait for services to start
          wait_for:
            timeout: 2

        - name: Check chronyd service
          command: chronyc -n tracking
          changed_when: false
