Skip to content

Commit

Permalink
Install and configure Chrony (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
hungfaileung authored Jan 31, 2023
1 parent b204139 commit a763982
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
8 changes: 7 additions & 1 deletion _dependencies/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,10 @@ wait_for_dns: true
canary_tidy_on_success: false

# External DNS server for lookups when using external IPs (the default AWS resolver will resolve the VPC IPs)
external_dns_resolver: "8.8.8.8"
external_dns_resolver: "8.8.8.8"

# Whether to install chrony (ntp client)
chrony_install: yes

# NTP servers for chrony
ntp_servers: "{{ ['169.254.169.123 prefer iburst minpoll 4 maxpoll 4'] if cluster_vars.type == 'aws' else ['metadata.google.internal'] if cluster_vars.type == 'gcp' else ['pool.ntp.org'] }}"
8 changes: 8 additions & 0 deletions config/handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@
name: metricbeat
state: restarted
enabled: yes


- name: Chrony | Restart and enable chrony
become: yes
service:
name: chronyd
state: restarted
enabled: yes
43 changes: 43 additions & 0 deletions config/tasks/chrony.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---

- name: Chrony | Install and Configure - Ubuntu
block:
- name: Chrony | Ubuntu install
become: yes
apt:
name: chrony
update_cache: yes
state: present
when: ansible_os_family == "Debian"

- name: Chrony | Install and Configure - CentOS
block:
- name: Chrony | CentOS install
become: yes
yum:
name: chrony
state: present
when: ansible_os_family == "RedHat"

- name: Configure Chrony
become: yes
copy:
dest: "/etc/{% if ansible_os_family == 'Debian'%}chrony/{% endif %}chrony.conf"
backup: yes
content: |-
{% for ntp_server in ntp_servers %}
server {{ ntp_server }}
{% endfor %}
{% if ansible_os_family == 'RedHat' %}
keyfile /etc/chrony.keys
{% else %}
keyfile /etc/chrony/chrony.keys
{% endif %}
driftfile /var/lib/chrony/chrony.drift
logdir /var/log/chrony
rtcsync
makestep 1 3
notify:
- Chrony | Restart and enable chrony
4 changes: 4 additions & 0 deletions config/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@
include_tasks: cloud_agents.yml
when: (cloud_agent is defined and cloud_agent)

- name: Install chrony (NTP client)
include_tasks: chrony.yml
when: chrony_install|bool

- name: Update packages (when pkgupdate is defined)
include_tasks: pkgupdate.yml
when: pkgupdate is defined and (pkgupdate == 'always' or (pkgupdate == 'onCreate' and inventory_hostname in (hostvars['localhost'].cluster_hosts_created | json_query('[].hostname'))))
Expand Down

0 comments on commit a763982

Please sign in to comment.