Compare commits
2 Commits
master
...
ntp-chrony
Author | SHA1 | Date | |
---|---|---|---|
42bb310ca1 | |||
f5cc5cea9c |
@ -6,7 +6,6 @@ type: docker
|
||||
|
||||
steps:
|
||||
- name: lint
|
||||
image: alpine:latest
|
||||
image: cytopia/ansible-lint:latest
|
||||
commands:
|
||||
- apk add git ansible ansible-lint
|
||||
- ansible-lint -x305,403,701
|
||||
|
@ -5,3 +5,6 @@
|
||||
|
||||
- name: Restart ntpd
|
||||
service: name=ntpd state=restarted
|
||||
|
||||
- name: Restart chrony
|
||||
service: name=chrony state=restarted
|
||||
|
34
roles/ntp/tasks/chrony.yml
Normal file
34
roles/ntp/tasks/chrony.yml
Normal file
@ -0,0 +1,34 @@
|
||||
---
|
||||
# Use chronyd to lock time via PHC to hosts RTC
|
||||
|
||||
- name: Install chrony
|
||||
apt:
|
||||
name: chrony
|
||||
state: latest
|
||||
install_recommends: no
|
||||
|
||||
- name: Load kmod ptp_kvm at boot time
|
||||
blockinfile:
|
||||
path: /etc/modules-load.d/ptp_kvm.conf
|
||||
create: yes
|
||||
owner: root
|
||||
mode: '0400'
|
||||
block: |
|
||||
# Load VirtIO PTP driver for chrony
|
||||
ptp_kvm
|
||||
register: load_ptp_kvm
|
||||
when:
|
||||
- ansible_virtualization_role == 'guest'
|
||||
- ansible_virtualization_type == 'kvm'
|
||||
|
||||
- name: Load kmod ptp_kvm
|
||||
modprobe:
|
||||
name: ptp_kvm
|
||||
state: present
|
||||
when: not (load_ptp_kvm is skipped)
|
||||
|
||||
- name: Configure chronyd
|
||||
template:
|
||||
src: chrony.conf.j2
|
||||
dest: /etc/chrony/chrony.conf
|
||||
notify: Restart chrony
|
@ -1,11 +1,16 @@
|
||||
---
|
||||
# Select best time source
|
||||
# * on kvm sync to hypervisor rtc within nanoseconds accuracy
|
||||
# * on anything else use ntpd wich supports only milliseconds accuracy
|
||||
|
||||
- name: Install ntp
|
||||
apt: name=ntp
|
||||
- name: Setup chrony
|
||||
include_tasks: chrony.yml
|
||||
register: ntp_use_chrony
|
||||
when:
|
||||
- ansible_virtualization_role == 'guest'
|
||||
- ansible_virtualization_type == 'kvm'
|
||||
|
||||
- name: Configure ntp
|
||||
template: src=ntp.conf.j2 dest=/etc/ntp.conf
|
||||
notify: Restart ntp
|
||||
|
||||
- name: Start the ntp service
|
||||
service: name=ntp state=started enabled=yes
|
||||
- name: Setup ntpd
|
||||
include_tasks: ntp.yml
|
||||
when:
|
||||
- ntp_use_chrony is skipped
|
||||
|
11
roles/ntp/tasks/ntp.yml
Normal file
11
roles/ntp/tasks/ntp.yml
Normal file
@ -0,0 +1,11 @@
|
||||
---
|
||||
|
||||
- name: Install ntp
|
||||
apt: name=ntp
|
||||
|
||||
- name: Configure ntp
|
||||
template: src=ntp.conf.j2 dest=/etc/ntp.conf
|
||||
notify: Restart ntp
|
||||
|
||||
- name: Start the ntp service
|
||||
service: name=ntp state=started enabled=yes
|
27
roles/ntp/templates/chrony.conf.j2
Normal file
27
roles/ntp/templates/chrony.conf.j2
Normal file
@ -0,0 +1,27 @@
|
||||
# {{ ansible_managed }}
|
||||
|
||||
{% if not (load_ptp_kvm is skipped) %}
|
||||
refclock PHC /dev/ptp0 poll 2
|
||||
{% elif ntp_servers is defined %}
|
||||
{% for srv in ntp_servers %}
|
||||
server {{ srv }} iburst
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
pool 2.debian.pool.ntp.org iburst
|
||||
{% endif %}
|
||||
|
||||
{% if ntp_peers is defined %}
|
||||
{% for peer in ntp_peers %}
|
||||
peer {{ peer }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
keyfile /etc/chrony/chrony.keys
|
||||
driftfile /var/lib/chrony/chrony.drift
|
||||
logdir /var/log/chrony
|
||||
maxupdateskew 100.0
|
||||
rtcsync
|
||||
makestep 1 3
|
||||
|
||||
# Do not allow chronyc for security reasons
|
||||
cmdport 0
|
Loading…
Reference in New Issue
Block a user