Skip to content
This repository has been archived by the owner on Jul 7, 2021. It is now read-only.

Commit

Permalink
extended and reformated role
Browse files Browse the repository at this point in the history
  • Loading branch information
Rene Moser committed Jan 9, 2014
1 parent 08fd372 commit e3c7930
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 102 deletions.
39 changes: 4 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ntp
===

[![Build Status](https://travis-ci.org/resmo/ansible-role-ntp.png?branch=master)](https://travis-ci.org/resmo/ansible-role-ntp)

This role enables users to install and configure ntp on their hosts.

Requirements
Expand All @@ -9,34 +11,6 @@ Requirements
This role requires Ansible 1.4 or higher, and platform requirements are listed
in the metadata file.

Role Variables
--------------

The variables that can be passed to this role and a brief description about
them are as follows. See the NTP configuration documentation for details:

# The driftfile
ntp_driftfile: /var/lib/ntp/drifta

# The server to sync time with
ntp_server: [0.ubuntu.pool.ntp.org, 1.ubuntu.pool.ntp.org]

ntp_restrict:
- "restrict -4 default kod notrap nomodify nopeer noquery"
- "restrict -6 default kod notrap nomodify nopeer noquery"
- "restrict 127.0.0.1"

ntp_crypto: no
ntp_includefile: no
ntp_keys: no
ntp_trustedkey: no
ntp_requestkey: no
ntp_controlkey: no
ntp_statistics: no
ntp_broadcast: no
ntp_broadcastclient: no
ntp_multicastclient: no

Examples
--------

Expand All @@ -51,12 +25,7 @@ Examples
- hosts: all
roles:
- role: ntp
ntp_server: [2.ubuntu.pool.ntp.org, 1.ubuntu.pool.ntp.org]

Dependencies
------------

None
ntp_config_server: [2.ubuntu.pool.ntp.org, 1.ubuntu.pool.ntp.org]

License
-------
Expand All @@ -67,4 +36,4 @@ Author Information
------------------

Benno Joy

René Moser
40 changes: 24 additions & 16 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
---
npt_pkg_state: installed
ntp_service_state: started
ntp_service_enabled: yes

ntp_driftfile: /var/lib/ntp/drift
ntp_server: [0.ubuntu.pool.ntp.org, 1.ubuntu.pool.ntp.org]
ntp_restrict:
- "restrict -4 default kod notrap nomodify nopeer noquery"
- "restrict -6 default kod notrap nomodify nopeer noquery"
- "restrict 127.0.0.1"
ntp_config_server: [0.pool.ntp.org, 1.pool.ntp.org, 2.pool.ntp.org, 3.pool.ntp.org]
ntp_config_restrict:
- "-4 default kod notrap nomodify nopeer noquery"
- "-6 default kod notrap nomodify nopeer noquery"
- "127.0.0.1"

ntp_crypto: no
ntp_includefile: no
ntp_keys: no
ntp_trustedkey: no
ntp_requestkey: no
ntp_controlkey: no
ntp_statistics: no
ntp_broadcast: no
ntp_broadcastclient: no
ntp_multicastclient: no
ntp_config_filegen:
- "loopstats file loopstats type day enable"
- "peerstats file peerstats type day enable"
- "clockstats file clockstats type day enable"

ntp_config_statistics: "loopstats peerstats clockstats"

ntp_config_crypto: no
ntp_config_includefile: no
ntp_config_keys: no
ntp_config_trustedkey: no
ntp_config_requestkey: no
ntp_config_controlkey: no
ntp_config_broadcast: no
ntp_config_broadcastclient: no
ntp_config_multicastclient: no
4 changes: 1 addition & 3 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
---

- name: restart ntp
service: name={{ ntp_svc_name }} state=restarted enabled=yes

service: name={{ ntp_service_name }} state=restarted
5 changes: 2 additions & 3 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
galaxy_info:
author: "Benno Joy"
author: "Benno Joy, René Moser"
company: AnsibleWorks
license: BSD
min_ansible_version: 1.4
Expand All @@ -21,6 +21,5 @@ galaxy_info:
- raring
- saucy
categories:
- development
- system
dependencies: []

15 changes: 7 additions & 8 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
---

- name: Add the OS specific varibles
- name: Add the OS specific variables
include_vars: "{{ ansible_os_family }}.yml"

- name: Install the required packages in Redhat derivatives
yum: name={{ item }} state=installed
- name: Install the required packages in Redhat derivatives
yum: name={{ item }} state={{ npt_pkg_state }}
with_items: ntp_pkgs
when: ansible_os_family == 'RedHat'

- name: Install the required packages in Debian derivatives
apt: name={{ item }} state=installed update_cache=yes
apt: name={{ item }} state={{ npt_pkg_state }} update_cache=yes
with_items: ntp_pkgs
environment: env
when: ansible_os_family == 'Debian'

- name: Copy the ntp.conf template file
template: src=ntp.conf.j2 dest=/etc/ntp.conf
notify:
- restart ntp
- restart ntp


- name: Start/stop ntp service
service: name={{ ntp_service_name }} state={{ ntp_service_state }} enabled={{ ntp_service_enabled }}
61 changes: 33 additions & 28 deletions templates/ntp.conf.j2
Original file line number Diff line number Diff line change
@@ -1,50 +1,55 @@
#{{ ansible_managed }}
# {{ ansible_managed }}

driftfile {{ ntp_driftfile }}
{% for i in ntp_server %}
server {{ i }}
{% endfor %}
driftfile {{ ntp_config_driftfile }}

{% for i in ntp_restrict %}
{{ i }}
{% for server in ntp_config_server %}
server {{ server }}
{% endfor %}

{% if ntp_crypto %}
crypto
{% if ntp_config_statistics %}
statistics {{ ntp_config_statistics }}
{% endif %}

{% if ntp_includefile %}
includefile {{ ntp_includefile }}
{% for filegen in ntp_config_filegen %}
filegen {{ filegen }}
{% endfor %}

{% for restrict in ntp_config_restrict %}
restrict {{ restrict }}
{% endfor %}

{% if ntp_config_crypto %}
crypto
{% endif %}

{% if ntp_keys %}
keys {{ ntp_keys }}
{% if ntp_config_includefile %}
includefile {{ ntp_config_includefile }}
{% endif %}

{% if ntp_trustedkey %}
trustedkey {{ ntp_trustedkey }}
{% if ntp_config_keys %}
keys {{ ntp_config_keys }}
{% endif %}

{% if ntp_requestkey %}
requestkey {{ ntp_requestkey }}
{% if ntp_config_trustedkey %}
trustedkey {{ ntp_config_trustedkey }}
{% endif %}

{% if ntp_controlkey %}
controlkey {{ ntp_controlkey }}
{% if ntp_config_requestkey %}
requestkey {{ ntp_config_requestkey }}
{% endif %}

{% if ntp_statistics %}
statistics {{ ntp_statistics }}
{% if ntp_config_controlkey %}
controlkey {{ ntp_config_controlkey }}
{% endif %}

{% if ntp_broadcast %}
broadcast {{ ntp_broadcast }}
{% if ntp_config_broadcast %}
broadcast {{ ntp_config_broadcast }}
{% endif %}

{% if ntp_broadcastclient %}
{% if ntp_config_broadcastclient %}
broadcastclient
{% endif %}
{% endif %}

{% if ntp_multicastclient %}
multicastclient {{ ntp_multicastclient }}
{% endif %}
{% if ntp_config_multicastclient %}
multicastclient {{ ntp_config_multicastclient }}
{% endif %}
7 changes: 4 additions & 3 deletions vars/Debian.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
ntp_pkgs:
- python-selinux
- ntp
- ntp

ntp_service_name: ntp
ntp_config_driftfile: /var/lib/ntp/ntp.drift

ntp_svc_name: ntp
6 changes: 3 additions & 3 deletions vars/RedHat.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
ntp_pkgs:
- libselinux-python
- ntp
- ntp

ntp_svc_name: ntpd
ntp_service_name: ntpd
ntp_config_driftfile: /var/lib/ntp/drift
3 changes: 0 additions & 3 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
---
env:
RUNLEVEL: 1

0 comments on commit e3c7930

Please sign in to comment.