Pull-Mechanik: local.yml, schul-pull.sh, systemd-Units
Laptops ziehen sich das Repo selbst (HTTPS via git.lehrstun.de, SSH-Fallback mit Deploy-Key) und fuehren local.yml aus. Timer laeuft bei Boot + alle 30 min. local.yml haelt die Mechanik selbst aktuell. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
8
files/ansible-pull.service
Normal file
8
files/ansible-pull.service
Normal file
@@ -0,0 +1,8 @@
|
||||
[Unit]
|
||||
Description=Schul-Laptops: Konfiguration per ansible-pull aktualisieren
|
||||
Wants=network-online.target
|
||||
After=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/local/bin/schul-pull.sh
|
||||
11
files/ansible-pull.timer
Normal file
11
files/ansible-pull.timer
Normal file
@@ -0,0 +1,11 @@
|
||||
[Unit]
|
||||
Description=Schul-Laptops: regelmaessiger ansible-pull (Boot + alle 30 min)
|
||||
|
||||
[Timer]
|
||||
OnBootSec=2min
|
||||
OnUnitActiveSec=30min
|
||||
RandomizedDelaySec=5min
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
24
files/schul-pull.sh
Normal file
24
files/schul-pull.sh
Normal file
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Zieht das schul-laptops-Repo und fuehrt local.yml aus.
|
||||
# HTTPS zuerst (funktioniert auch im Schulnetz), SSH mit Deploy-Key als Fallback.
|
||||
# Wird vom systemd-Timer (ansible-pull.timer) als root aufgerufen.
|
||||
#
|
||||
set -u
|
||||
|
||||
HTTPS_URL="https://git.lehrstun.de/admin/schul-laptops.git"
|
||||
SSH_URL="ssh://git@46.225.114.15:2222/admin/schul-laptops.git"
|
||||
DEPLOY_KEY="/root/.ssh/ansible-pull-deploy"
|
||||
CHECKOUT="/var/lib/schul-laptops"
|
||||
|
||||
run_pull() {
|
||||
ansible-pull -U "$1" -d "$CHECKOUT" -c local -i localhost, local.yml
|
||||
}
|
||||
|
||||
if run_pull "$HTTPS_URL"; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "HTTPS fehlgeschlagen, versuche SSH-Fallback (Port 2222) ..." >&2
|
||||
export GIT_SSH_COMMAND="ssh -i $DEPLOY_KEY -p 2222 -o BatchMode=yes"
|
||||
run_pull "$SSH_URL"
|
||||
9
group_vars/all.yml
Normal file
9
group_vars/all.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
---
|
||||
# Software, die auf allen Schul-Laptops installiert sein soll.
|
||||
# Paket hier ergaenzen + pushen = wird auf allen Laptops installiert.
|
||||
schul_pakete:
|
||||
- htop
|
||||
- git
|
||||
- curl
|
||||
- vim
|
||||
- ansible
|
||||
63
local.yml
Normal file
63
local.yml
Normal file
@@ -0,0 +1,63 @@
|
||||
---
|
||||
# Wird per ansible-pull auf jedem Laptop lokal ausgefuehrt (via schul-pull.sh).
|
||||
# Aenderungen hier verteilen sich beim naechsten Timer-Lauf auf alle Laptops.
|
||||
- name: Schul-Laptop konfigurieren
|
||||
hosts: localhost
|
||||
connection: local
|
||||
become: true
|
||||
|
||||
tasks:
|
||||
- name: APT-Cache aktualisieren
|
||||
apt:
|
||||
update_cache: yes
|
||||
cache_valid_time: 3600
|
||||
|
||||
- name: System-Updates installieren (safe upgrade)
|
||||
apt:
|
||||
upgrade: safe
|
||||
|
||||
- name: Standard-Software installieren
|
||||
apt:
|
||||
name: "{{ schul_pakete }}"
|
||||
state: present
|
||||
|
||||
# --- Selbstverwaltung: haelt die Pull-Mechanik auf allen Laptops aktuell ---
|
||||
|
||||
- name: Pull-Script installieren
|
||||
copy:
|
||||
src: files/schul-pull.sh
|
||||
dest: /usr/local/bin/schul-pull.sh
|
||||
mode: "0755"
|
||||
|
||||
- name: systemd-Units fuer ansible-pull installieren
|
||||
copy:
|
||||
src: "files/{{ item }}"
|
||||
dest: "/etc/systemd/system/{{ item }}"
|
||||
mode: "0644"
|
||||
loop:
|
||||
- ansible-pull.service
|
||||
- ansible-pull.timer
|
||||
register: units
|
||||
|
||||
- name: systemd neu laden, falls Units geaendert
|
||||
systemd:
|
||||
daemon_reload: yes
|
||||
when: units.changed
|
||||
|
||||
- name: ansible-pull.timer aktivieren
|
||||
systemd:
|
||||
name: ansible-pull.timer
|
||||
enabled: yes
|
||||
state: started
|
||||
|
||||
# --- Status melden ---
|
||||
|
||||
- name: Pruefen ob ein Neustart noetig ist
|
||||
stat:
|
||||
path: /var/run/reboot-required
|
||||
register: reboot_required
|
||||
|
||||
- name: Neustart-Hinweis ins Log schreiben
|
||||
debug:
|
||||
msg: "ACHTUNG: Neustart erforderlich (wird nicht automatisch ausgefuehrt)."
|
||||
when: reboot_required.stat.exists
|
||||
Reference in New Issue
Block a user