Merge ntp_debian.yml and ntp_rpm.yml into one (the new file is called
setup_ntp.yml) since they are almost identical.
Since this is as a "as it is" backport for the original commit, it also
adds the feature of supporting multiple NTP daemons (namely, chronyd &
timesyncd). This is to maintain consistency across all branches
since the backport for stable-3.2 was auto-merged by mergify despite
of conflicts.
Signed-off-by: Rishabh Dave <ridave@redhat.com>
(cherry picked from commit
b03ab607422eda0094d74223d52024a373b7ee9a)
# Hard code this so we will skip the entire file instead of individual tasks (Default isn't Consistent)
static: False
-- name: include ntp debian setup tasks
- include: "misc/ntp_debian.yml"
- when:
- - ansible_os_family == 'Debian'
- - ntp_service_enabled
+- name: include ntp setup tasks
+ include: misc/setup_ntp.yml
+ when: ntp_service_enabled
+ tags: configure_ntp
# Hard code this so we will skip the entire file instead of individual tasks (Default isn't Consistent)
static: False
-- name: include ntp rpm setup tasks
- include: "misc/ntp_rpm.yml"
- when:
- - ansible_os_family in ['RedHat', 'Suse']
- - ntp_service_enabled
- # Hard code this so we will skip the entire file instead of individual tasks (Default isn't Consistent)
- static: False
- name: get ceph version
command: ceph --version
+++ /dev/null
----
-- name: setup ntpd
- block:
- - command: timedatectl set-ntp no
- - package:
- name: ntp
- state: present
- - service:
- name: ntp
- enabled: yes
- state: started
- when: ntp_daemon_type == "ntpd"
-
-- name: setup chrony
- block:
- - command: timedatectl set-ntp no
- - package:
- name: chrony
- state: present
- - service:
- name: chronyd
- enabled: yes
- state: started
- when: ntp_daemon_type == "chronyd"
-
-- name: setup timesyncd
- block:
- - command: timedatectl set-ntp on
- when: ntp_daemon_type == "timesyncd"
+++ /dev/null
----
-- name: setup ntpd
- block:
- - command: timedatectl set-ntp no
- - package:
- name: ntp
- state: present
- - service:
- name: ntpd
- enabled: yes
- state: started
- when: ntp_daemon_type == "ntpd"
-
-- name: setup chrony
- block:
- - command: timedatectl set-ntp no
- - package:
- name: chrony
- state: present
- - service:
- name: chronyd
- enabled: yes
- state: started
- when: ntp_daemon_type == "chronyd"
-
-- name: setup timesyncd
- block:
- - command: timedatectl set-ntp on
- when: ntp_daemon_type == "timesyncd"
--- /dev/null
+---
+- name: set ntp service name depending on OS family
+ block:
+ - name: set ntp service name for Debian family
+ set_fact:
+ ntp_service_name: ntp
+ when: ansible_os_family == 'Debian'
+ - name: set ntp service name for Red Hat family
+ set_fact:
+ ntp_service_name: ntpd
+ when: ansible_os_family in ['RedHat', 'Suse']
+
+- name: setup ntp daemon
+ block:
+ - name: install and enable timesyncd
+ command: timedatectl set-ntp on
+ when: ntp_daemon_type == "timesyncd"
+
+ - name: disable time sync using timesyncd if we are not using it
+ command: timedatectl set-ntp no
+ when: ntp_daemon_type != "timesyncd"
+
+ - name: setup ntpd
+ when: ntp_daemon_type == "ntpd"
+ block:
+ - name: install ntp
+ package:
+ name: ntp
+ state: present
+ register: result
+ until: result is succeeded
+ - name: enable and start ntp
+ service:
+ name: "{{ ntp_service_name }}"
+ enabled: yes
+ state: started
+
+ - name: setup chronyd
+ when: ntp_daemon_type == "chronyd"
+ block:
+ - name: install chrony
+ package:
+ name: chrony
+ state: present
+ register: result
+ until: result is succeeded
+ - name: enable and start chronyd
+ service:
+ name: chronyd
+ enabled: yes
+ state: started