# 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 {{vendor.stdout}} 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}} - name: setup legacy ntp ansible.builtin.template: src: "templates/ntp.conf.j2" dest: "/etc/ntp.conf" mode: 0600 notify: restart ntp diff: true #no_log: true when: ntp.stdout|trim == 'ntp' - name: tune legacy ntp runtime ansible.builtin.copy: src: "templates/default_ntp" dest: "/etc/default/ntp" mode: 0600 notify: restart ntp diff: true #no_log: true when: ntp.stdout|trim == 'ntp' - name: setup openntpd on debian/ubuntu ansible.builtin.template: src: "templates/openntpd.conf.j2" dest: "/etc/openntpd/ntpd.conf" mode: 0600 notify: restart openntpd diff: true #no_log: 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" dest: "/etc/openntpd.conf" mode: 0600 notify: restart openntpd diff: true #no_log: true when: > ( ntp.stdout|trim == 'openntpd' or ntp.stdout|trim == '/usr/local/sbin/ntpd' ) and vendor.stdout == 'slackware' - name: tune openntpd runtime for debian/ubuntu systems ansible.builtin.copy: src: "templates/default_openntpd" dest: "/etc/default/openntpd" mode: 0600 notify: restart openntpd diff: true #no_log: true when: ntp.stdout|trim == 'openntpd' 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"