From f354af18a8088921dd3250e60195ed5673b1e58a Mon Sep 17 00:00:00 2001 From: Markus Hauschild Date: Sun, 13 Dec 2015 18:51:08 +0100 Subject: [PATCH] Add ntp role. --- roles/ntp/handlers/Debian.yml | 4 ++++ roles/ntp/handlers/FreeBSD.yml | 4 ++++ roles/ntp/handlers/main.yml | 7 +++++++ roles/ntp/tasks/Debian.yml | 11 +++++++++++ roles/ntp/tasks/FreeBSD.yml | 10 ++++++++++ roles/ntp/tasks/main.yml | 8 ++++++++ roles/ntp/templates/ntp.conf.j2 | 15 +++++++++++++++ 7 files changed, 59 insertions(+) create mode 100644 roles/ntp/handlers/Debian.yml create mode 100644 roles/ntp/handlers/FreeBSD.yml create mode 100644 roles/ntp/handlers/main.yml create mode 100644 roles/ntp/tasks/Debian.yml create mode 100644 roles/ntp/tasks/FreeBSD.yml create mode 100644 roles/ntp/tasks/main.yml create mode 100644 roles/ntp/templates/ntp.conf.j2 diff --git a/roles/ntp/handlers/Debian.yml b/roles/ntp/handlers/Debian.yml new file mode 100644 index 0000000..60816df --- /dev/null +++ b/roles/ntp/handlers/Debian.yml @@ -0,0 +1,4 @@ +--- + +- name: Restart ntp + service: name=ntp state=restarted diff --git a/roles/ntp/handlers/FreeBSD.yml b/roles/ntp/handlers/FreeBSD.yml new file mode 100644 index 0000000..0904997 --- /dev/null +++ b/roles/ntp/handlers/FreeBSD.yml @@ -0,0 +1,4 @@ +--- + +- name: Restart ntp + service: name=ntpd state=restarted diff --git a/roles/ntp/handlers/main.yml b/roles/ntp/handlers/main.yml new file mode 100644 index 0000000..ad14d5b --- /dev/null +++ b/roles/ntp/handlers/main.yml @@ -0,0 +1,7 @@ +--- + +- include: Debian.yml + when: ansible_os_family == 'Debian' + +- include: FreeBSD.yml + when: ansible_distribution == 'FreeBSD' diff --git a/roles/ntp/tasks/Debian.yml b/roles/ntp/tasks/Debian.yml new file mode 100644 index 0000000..b113021 --- /dev/null +++ b/roles/ntp/tasks/Debian.yml @@ -0,0 +1,11 @@ +--- + +- name: Install ntp + apt: name=ntp state=present + +- name: Configure ntp + template: src=ntp.conf.j2 dest=/etc/ntp.conf + notify: Restart ntp + +- name: Start the ntp service + service: name=ntp state=started enabled=yes diff --git a/roles/ntp/tasks/FreeBSD.yml b/roles/ntp/tasks/FreeBSD.yml new file mode 100644 index 0000000..2032859 --- /dev/null +++ b/roles/ntp/tasks/FreeBSD.yml @@ -0,0 +1,10 @@ +--- + +# ntp is already installed on FreeBSD + +- name: Configure ntp + template: src=ntp.conf.j2 dest=/etc/ntp.conf + notify: Restart ntp + +- name: Start the ntp service + service: name=ntpd state=started enabled=yes diff --git a/roles/ntp/tasks/main.yml b/roles/ntp/tasks/main.yml new file mode 100644 index 0000000..143e7cc --- /dev/null +++ b/roles/ntp/tasks/main.yml @@ -0,0 +1,8 @@ +--- +# This playbook contains common plays that will be run on all nodes. + +- include: Debian.yml + when: ansible_os_family == 'Debian' + +- include: FreeBSD.yml + when: ansible_distribution == 'FreeBSD' diff --git a/roles/ntp/templates/ntp.conf.j2 b/roles/ntp/templates/ntp.conf.j2 new file mode 100644 index 0000000..7226197 --- /dev/null +++ b/roles/ntp/templates/ntp.conf.j2 @@ -0,0 +1,15 @@ +{% for srv in ntp_servers %} +server {{ srv }} iburst +{% endfor %} +{% if ntp_peers is defined %} + +{% for peer in ntp_peers %} +peer {{ peer }} +{% endfor %} +{% endif %} + +restrict default kod nomodify notrap nopeer noquery +restrict -6 default kod nomodify notrap nopeer noquery + +restrict 127.0.0.1 +restrict -6 ::1