Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
156 lines (93 sloc) 3.78 KB

Ansible NTP-GPS

A simple Ansible role to configure a GPS based NTP Server which can deliver a time signal to a network that is not connected to the internet.

This build uses a Raspberry Pi and time signals derived from a connected GPS device.


Designed and tested with:

Alt text

Alt text

Wiring connections:

from Raspi pin:  4 (+5V)            to GPS Breakout pin: VIN +5V        
from Raspi pin:  6 (Ground)         to GPS Breakout pin: GND Gnd        
from Raspi pin:  8 (TXD0) (GPIO14)  to GPS Breakout pin: RX TX
from Raspi pin: 10 (RXD0) (GPIO15)  to GPS Breakout pin: TX RX
from Raspi pin: 12 (GPIO18)         to GPS Breakout pin: PPS (Pulses Per Second)

Role Variables




Example Playbook

Create playbook, tinaja-ntp-gps.yml:

    - hosts: ntpserver
         - { role: tinaja.ntp-gps }

Basic Steps

  • Install Ansible - will assume this is already done...
  • Download the latest version of the Raspbian image from:
  • Burn the image on a MicroSD card (8G or more) using etcher
  • Add a magic empty file named SSH onto the boot partition (configures default SSH service)
  • Plug in the MicroSD image into the Raspi and boot up.
  • After bootup, copy your public key to the raspberrypi using user:pi, password:raspberry:

$ ssh-copy-id -f -i ~/.ssh/ pi@raspberrypi.local

  • Setup a host inventory file with a reference like this:

tinaja-ntp ansible_host=<raspi ipaddress> ansible_user=pi

  • Run your playbook:

$ ansible-playbook tinaja-ntp-gps.yml -i hosts/hosts.ini -u pi -b -c ssh

Run these tests after rebooting:

Log into your raspi:

$ ssh pi@raspberrypi.local

Escalate to user, root:

# sudo su -

See the serial data streaming in from the GPS device

# cat /dev/ttyAMA0

See the /dev/pps0 device streaming in

# ppstest /dev/pps0

See the gps device statistics including the time, Latitude, Longitude from the GPS receiver

# gpsmon

See the list of ntp servers. The PPS reference should have an asterisk indicating the primary source.

# ntpq -p

*SHM(2) .PPS. 0 l 1 64 377 0.000 -51.298 4.627

On your local server

Set up the NTP server to point to the new NTP server. Edit /etc/ntp.cfg:

# nano /etc/ntp.conf

Change this:

# You do need to talk to an NTP server or two (or three).  
#server ntp.your-provider.example  

to this:

# You do need to talk to an NTP server or two (or three).  
#server ntp.your-provider.example  
server <your ntp server ip or fqdn>

Save the file and restart the NTP service:

# systemctl restart ntp.service

See the magic, by running this command:

# date




Author Information

Chris Jefferies -

You can’t perform that action at this time.