---
- name: Configure NTP with default 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 provider packages
      check_mode: false
      tags: tests::setup
      block:
        - name: Remove NTP providers
          package:
            name: "{{ item }}"
            state: absent
          with_items:
            - chrony
            - ntp

  post_tasks:
    - name: Verify provider is working
      tags: tests::verify
      block:
        - name: Wait for services to start
          wait_for:
            timeout: 2

        - name: Get list of currently used time sources
          shell: chronyc -n sources || ntpq -pn
          register: sources
          changed_when: false

        - name: Check time sources
          assert:
            that:
              - "'172.16.123.1' in sources.stdout"
