Last active
October 18, 2019 04:40
-
-
Save tsuchm/54ade1fa4c6a897a615aa2156f56aabd to your computer and use it in GitHub Desktop.
Ansible playbook to install NTP or Chrony
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - name: Decide whether ntp or chrony is used for the target | |
| set_fact: | |
| use_chrony: true | |
| when: ansible_os_family == 'RedHat' and ansible_distribution_major_version >= '7' | |
| - name: Install either ntp or chrony | |
| package: | |
| name: >- | |
| {%- if use_chrony is defined -%}chrony | |
| {%- else -%}ntp | |
| {%- endif -%} | |
| state: present | |
| - name: Prepare /etc/ntp.conf | |
| copy: src=ntp.conf dest=/etc/ntp.conf owner=root group=root mode=0644 | |
| when: use_chrony is not defined | |
| - name: Remove /etc/ntp.conf when chrony is used | |
| file: | |
| path: /etc/ntp.conf | |
| state: absent | |
| when: use_chrony is defined | |
| - name: Prepare /etc/chrony.conf | |
| copy: src=chrony.conf dest=/etc/chrony.conf owner=root group=root mode=0644 | |
| when: use_chrony is defined | |
| - name: Check either ntp or chrony is running and enabled | |
| service: | |
| name: >- | |
| {%- if use_chrony is defined -%}chronyd | |
| {%- else -%}ntp | |
| {%- endif -%} | |
| state: started | |
| enabled: yes | |
| - name: Uninstall ntp when chrony is installed | |
| package: | |
| name: ntp | |
| state: absent | |
| when: use_chrony is defined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment