Skip to content

Commit

Permalink
PR #72 follow-up: Make it so you can still override ntp_package and c…
Browse files Browse the repository at this point in the history
…onfig file.
  • Loading branch information
geerlingguy committed Mar 26, 2020
1 parent c9e2a45 commit 13e46d8
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 14 deletions.
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -20,6 +20,14 @@ Whether to start the ntpd service and enable it at system boot. On many virtual

Set the timezone for your server.

ntp_package: ntp

The package to install which provides NTP functionality. The default is `ntp` for most platforms, or `chrony` on RHEL/CentOS 7 and later.

ntp_config_file: /etc/ntp.conf

The path to the NTP configuration file. The default is `/etc/ntp.conf` for most platforms, or `/etc/chrony.conf` on RHEL/CentOS 7 and later.

ntp_manage_config: false

Set to true to allow this role to manage the NTP configuration file (`/etc/ntp.conf`).
Expand Down
5 changes: 3 additions & 2 deletions defaults/main.yml
@@ -1,8 +1,9 @@
---
ntp_enabled: true
ntp_timezone: Etc/UTC
ntp_package: ntp
ntp_configfile: /etc/ntp.conf

# ntp_package: ntp
# ntp_config_file: /etc/ntp.conf

ntp_manage_config: false

Expand Down
3 changes: 3 additions & 0 deletions meta/main.yml
Expand Up @@ -35,3 +35,6 @@ galaxy_info:
- date
- time
- timezone
- chrony
- chronyd
- synchronization
30 changes: 22 additions & 8 deletions tasks/main.yml
Expand Up @@ -2,11 +2,23 @@
- name: Include OS-specific variables.
include_vars: "{{ ansible_os_family }}.yml"

- name: Include OS- Release specific variables on EL6.
include_vars: RedHat6.yml
when: ansible_os_family == 'RedHat' and ansible_distribution_major_version == '6'

- name: Ensure NTP-related packages are installed.
- name: Include OS-Release specific variables on RHEL 6.
include_vars: RedHat-6.yml
when:
- ansible_os_family == 'RedHat'
- ansible_distribution_major_version == '6'

- name: Set the ntp_package variable.
set_fact:
ntp_package: "{{ __ntp_package }}"
when: ntp_package is not defined

- name: Set the ntp_config_file variable.
set_fact:
ntp_config_file: "{{ __ntp_config_file }}"
when: ntp_config_file is not defined

- name: Ensure NTP package is installed.
package:
name: "{{ ntp_package }}"
state: present
Expand All @@ -18,7 +30,9 @@
when: ansible_system == "Linux"

- include_tasks: clock-rhel-6.yml
when: ansible_os_family == 'RedHat' and ansible_distribution_version.split('.')[0] == '6'
when:
- ansible_os_family == 'RedHat'
- ansible_distribution_major_version == '6'

- name: Set timezone
timezone:
Expand All @@ -41,7 +55,7 @@

- name: Generate ntp configuration file
template:
src: "{{ ntp_configfile |basename }}.j2"
dest: "{{ ntp_configfile }}"
src: "{{ ntp_config_file | basename }}.j2"
dest: "{{ ntp_config_file }}"
notify: restart ntp
when: ntp_manage_config | bool
2 changes: 2 additions & 0 deletions vars/Archlinux.yml
@@ -1,5 +1,7 @@
---
ntp_daemon: ntpd
ntp_tzdata_package: tzdata
__ntp_package: ntp
__ntp_config_file: /etc/ntp.conf
ntp_driftfile: /var/lib/ntp/drift
ntp_cron_daemon: cronie
2 changes: 2 additions & 0 deletions vars/Debian.yml
@@ -1,5 +1,7 @@
---
ntp_daemon: ntp
ntp_tzdata_package: tzdata
__ntp_package: ntp
__ntp_config_file: /etc/ntp.conf
ntp_driftfile: /var/lib/ntp/drift
ntp_cron_daemon: cron
2 changes: 2 additions & 0 deletions vars/FreeBSD.yml
@@ -1,5 +1,7 @@
---
ntp_daemon: ntpd
ntp_tzdata_package: tzdata
__ntp_package: ntp
__ntp_config_file: /etc/ntp.conf
ntp_driftfile: /var/lib/ntp/drift
ntp_cron_daemon: cron
4 changes: 2 additions & 2 deletions vars/RedHat.yml
@@ -1,7 +1,7 @@
---
ntp_daemon: chronyd
ntp_configfile: /etc/chrony.conf
ntp_package: chrony
ntp_tzdata_package: tzdata
__ntp_package: chrony
__ntp_config_file: /etc/chrony.conf
ntp_driftfile: /var/lib/ntp/drift
ntp_cron_daemon: crond
5 changes: 3 additions & 2 deletions vars/RedHat6.yml
@@ -1,6 +1,7 @@
---
ntp_daemon: ntpd
ntp_configfile: /etc/ntp.conf
ntp_package: ntp
ntp_tzdata_package: tzdata
__ntp_package: chrony
__ntp_config_file: /etc/ntp.conf
ntp_driftfile: /var/lib/ntp/drift
ntp_cron_daemon: crond
2 changes: 2 additions & 0 deletions vars/Suse.yml
@@ -1,5 +1,7 @@
---
ntp_daemon: ntpd
ntp_tzdata_package: timezone
__ntp_package: ntp
__ntp_config_file: /etc/ntp.conf
ntp_driftfile: /var/lib/ntp/drift/ntp.drift
ntp_cron_daemon: cron

0 comments on commit 13e46d8

Please sign in to comment.