Gerade eben bemerkte ich auf Einem meiner vielen Raspberry PIs, dass die Zeit nicht stimmt. Also mal geschaut was da los ist.
pi@raspbirrypi:~ $ ntpq
-bash: ntpq: command not found
Befehl ntpq Fehlanzeige! Ist ntp denn überhaupt installiert?
pi@raspbirrypi:~ $ dpkg -l | grep -i ntp
pi@raspbirrypi:~ $
Nö 😀
Da ich schon länger darüber nachdachte, dass eigentlich jeder Raspberry Pi bei mir im Netz eine gleiche Grundconfig benötigt, fangen wir doch jetzt damit an. 🙂 Und so sieht das initiale Ansible Playbook aus.
root@netbase:/etc/ansible# cat raspberry_base.yml
---
- name: installiert die Basis Software auf alle Raspberries damit die Grundpakete alle gleich sind.
hosts: raspi
become: yes
tasks:
- name: Install ntp
apt:
name: ntp
state: present
- name: Set Timezone to Europe/Berlin
shell: "timedatectl set-timezone Europe/Berlin"
Dies werde ich dann in Zukunft immer mehr erweitern. Neben dem NTP Dienst habe ich auch gleich noch die Zeitzone gesetzt, da ich teilweise Raspberries mit UTC und andere mit CET gefunden habe. BTW -> become: yes <- steht dafür, dass wir den root brauchen. Ist ja logisch, ein „normaler“ User kann in der Regel keine Softwarepakete installieren.
Ansible Playbook abgefeuert und fertig. 🙂
root@netbase:/etc/ansible# ansible-playbook -u pi raspberry_base.yml
PLAY [installiert die Basis Software auf alle Raspberries damit die Grundpakete alle gleich sind.] ******************************************************************
TASK [Gathering Facts] ******************************************************************
ok: [raspbirrypi.home]
ok: [raspburrypi.home]
ok: [raspbarrypi.home]
ok: [raspborrypi.home]
ok: [raspberrypi.home]
ok: [blackberrypi.home]
ok: [raspstrompi.home]
TASK [Install ntp] ******************************************************************
ok: [raspburrypi.home]
ok: [raspbarrypi.home]
ok: [raspbirrypi.home]
ok: [raspborrypi.home]
ok: [blackberrypi.home]
ok: [raspberrypi.home]
ok: [raspstrompi.home]
TASK [Set Timezone to Europe/Berlin] ******************************************************************
changed: [raspbarrypi.home]
changed: [raspburrypi.home]
changed: [raspbirrypi.home]
changed: [raspborrypi.home]
changed: [blackberrypi.home]
changed: [raspberrypi.home]
changed: [raspstrompi.home]
PLAY RECAP ******************************************************************
blackberrypi.home : ok=3 changed=1 unreachable=0 failed=0
raspbarrypi.home : ok=3 changed=1 unreachable=0 failed=0
raspberrypi.home : ok=3 changed=1 unreachable=0 failed=0
raspbirrypi.home : ok=3 changed=1 unreachable=0 failed=0
raspborrypi.home : ok=3 changed=1 unreachable=0 failed=0
raspburrypi.home : ok=3 changed=1 unreachable=0 failed=0
raspstrompi.home : ok=3 changed=1 unreachable=0 failed=0
Wer sich noch fragt, was in meinem playbook hosts: raspi bedeutet. Der findet die Antwort hier.
root@netbase:/etc/ansible# cat hosts
# This is the default ansible 'hosts' file.
#
# It should live in /etc/ansible/hosts
#
# - Comments begin with the '#' character
# - Blank lines are ignored
# - Groups of hosts are delimited by [header] elements
# - You can enter hostnames or ip addresses
# - A hostname/ip can be a member of multiple groups
# Ex 1: Ungrouped hosts, specify before any group headers.
#green.example.com
#blue.example.com
#192.168.100.1
#192.168.100.10
netbase.home ansible_connection=local
# All RaspberrPis
[raspi]
raspberrypi.home
raspborrypi.home
raspbirrypi.home
raspburrypi.home
raspbarrypi.home
blackberrypi.home
raspstrompi.home
Kleiner Sidehack noch am Rande; sollte Euch mal die Zeit völlig aus dem Ruder laufen und diese sich trotz hinterlegtem NTP Server nicht mehr einstellen, könnt ihr mit den folgenden Befehlen das Ganze per Workaround erstmal lösen.
pi@raspberrypi ~ $ sudo service ntp stop
pi@raspberrypi ~ $ sudo ntpd -gq
22 Feb 01:50:18 ntpd[21891]: ntpd 4.2.8p10@1.3728-o Sat Mar 10 18:03:33 UTC 2018 (1): Starting
22 Feb 01:50:18 ntpd[21891]: Command line: ntpd -gq
22 Feb 01:50:18 ntpd[21891]: proto: precision = 1.145 usec (-20)
22 Feb 01:50:18 ntpd[21891]: Listen and drop on 0 v6wildcard [::]:123
22 Feb 01:50:18 ntpd[21891]: Listen and drop on 1 v4wildcard 0.0.0.0:123
22 Feb 01:50:18 ntpd[21891]: Listen normally on 2 lo 127.0.0.1:123
22 Feb 01:50:18 ntpd[21891]: Listen normally on 3 eth0 192.168.1.113:123
22 Feb 01:50:18 ntpd[21891]: Listen normally on 4 lo [::1]:123
22 Feb 01:50:18 ntpd[21891]: Listen normally on 5 eth0 [2003:c9:b702:26be:ba27:ebff:fec6:809c]:123
22 Feb 01:50:18 ntpd[21891]: Listen normally on 6 eth0 [fe80::ba27:ebff:fec6:809c%2]:123
22 Feb 01:50:18 ntpd[21891]: Listening on routing socket on fd #23 for interface updates
22 Feb 01:50:19 ntpd[21891]: Soliciting pool server 173.212.192.154
22 Feb 01:50:20 ntpd[21891]: Soliciting pool server 195.201.163.190
22 Feb 01:50:20 ntpd[21891]: Soliciting pool server 144.76.0.164
22 Feb 01:50:21 ntpd[21891]: Soliciting pool server 46.165.252.57
22 Feb 01:50:21 ntpd[21891]: Soliciting pool server 176.9.166.35
22 Feb 01:50:21 ntpd[21891]: Soliciting pool server 2001:418:3ff::53
22 Feb 01:50:22 ntpd[21891]: Soliciting pool server 2001:638:504:2000::34
22 Feb 01:50:22 ntpd[21891]: Soliciting pool server 194.25.134.196
22 Feb 01:50:22 ntpd[21891]: Soliciting pool server 80.153.195.191
22 Feb 01:50:22 ntpd[21891]: Soliciting pool server 37.221.193.210
22 Feb 01:50:23 ntpd[21891]: Soliciting pool server 116.202.222.249
22 Feb 01:50:23 ntpd[21891]: Soliciting pool server 2a01:4f9:c010:bf3::2
22 Feb 01:50:23 ntpd[21891]: Soliciting pool server 3.121.254.221
22 Feb 01:50:23 ntpd[21891]: Soliciting pool server 162.159.200.123
22 Feb 01:50:24 ntpd[21891]: Soliciting pool server 185.11.138.90
22 Feb 01:50:24 ntpd[21891]: Soliciting pool server 2a03:4000:27:602:d4cf:50ff:fedb:b65a
22 Feb 01:50:24 ntpd[21891]: Soliciting pool server 213.209.109.44
22 Feb 01:50:27 ntpd[21891]: ntpd: time slew +0.009508 s
ntpd: time slew +0.009508s
pi@raspberrypi ~ $ sudo service ntp start
Das -gq weist den ntp-Daemon an, die Zeit ungeachtet des Offsets (g) zu korrigieren und sofort zu beenden (q), nachdem die Zeit eingestellt wurde.
Bei Wiederholung der Zeitprobleme müsst ihr in die Analyse gehen, wo die eigentliche Ursache für das Problem liegt.