From b8022a604742b5fa3fb2506fee48289df3e9bd15 Mon Sep 17 00:00:00 2001 From: Davous3k Date: Tue, 26 Jul 2022 23:19:22 +0200 Subject: [PATCH] 1st commit --- chrony.yml | 12 ++++++++++ chrony/defaults/main.yml | 11 +++++++++ chrony/handlers/main.yml | 3 +++ chrony/meta/main.yml | 42 +++++++++++++++++++++++++++++++++ chrony/tasks/main.yml | 19 +++++++++++++++ chrony/tasks/ubuntu.yml | 3 +++ chrony/templates/chrony.conf.j2 | 39 ++++++++++++++++++++++++++++++ chrony/vars/ubuntu.yml | 5 ++++ 8 files changed, 134 insertions(+) create mode 100644 chrony.yml create mode 100644 chrony/defaults/main.yml create mode 100644 chrony/handlers/main.yml create mode 100644 chrony/meta/main.yml create mode 100644 chrony/tasks/main.yml create mode 100644 chrony/tasks/ubuntu.yml create mode 100644 chrony/templates/chrony.conf.j2 create mode 100644 chrony/vars/ubuntu.yml diff --git a/chrony.yml b/chrony.yml new file mode 100644 index 0000000..b332cbc --- /dev/null +++ b/chrony.yml @@ -0,0 +1,12 @@ +- name: Setup chrony + hosts: test + become: true + gather_facts: False + pre_tasks: + - name: 1. Check Python and install if not present + raw: test -e /usr/bin/python || ( apt -y update && apt install -y python) + changed_when: False + - name: 2. Gather facts + setup: # aka gather_facts + roles: + - chrony diff --git a/chrony/defaults/main.yml b/chrony/defaults/main.yml new file mode 100644 index 0000000..7784c29 --- /dev/null +++ b/chrony/defaults/main.yml @@ -0,0 +1,11 @@ +--- +chrony_pkg_state: present +chrony_service_state: started +chrony_service_enabled: yes +chrony_config_server: + - 0.cz.pool.ntp.org + - 1.cz.pool.ntp.org + - 2.cz.pool.ntp.org + - 3.cz.pool.ntp.org +chrony_config_logdir: /var/log/chrony +chrony_config_extra_options: {} diff --git a/chrony/handlers/main.yml b/chrony/handlers/main.yml new file mode 100644 index 0000000..a917f78 --- /dev/null +++ b/chrony/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart chrony + service: name={{ chrony_service_name }} state=restarted diff --git a/chrony/meta/main.yml b/chrony/meta/main.yml new file mode 100644 index 0000000..f643c29 --- /dev/null +++ b/chrony/meta/main.yml @@ -0,0 +1,42 @@ +--- +galaxy_info: + author: davo + role_name: chrony + company: davo + description: Enables users to install and configure chrony on their hosts. + license: MIT + min_ansible_version: 2.4 + platforms: + - name: Ubuntu + versions: + - artful + - bionic + - cosmic + - cuttlefish + - disco + - eoan + - focal + - groovy + - hirsute + - impish + - jammy + - lucid + - maverick + - natty + - precise + - quantal + - raring + - saucy + - trusty + - utopic + - vivid + - wily + - xenial + - yakkety + - zesty + galaxy_tags: + - system + - chrony + - ntp + - time +dependencies: [] diff --git a/chrony/tasks/main.yml b/chrony/tasks/main.yml new file mode 100644 index 0000000..f7094a5 --- /dev/null +++ b/chrony/tasks/main.yml @@ -0,0 +1,19 @@ +--- +- name: chrony | Add the OS specific variables + include_vars: "ubuntu.yml" + +- name: chrony | Installation + include_tasks: "ubuntu.yml" + +- name: chrony | Copy the chrony.conf template file + template: + src: chrony.conf.j2 + dest: "{{ chrony_config_location }}" + notify: + - restart chrony + +- name: chrony | start and enable chrony service + service: + name: "{{ chrony_service_name }}" + state: "{{ chrony_service_state }}" + enabled: "{{ chrony_service_enabled }}" diff --git a/chrony/tasks/ubuntu.yml b/chrony/tasks/ubuntu.yml new file mode 100644 index 0000000..6049560 --- /dev/null +++ b/chrony/tasks/ubuntu.yml @@ -0,0 +1,3 @@ +--- +- name: Install the require packages in Ubuntu derivatives + apt: name=chrony state={{ chrony_pkg_state }} diff --git a/chrony/templates/chrony.conf.j2 b/chrony/templates/chrony.conf.j2 new file mode 100644 index 0000000..85ea208 --- /dev/null +++ b/chrony/templates/chrony.conf.j2 @@ -0,0 +1,39 @@ +# {{ ansible_managed }} + +# List of NTP servers to use. +{% for server in chrony_config_server %} +server {{ server }} iburst +{% endfor %} + +# This directive specify the location of the file containing ID/key pairs for +# NTP authentication. +keyfile {{ chrony_config_keyfile }} + +# This directive specify the file into which chronyd will store the rate +# information. +driftfile {{ chrony_config_driftfile }} + +# Uncomment the following line to turn logging on. +#log tracking measurements statistics + +# Log files location. +logdir {{chrony_config_logdir }} + +# Stop bad estimates upsetting machine clock. +maxupdateskew 100.0 + +# Bind local adress +bindaddress 127.0.0.1 + +# This directive enables kernel synchronisation (every 11 minutes) of the +# real-time clock. Note that it can't be used along with the 'rtcfile' directive. +rtcsync + +# Step the system clock instead of slewing it if the adjustment is larger than +# one second, but only in the first three clock updates. +makestep 1 3 + +# Extra options +{% for k, v in chrony_config_extra_options.items() %} +{{ k }} {{ v }} +{% endfor %} diff --git a/chrony/vars/ubuntu.yml b/chrony/vars/ubuntu.yml new file mode 100644 index 0000000..8cd6485 --- /dev/null +++ b/chrony/vars/ubuntu.yml @@ -0,0 +1,5 @@ +--- +chrony_service_name: chrony +chrony_config_location: /etc/chrony/chrony.conf +chrony_config_driftfile: /var/lib/chrony/chrony.drift +chrony_config_keyfile: /etc/chrony/chrony.keys