From 4233329691eb1512e8d07852769da9e7920b86e2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Diemer?= <stephane.diemer@ubicast.eu>
Date: Tue, 13 Mar 2018 09:48:12 +0100
Subject: [PATCH] Handle multiple servers in ntp setup.

---
 2.Common_services/2.NTP/0_setup.py | 9 ++++++++-
 2.Common_services/2.NTP/ntp.conf   | 3 +--
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/2.Common_services/2.NTP/0_setup.py b/2.Common_services/2.NTP/0_setup.py
index d6d38948..7c0868bc 100644
--- a/2.Common_services/2.NTP/0_setup.py
+++ b/2.Common_services/2.NTP/0_setup.py
@@ -5,12 +5,19 @@ import utils
 
 def setup(interactive=True):
     dir_path = utils.get_dir(__file__)
+    servers = ''
+    if utils.get_conf('NTP_SERVER'):
+        for server in utils.get_conf('NTP_SERVER').split(','):
+            if server.strip():
+                servers += 'server %s\n' % server.strip()
+    if not servers:
+        servers = 'server ntp.ubuntu.com\n'
     cmds = [
         # NTP
         'DEBIAN_FRONTEND=noninteractive apt-get install -y ntp',
         'echo "Replacing /etc/ntp.conf"',
         dict(line='write', template='%s/ntp.conf' % dir_path, target='/etc/ntp.conf', params=(
-            ('{{ NTP_SERVER }}', utils.get_conf('NTP_SERVER') or 'ntp.ubuntu.com'),
+            ('{{ servers }}', servers),
         )),
         'service ntp restart',
     ]
diff --git a/2.Common_services/2.NTP/ntp.conf b/2.Common_services/2.NTP/ntp.conf
index 921f2ec4..e3def2a0 100644
--- a/2.Common_services/2.NTP/ntp.conf
+++ b/2.Common_services/2.NTP/ntp.conf
@@ -12,8 +12,7 @@ filegen peerstats file peerstats type day enable
 filegen clockstats file clockstats type day enable
 
 # Specify one or more NTP servers.
-server {{ NTP_SERVER }}
-
+{{ servers }}
 # Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for
 # details.  The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>
 # might also be helpful.
-- 
GitLab