# todo - handle cluster scenarii with openntpd (listen & peers as servers) - name: time sync maintenance routines gather_facts: no hosts: "{{target}}" become: "{{become}}" tasks: - name: define distro vendor ansible.builtin.shell: executable: /bin/bash cmd: "lsb_release -is 2>/dev/null" changed_when: false check_mode: false register: vendor - name: define which ntp package is installed ansible.builtin.script: cmd: scripts/check-ntp-package changed_when: false check_mode: false register: ntp # run for any distro vendor # enable the failure if you consider ntp to be mandatory failed_when: false #- debug: var={{ntp.stdout}} ### ntp - name: setup legacy ntp ansible.builtin.template: src: "templates/ntp.conf.j2" dest: "/etc/ntp.conf" notify: restart ntp diff: true when: ntp.stdout|trim == 'ntp' - name: tune legacy ntp runtime ansible.builtin.copy: src: "templates/default_ntp" dest: "/etc/default/ntp" notify: restart ntp diff: true when: ntp.stdout|trim == 'ntp' ### openntpd - name: setup openntpd on debian/ubuntu ansible.builtin.template: src: "templates/openntpd.conf.j2" dest: "/etc/openntpd/ntpd.conf" notify: restart openntpd diff: true when: > ( ntp.stdout|trim == 'openntpd' or ntp.stdout|trim == '/usr/local/sbin/ntpd' ) and ( vendor.stdout == 'Debian' or vendor.stdout == 'Ubuntu' ) - name: setup openntpd on slackware ansible.builtin.template: src: "templates/openntpd.conf.j2" # todo - that's the path used from source, not necessarily for sbo package and such dest: "/etc/openntpd.conf" notify: restart openntpd diff: true when: > ( ntp.stdout|trim == 'openntpd' or ntp.stdout|trim == '/usr/local/sbin/ntpd' ) and vendor.stdout == 'slackware' - name: tune openntpd runtime on debian/ubuntu ansible.builtin.copy: src: "templates/default_openntpd" dest: "/etc/default/openntpd" notify: restart openntpd diff: true when: ntp.stdout|trim == 'openntpd' # todo - tune openntpd runtime on slackware - name: tune systemd-timesyncd runtime ansible.builtin.template: src: "templates/timesyncd.conf.j2" dest: "/etc/systemd/timesyncd.conf" notify: restart systemd-timesyncd diff: true when: ntp.stdout|trim == 'systemd-timesyncd' handlers: - name: restart ntp ansible.builtin.shell: executable: /bin/bash # todo restart script cmd: "[[ -x /lib/systemd/systemd ]] && systemctl restart ntp.service || /root/RESTART-NTP" - name: restart openntpd ansible.builtin.shell: executable: /bin/bash # todo restart script cmd: "[[ -x /lib/systemd/systemd ]] && systemctl restart openntpd.service || /root/RESTART-OPENNTPD" - name: restart systemd-timesyncd ansible.builtin.shell: executable: /bin/bash cmd: "systemctl restart systemd-timesyncd.service"