├── .gitignore ├── tests └── role.yml ├── vars ├── RedHat.yml └── Debian.yml ├── handlers └── main.yml ├── meta └── main.yml ├── .travis.yml ├── README.md ├── defaults └── main.yml ├── tasks └── main.yml └── templates └── ntp.conf.j2 /.gitignore: -------------------------------------------------------------------------------- 1 | vagrant* 2 | .vagrant 3 | -------------------------------------------------------------------------------- /tests/role.yml: -------------------------------------------------------------------------------- 1 | - hosts: localhost 2 | roles: 3 | - ansible-role-ntp 4 | -------------------------------------------------------------------------------- /vars/RedHat.yml: -------------------------------------------------------------------------------- 1 | --- 2 | ntp_service_name: ntpd 3 | ntp_config_driftfile: /var/lib/ntp/drift 4 | -------------------------------------------------------------------------------- /vars/Debian.yml: -------------------------------------------------------------------------------- 1 | --- 2 | ntp_service_name: ntp 3 | ntp_config_driftfile: /var/lib/ntp/ntp.drift 4 | 5 | -------------------------------------------------------------------------------- /handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: restart ntp 3 | service: name={{ ntp_service_name }} state=restarted 4 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | galaxy_info: 3 | author: "René Moser" 4 | license: BSD 5 | min_ansible_version: 1.4 6 | platforms: 7 | - name: EL 8 | versions: 9 | - 5 10 | - 6 11 | - name: Fedora 12 | versions: 13 | - 16 14 | - 17 15 | - 18 16 | - name: Ubuntu 17 | versions: 18 | - precise 19 | - quantal 20 | - raring 21 | - saucy 22 | - name: Debian 23 | versions: 24 | - wheezy 25 | categories: 26 | - system 27 | dependencies: [] 28 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: python 3 | python: "2.7" 4 | before_install: 5 | - sudo apt-get update -qq 6 | - sudo apt-get install -qq python-apt python-pycurl 7 | install: 8 | - pip install ansible 9 | - echo -e 'localhost ansible_connection=local' > tests/inventory 10 | - echo -e '[defaults]\nroles_path = ../\nhostfile = ./tests/inventory' > ansible.cfg 11 | script: 12 | - ansible-playbook --syntax-check tests/role.yml 13 | - ansible-playbook --sudo -v --diff tests/role.yml 14 | - > 15 | ansible-playbook --sudo tests/role.yml 16 | | grep -q 'changed=0.*failed=0' 17 | && (echo 'Idempotence test: pass' && exit 0) 18 | || (echo 'Idempotence test: fail' && exit 1) 19 | notifications: 20 | webhooks: https://galaxy.ansible.com/api/v1/notifications/ 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ntp 2 | === 3 | 4 | [![Build Status](https://travis-ci.org/resmo/ansible-role-ntp.png?branch=master)](https://travis-ci.org/resmo/ansible-role-ntp) 5 | 6 | This role enables users to install and configure ntp on their hosts. 7 | 8 | Requirements 9 | ------------ 10 | 11 | This role requires Ansible 1.4 or higher, and platform requirements are listed 12 | in the metadata file. 13 | 14 | Examples 15 | -------- 16 | 17 | 1) Install ntp and set the default settings. 18 | 19 | - hosts: all 20 | roles: 21 | - role: ntp 22 | 23 | 2) Install ntp and set some custom servers. 24 | 25 | - hosts: all 26 | roles: 27 | - role: ntp 28 | ntp_config_server: [2.ubuntu.pool.ntp.org, 1.ubuntu.pool.ntp.org] 29 | 30 | License 31 | ------- 32 | 33 | BSD 34 | 35 | Author Information 36 | ------------------ 37 | 38 | - Benno Joy 39 | - René Moser 40 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | ntp_pkg_state: 'installed' 3 | ntp_service_state: 'started' 4 | ntp_service_enabled: 'yes' 5 | 6 | ntp_config_server: [ '0.pool.ntp.org', '1.pool.ntp.org', '2.pool.ntp.org', '3.pool.ntp.org' ] 7 | ntp_config_restrict: 8 | - '-4 default kod notrap nomodify nopeer noquery' 9 | - '-6 default kod notrap nomodify nopeer noquery' 10 | - '127.0.0.1' 11 | - '::1' 12 | 13 | ntp_config_listen: [] 14 | 15 | ntp_config_filegen: 16 | - 'loopstats file loopstats type day enable' 17 | - 'peerstats file peerstats type day enable' 18 | - 'clockstats file clockstats type day enable' 19 | 20 | ntp_config_statistics: 'loopstats peerstats clockstats' 21 | ntp_config_crypto: '' 22 | ntp_config_includefile: '' 23 | ntp_config_keys: '' 24 | ntp_config_trustedkey: '' 25 | ntp_config_requestkey: '' 26 | ntp_config_controlkey: '' 27 | ntp_config_broadcast: '' 28 | ntp_config_broadcastclient: '' 29 | ntp_config_multicastclient: '' 30 | ntp_config_tinker_panic_enabled: '' 31 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Add the OS specific variables 3 | include_vars: '{{ ansible_os_family }}.yml' 4 | tags: [ 'configuration', 'package', 'service', 'ntp' ] 5 | 6 | - name: Install the required packages in Redhat derivatives 7 | yum: name=ntp state={{ ntp_pkg_state }} 8 | when: ansible_os_family == 'RedHat' 9 | tags: [ 'package', 'ntp' ] 10 | 11 | - name: Install the required packages in Debian derivatives 12 | apt: name=ntp state={{ ntp_pkg_state }} update_cache=yes cache_valid_time=86400 13 | when: ansible_os_family == 'Debian' 14 | tags: [ 'package', 'ntp' ] 15 | 16 | - name: Copy the ntp.conf template file 17 | template: src=ntp.conf.j2 dest=/etc/ntp.conf 18 | notify: 19 | - restart ntp 20 | tags: [ 'configuration', 'package', 'ntp' ] 21 | 22 | - name: Start/stop ntp service 23 | service: name={{ ntp_service_name }} state={{ ntp_service_state }} enabled={{ ntp_service_enabled }} pattern='/ntpd' 24 | tags: [ 'service', 'ntp' ] 25 | -------------------------------------------------------------------------------- /templates/ntp.conf.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | 3 | {% if ntp_config_tinker_panic_enabled %} 4 | tinker panic 0 5 | {% endif %} 6 | 7 | driftfile {{ ntp_config_driftfile }} 8 | 9 | {% for server in ntp_config_server %} 10 | server {{ server }} 11 | {% endfor %} 12 | 13 | {% if ntp_config_statistics %} 14 | statistics {{ ntp_config_statistics }} 15 | {% endif %} 16 | 17 | {% for filegen in ntp_config_filegen %} 18 | filegen {{ filegen }} 19 | {% endfor %} 20 | 21 | {% for listen in ntp_config_listen %} 22 | interface listen {{ listen }} 23 | {% endfor %} 24 | 25 | {% for restrict in ntp_config_restrict %} 26 | restrict {{ restrict }} 27 | {% endfor %} 28 | 29 | {% if ntp_config_crypto %} 30 | crypto 31 | {% endif %} 32 | 33 | {% if ntp_config_includefile %} 34 | includefile {{ ntp_config_includefile }} 35 | {% endif %} 36 | 37 | {% if ntp_config_keys %} 38 | keys {{ ntp_config_keys }} 39 | {% endif %} 40 | 41 | {% if ntp_config_trustedkey %} 42 | trustedkey {{ ntp_config_trustedkey }} 43 | {% endif %} 44 | 45 | {% if ntp_config_requestkey %} 46 | requestkey {{ ntp_config_requestkey }} 47 | {% endif %} 48 | 49 | {% if ntp_config_controlkey %} 50 | controlkey {{ ntp_config_controlkey }} 51 | {% endif %} 52 | 53 | {% if ntp_config_broadcast %} 54 | broadcast {{ ntp_config_broadcast }} 55 | {% endif %} 56 | 57 | {% if ntp_config_broadcastclient %} 58 | broadcastclient 59 | {% endif %} 60 | 61 | {% if ntp_config_multicastclient %} 62 | multicastclient {{ ntp_config_multicastclient }} 63 | {% endif %} 64 | --------------------------------------------------------------------------------