From 488281187e8ac6c587db74961db9e075f31c8eae Mon Sep 17 00:00:00 2001 From: Rishabh Dave Date: Wed, 12 Dec 2018 16:45:00 +0530 Subject: [PATCH] ceph-infra: merge ntp_debian.yml and ntp_rpm.yml Merge ntp_debian.yml and ntp_rpm.yml into one (the new file is called setup_ntp.yml) since they are almost identical. Also avoid repetition of the common setup step for ntpd and chronyd services. Signed-off-by: Rishabh Dave (cherry picked from commit b03ab607422eda0094d74223d52024a373b7ee9a) # Conflicts: # roles/ceph-infra/tasks/ntp_debian.yml # roles/ceph-infra/tasks/ntp_rpm.yml --- roles/ceph-infra/tasks/main.yml | 15 ++------ roles/ceph-infra/tasks/setup_ntp.yml | 51 ++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 roles/ceph-infra/tasks/setup_ntp.yml diff --git a/roles/ceph-infra/tasks/main.yml b/roles/ceph-infra/tasks/main.yml index 8bec42420..ff0683980 100644 --- a/roles/ceph-infra/tasks/main.yml +++ b/roles/ceph-infra/tasks/main.yml @@ -6,16 +6,7 @@ - ansible_os_family in ['RedHat', 'Suse'] tags: configure_firewall -- name: include_tasks "ntp_debian.yml" - include_tasks: "ntp_debian.yml" - when: - - ansible_os_family == 'Debian' - - ntp_service_enabled +- name: include_tasks setup_ntp.yml + include_tasks: setup_ntp.yml + when: ntp_service_enabled tags: configure_ntp - -- name: include_tasks "ntp_rpm.yml" - include_tasks: "ntp_rpm.yml" - when: - - ansible_os_family in ['RedHat', 'Suse'] - - ntp_service_enabled - tags: configure_ntp \ No newline at end of file diff --git a/roles/ceph-infra/tasks/setup_ntp.yml b/roles/ceph-infra/tasks/setup_ntp.yml new file mode 100644 index 000000000..b6a2ce34a --- /dev/null +++ b/roles/ceph-infra/tasks/setup_ntp.yml @@ -0,0 +1,51 @@ +--- +- 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