diff --git a/README.md b/README.md index fad778ffdc255bb98b9e96b223fe49bb8afc2108..d0ab1891ee273a53fb0db1b6baa90ca4e1e5fba8 100644 --- a/README.md +++ b/README.md @@ -12,20 +12,20 @@ Role Variables -------------- If you're only trying to set up a host as a NTP client, then you can stick with -the defaults. You may want to update the `ntp_pools` variable to point to a +the defaults. You may want to update the `ntp__pools` variable to point to a closer pool, but you don't have to. Most of the other variables are only relevant if you're setting up a NTP server. | Variable | Default | Purpose | |----------|---------|---------| -| `ntp_enabled` | `true` | Asserts whether the NTP sevice should be enabled and start at boot. | -| `ntp_server` | `false` | Asserts whether the host should be configured to respond to time requests. | -| `ntp_logging` | `false` | Asserts whether logging should be enabled. | -| `ntp_sync_now` | `false` | Asserts whether the NTP service should immediately sync with its configured time servers, without regard to "easing", or errors poteentially caused by "jumps" in time. | -| `ntp_restrict` | `['127.0.0.1', '::1']` | Additional access restrictions. We already define secure defaults based on the value of `ntp_server`. Any additional `ntp_restrict` entries are likely to allow more access. | -| `ntp_servers` | `[]` | A list of NTP servers to query for time. **It's recommended to use `ntp_pools`**, but we support declaring specific servers too for backwards compatibility. | -| `ntp_pools` | `[pool.ntp.org]` | A list of NTP pool addresses. Using 1 pool is fine, and will result in multiple actual servers being used. | -| `ntp_peers` | `[]` | A list of NTP servers to peer with. You will have to add the appropriate `ntp_restrict` entries to allow peering. | +| ntp__enabled | `true` | Asserts whether the NTP sevice should be enabled and start at boot. | +| ntp__server | `false` | Asserts whether the host should be configured to respond to time requests. | +| ntp__logging | `false` | Asserts whether logging should be enabled. | +| ntp__sync_now | `false` | Asserts whether the NTP service should immediately sync with its configured time servers, without regard to "easing", or errors potentially caused by "jumps" in time. | +| ntp__restrict | `['127.0.0.1', '::1']` | Additional access restrictions. We already define secure defaults based on the value of `ntp__server`. Any additional `ntp__restrict` entries are likely to allow more access. | +| ntp__servers | `[]` | A list of NTP servers to query for time. **It's recommended to use `ntp__pools`**, but we support declaring specific servers too for backwards compatibility. | +| ntp__pools | `[pool.ntp.org]` | A list of NTP pool addresses. Using 1 pool is fine, and will result in multiple actual servers being used. | +| ntp__peers | `[]` | A list of NTP servers to peer with. You will have to add the appropriate `ntp__restrict` entries to allow peering. | Example Playbook ---------------- @@ -37,5 +37,5 @@ pool. ``` - hosts: servers roles: - - { role: ntp, ntp_pools: [us.pool.ntp.org] } + - { role: ntp, ntp__pools: [us.pool.ntp.org] } ``` diff --git a/defaults/main.yaml b/defaults/main.yaml index 8f5c45fcfe76083de2d7dacb40468e997cf07a4b..c7935db606943341cd57b5de36490caa700a6f9d 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -1,18 +1,18 @@ --- -ntp_enabled: true +ntp__enabled: true # Configure NTP to respond to requests for time. -ntp_server: false +ntp__server: false # Enable logging -ntp_logging: false +ntp__logging: false # Force NTP to update time immediately, without any "easing" -ntp_sync_now: false +ntp__sync_now: false # NTP 'restrict' directives. # Format: <address> [mask <mask>] [flag1] [flag2] ... -ntp_restrict: +ntp__restrict: - '127.0.0.1 # Local users have full access' - '::1 # Local users have full access' @@ -27,12 +27,12 @@ ntp_restrict: # specify a public pool as a backup. # # Public NTP Pools and Servers can be found at http://www.pool.ntp.org -ntp_servers: [] -ntp_pools: +ntp__servers: [] +ntp__pools: - pool.ntp.org iburst # Peers are set up as symmetric peer servers. You will have to add the # appropriate 'restrict' lines above though. -ntp_peers: [] +ntp__peers: [] ... # vi: set ts=2 sts=2 sw=2 et ft=yaml: diff --git a/handlers/main.yaml b/handlers/main.yaml index 99c7f97a9b64840d253ce0cf40fb7935c2f1c394..5171e4cf0a4999b17f0c6982dc17e80ea48fe5a5 100644 --- a/handlers/main.yaml +++ b/handlers/main.yaml @@ -1,9 +1,9 @@ --- - name: restart ntp service: - name: '{{ ntp_daemon }}' + name: '{{ ntp__daemon }}' state: restarted - when: ntp_enabled + when: ntp__enabled become: true ... # vi: set ts=2 sts=2 sw=2 et ft=yaml: diff --git a/tasks/main.yaml b/tasks/main.yaml index 845f7d5fbbd5afe63d0bddfb22bf9b5ece3b5503..2cb78c2e6b9703595e5d3e27c2b372d0c042f3d7 100644 --- a/tasks/main.yaml +++ b/tasks/main.yaml @@ -5,28 +5,28 @@ - name: Check if 'timedatectl' package is installed command: which timedatectl - register: has_timedatectl - failed_when: has_timedatectl.rc == 2 + register: _ntp__has_timedatectl + failed_when: _ntp__has_timedatectl.rc == 2 changed_when: false - when: ntp_enabled + when: ntp__enabled - name: Check if systemd time sync is disabled shell: "timedatectl status | grep -c 'Network time on: no$'" - register: timesync_status - failed_when: timesync_status.rc == 2 + register: _ntp__timesync_status + failed_when: _ntp__timesync_status.rc == 2 changed_when: false - when: (has_timedatectl.rc is defined) and (has_timedatectl.rc == 0) + when: (_ntp__has_timedatectl.rc is defined) and (_ntp__has_timedatectl.rc == 0) - name: Disable systemd time sync before enabling NTP command: timedatectl set-ntp false - when: ntp_enabled and (timesync_status.rc is defined) and (timesync_status.rc == 1) + when: ntp__enabled and (_ntp__timesync_status.rc is defined) and (_ntp__timesync_status.rc == 1) become: true - name: Install the NTP package package: name: ntp state: present - register: installed + register: _ntp__installed become: true - name: Generate the NTP configuration file @@ -36,36 +36,36 @@ owner: root group: root mode: 0644 - register: configured + register: _ntp__configured notify: restart ntp become: true - name: Stop the NTP service before forcing a time sync service: - name: '{{ ntp_daemon }}' + name: '{{ ntp__daemon }}' state: stopped - when: ntp_sync_now and (installed|changed or configured|changed) + when: ntp__sync_now and (_ntp__installed is changed or _ntp__configured is changed) become: true - name: Force a NTP time sync command: ntpd -gq - when: ntp_sync_now and (installed|changed or configured|changed) + when: ntp__sync_now and (_ntp__installed is changed or _ntp__configured is changed) become: true - name: Ensure NTP is running and enabled as configured service: - name: '{{ ntp_daemon }}' + name: '{{ ntp__daemon }}' state: started enabled: yes - when: ntp_enabled + when: ntp__enabled become: true - name: Ensure NTP is stopped and disabled as configured service: - name: '{{ ntp_daemon }}' + name: '{{ ntp__daemon }}' state: stopped enabled: no - when: not ntp_enabled + when: not ntp__enabled become: true ... diff --git a/templates/ntp.conf.j2 b/templates/ntp.conf.j2 index bca93134c479c77742688f919c84f70e59d6f0fc..647215084d77ecd71fc17c952ecb9e81a26b3cb0 100644 --- a/templates/ntp.conf.j2 +++ b/templates/ntp.conf.j2 @@ -6,7 +6,7 @@ driftfile /var/lib/ntp/ntp.drift # Enable this if you want statistics to be logged. -{% if ntp_logging %} +{% if ntp__logging %} statsdir /var/log/ntpstats/ {% else %} #statsdir /var/log/ntpstats/ @@ -17,7 +17,7 @@ filegen loopstats file loopstats type day enable filegen peerstats file peerstats type day enable filegen clockstats file clockstats type day enable -{% if ntp_server %} +{% if ntp__server %} # By default, exchange time with everybody, but don't allow configuration restrict -4 default kod notrap nomodify nopeer noquery limited restrict -6 default kod notrap nomodify nopeer noquery limited @@ -27,7 +27,7 @@ restrict -4 default ignore restrict -6 default ignore {% endif %} -{% for restriction in ntp_restrict %} +{% for restriction in ntp__restrict %} restrict {{ restriction }} {% endfor %} @@ -36,19 +36,19 @@ restrict source notrap nomodify noquery # Add the ntp servers. You generally don't need these if you're using a pool. # server 0.pool.ntp.org iburst -{% for server in ntp_servers %} +{% for server in ntp__servers %} server {{ server }} {% endfor %} # Add the pool servers # pool pool.ntp.org iburst -{% for server in ntp_pools %} +{% for server in ntp__pools %} pool {{ server }} {% endfor %} # Add peer servers. # peer my.other.ntp.server -{% for server in ntp_peers|difference(ansible_host) %} +{% for server in ntp__peers|difference(ansible_host) %} peer {{ server }} {% endfor %} diff --git a/vars/debian.yaml b/vars/debian.yaml index 86ded0523484bc3102d3059661eb33e1630e6847..cf8faf587c889ba3d03d9fbcedd2ee8979b2eba0 100644 --- a/vars/debian.yaml +++ b/vars/debian.yaml @@ -1,4 +1,4 @@ --- -ntp_daemon: ntp +ntp__daemon: ntp ... # vi: set ts=2 sts=2 sw=2 et ft=yaml: diff --git a/vars/redhat.yaml b/vars/redhat.yaml index 9884dfcddd07678ac43795782638caf3f676a174..a1a849bcf2d8a2600851426d492e4a26b0185f91 100644 --- a/vars/redhat.yaml +++ b/vars/redhat.yaml @@ -1,4 +1,4 @@ --- -ntp_daemon: ntpd +ntp__daemon: ntpd ... # vi: set ts=2 sts=2 sw=2 et ft=yaml: