changes to separate server and client and generate proper conf file
diff --git a/ntp/files/ntp.conf b/ntp/files/ntp.conf
index e19c49d..27f114d 100644
--- a/ntp/files/ntp.conf
+++ b/ntp/files/ntp.conf
@@ -8,25 +8,31 @@
# - http://support.ntp.org/bin/view/Support/GettingStarted
# - https://wiki.archlinux.org/index.php/Network_Time_Protocol_daemon
-# Associate to Czech public NTP pool servers
+# Associate to cloud NTP pool servers
+{%- if client.get('enabled', True) %}
{%- for stratum in client.strata %}
server {{ stratum }}{% if loop.first %} iburst{% endif %}
{%- endfor %}
+{%- endif %}
+{%- if server.get('enabled', True) %}
+{%- for stratum in server.strata %}
+server {{ stratum }}{% if loop.first %} iburst{% endif %}
+{%- endfor %}
+{%- endif %}
# Only allow read-only access from localhost
restrict default noquery nopeer
-
-
restrict 127.0.0.1
restrict ::1
-{%- if client.get('mode7') %}
+
# mode7 is required for collectd monitoring
+{%- if server.get('mode7') %}
enable mode7
{%- endif %}
-
{%- if server.get('enabled', False) %}
+
# Provide your current local time as a default should you temporarly lose Internet connectivity
server 127.127.1.0
fudge 127.127.1.0 stratum 10
@@ -44,6 +50,4 @@
# Location of drift file
driftfile /var/lib/ntp/ntp.drift
-logfile /var/log/ntp.log
-
-
+logfile /var/log/ntp.log
\ No newline at end of file
diff --git a/ntp/map.jinja b/ntp/map.jinja
index 60f7d70..abeb7a5 100644
--- a/ntp/map.jinja
+++ b/ntp/map.jinja
@@ -1,16 +1,15 @@
-
{% set client = salt['grains.filter_by']({
'Arch': {
'service': 'ntpd',
- 'mode7': False,
+ 'mode7': True,
},
'Debian': {
'service': 'ntp',
- 'mode7': False,
+ 'mode7': True
},
'RedHat': {
'service': 'ntpd',
- 'mode7': False,
+ 'mode7': True,
},
}, merge=salt['pillar.get']('ntp:client')) %}
@@ -33,4 +32,4 @@
'address': '0.0.0.0',
}
},
-}, merge=salt['pillar.get']('ntp:server')) %}
+}, merge=salt['pillar.get']('ntp:server')) %}
\ No newline at end of file
diff --git a/ntp/server.sls b/ntp/server.sls
index 57634b5..81d2d80 100644
--- a/ntp/server.sls
+++ b/ntp/server.sls
@@ -1,5 +1,54 @@
-{%- from "ntp/map.jinja" import server with context %}
+{% from "ntp/map.jinja" import server with context %}
+
{%- if server.enabled %}
-#include:
-# - ntp.client
+
+{%- if grains.os_family == 'Arch' %}
+
+ntp_remove_packages:
+ pkg.removed:
+ - names:
+ - openntpd
+ - require_in:
+ - pkg: ntp_packages
+
{%- endif %}
+
+ntp_packages:
+ pkg.installed:
+ - name: ntp
+
+{%- if grains.os_family == "RedHat" %}
+
+ntp_client_group_and_user:
+ group.present:
+ - name: ntp
+ - require:
+ - pkg: ntp_packages
+ user.present:
+ - name: ntp
+ - shell: /sbin/nologin
+ - home: /etc/ntp
+ - groups:
+ - ntp
+ - require:
+ - group: ntp
+ - require_in:
+ - file: /etc/ntp.conf
+
+{%- endif %}
+
+/etc/ntp.conf:
+ file.managed:
+ - source: salt://ntp/files/ntp.conf
+ - template: jinja
+ - require:
+ - pkg: ntp_packages
+
+ntp_service:
+ service.running:
+ - enable: true
+ - name: {{ server.service }}
+ - watch:
+ - file: /etc/ntp.conf
+
+{%- endif %}
\ No newline at end of file