---

- block:
  - name: Disable chrony
    service:
      name: chrony
      enabled: false
      state: stopped

  - name: Set PTP sync type
    set_fact:
      sync_type: "{{ 'dot1as' if zoox_compute_version is version('3.6', '>=') else '1588v2' }}"

  - name: Configure linuxptp
    copy:
      src: "{{ zoox_compute_version }}/ptp"
      dest: "/etc/default/ptp"
      owner: root
      group: root
      mode: '644'
    notify:
      - "Restart ptp4l"
      - "Restart phc2sys"

  - name: Configure ptp4l
    block:
      - copy:
          src: "{{ zoox_compute_version }}/ptp4l_{{ sync_type }}.conf"
          dest: "/etc/linuxptp/ptp4l.conf"
          owner: root
          group: root
          mode: '644'
        notify:
          - "Restart ptp4l"
      - copy:
          src: "{{ zoox_compute_version }}/ptp4l.init"
          dest: "/etc/init/ptp4l.conf"
          owner: root
          group: root
          mode: '644'
        notify:
          - "Restart ptp4l"
      - service:
          name: "ptp4l"
          enabled: yes

  - name: Configure phc2sys daemon
    block:
      - copy:
          src: "{{ zoox_compute_version }}/phc2sys.init"
          dest: "/etc/init/phc2sys.conf"
          owner: root
          group: root
          mode: '644'
        notify:
          - "Restart phc2sys"
      - copy:
          src: "{{ zoox_compute_version }}/phc2sys_{{ sync_type }}.conf"
          dest: "/etc/linuxptp/phc2sys.conf"
          owner: root
          group: root
          mode: '644'
        notify:
          - "Restart phc2sys"
      - service:
          name: "phc2sys"
          enabled: yes

  when: zoox_compute_version is version("3.6", ">=")
  become: yes
