# platform = multi_platform_all
# reboot = false
# strategy = configure
# complexity = low
# disruption = low
- name: Gather the package facts
  package_facts:
    manager: auto
  tags:
  - DISA-STIG-UBTU-22-252015
  - chronyd_sync_clock
  - configure_strategy
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

- name: Synchronize internal information system clocks
  block:

  - name: Check for duplicate values
    ansible.builtin.lineinfile:
      path: /etc/chrony/chrony.conf
      create: true
      regexp: '(?i)^\s*makestep '
      state: absent
    check_mode: true
    changed_when: false
    register: dupes

  - name: Deduplicate values from /etc/chrony/chrony.conf
    ansible.builtin.lineinfile:
      path: /etc/chrony/chrony.conf
      create: true
      regexp: '(?i)^\s*makestep '
      state: absent
    when: dupes.found is defined and dupes.found > 1

  - name: Insert correct line to /etc/chrony/chrony.conf
    ansible.builtin.lineinfile:
      path: /etc/chrony/chrony.conf
      create: true
      regexp: '(?i)^\s*makestep '
      line: makestep 1 -1
      state: present
  when:
  - '"linux-base" in ansible_facts.packages'
  - '"chrony" in ansible_facts.packages'
  tags:
  - DISA-STIG-UBTU-22-252015
  - chronyd_sync_clock
  - configure_strategy
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed
