commit f354af18a8088921dd3250e60195ed5673b1e58a Author: Markus Hauschild Date: Sun Dec 13 18:51:08 2015 +0100 Add ntp role. 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