Skip to content

Latest commit

 

History

History
executable file
·
165 lines (100 loc) · 4.14 KB

README.md

File metadata and controls

executable file
·
165 lines (100 loc) · 4.14 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.

Requirements

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

None.

Role Templates

A set of default templates for cmdline.txt, dhclient.conf, ntp.conf, config.txt, and gpsd are provided in the templates subdirectory of this role. They should work fine for most applications. Should local conditions dictate, you may optionally override them by putting equivalent-named files in {{ inventory_dir }}/templates.

Dependencies

None.

Example Playbook

Create playbook, tinaja-ntp-gps.yml:

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

Basic Steps

  • Install Ansible - will assume this is already done...
  • Download the latest version of the Raspbian image from: https://downloads.raspberrypi.org/raspbian_lite_latest
  • 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/id_rsa.pub [email protected]

  • 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 [email protected]

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

References

License

MIT

Author Information

Chris Jefferies - [email protected]