Collect some general tasks from other roles into role_misc
Control execution of task by variables with defaults.
This commit is contained in:
parent
a8736395c8
commit
5b19a529f2
14 changed files with 659 additions and 612 deletions
|
@ -1,18 +0,0 @@
|
|||
#!/usr/bin/bash
|
||||
#
|
||||
# fix boot order: first PXE, then Debian
|
||||
#
|
||||
set -eu
|
||||
|
||||
cur="$(efibootmgr | grep -Ei 'BootOrder:' | \
|
||||
sed -E 's/^BootOrder: ([[:xdigit:]]{4}),.+$/\1/')"
|
||||
pxeip4="$(efibootmgr | grep -Ei "IP.*4" | \
|
||||
sed -E 's/^Boot([[:xdigit:]]{4}).+$/\1/')"
|
||||
debian="$(efibootmgr | grep -Ei "debian" | \
|
||||
sed -E 's/^Boot([[:xdigit:]]{4}).+$/\1/')"
|
||||
|
||||
if [[ "$cur" != "$pxeip4" ]] && [[ -n "$pxeip4" ]] && [[ -n "$debian" ]] ; then
|
||||
efibootmgr -o $pxeip4,$debian
|
||||
else
|
||||
echo "Nothing to do."
|
||||
fi
|
|
@ -1,48 +0,0 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# logout idle users and shutdown machine
|
||||
#
|
||||
set -eu
|
||||
|
||||
action="systemctl poweroff"
|
||||
uptime=$(cat /proc/uptime | cut -f1 -d.)
|
||||
maxidle=3600 ## seconds
|
||||
|
||||
u=($(loginctl list-users --no-legend | sort -hr | head -1))
|
||||
una=${u[1]:-''}
|
||||
uid=${u[0]:-''}
|
||||
|
||||
talk2dbus() {
|
||||
local display=":$(ls /tmp/.X11-unix/* | sed 's#/tmp/.X11-unix/X##' | head -n 1)"
|
||||
sudo -u $una DISPLAY=$display \
|
||||
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$uid/bus "$@"
|
||||
}
|
||||
|
||||
########
|
||||
|
||||
## shutdown if nobody is loged in:
|
||||
if [[ -z "$una" ]] || [[ $uid -lt 1000 ]] ; then
|
||||
exec $action
|
||||
fi
|
||||
|
||||
# FIXME: find idle time independent of running screensaver
|
||||
if ! t=$(talk2dbus qdbus org.kde.screensaver /ScreenSaver GetActiveTime) ; then
|
||||
echo "No graphical logins found."
|
||||
else
|
||||
idle=$(( t / 1000 ))
|
||||
if [[ $idle -gt $maxidle ]] && [[ ! -d "/srv/samba/schools/default-school/teachers/" ]] ; then
|
||||
talk2dbus notify-send -i system-shutdown -u critical -a 'Important System Information' \
|
||||
'Please log out, the system will shut down soon!' \
|
||||
'There has been no activity for too long.'
|
||||
## shutdown:
|
||||
#talk2dbus qdbus org.kde.ksmserver /KSMServer logout 1 2 0
|
||||
## logout:
|
||||
talk2dbus qdbus org.kde.ksmserver /KSMServer logout 1 0 0 || \
|
||||
loginctl terminate-user $una
|
||||
echo "Log-out user $una after being idle for $idle seconds."
|
||||
else
|
||||
echo "The user $una has been idle for $idle seconds."
|
||||
fi
|
||||
fi
|
||||
|
||||
#w -s | grep tty | sed "s/[[:space:]]\+/ /g" | cut -f4 -d ' '
|
|
@ -1,6 +0,0 @@
|
|||
[Unit]
|
||||
Description=Run pwroff script
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/local/sbin/pwroff
|
|
@ -1,9 +0,0 @@
|
|||
[Unit]
|
||||
Description=Run pwroff script every 15 min after 90 min uptime
|
||||
|
||||
[Timer]
|
||||
OnBootSec=90min
|
||||
OnUnitActiveSec=15min
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
|
@ -1,33 +0,0 @@
|
|||
#!/usr/bin/bash
|
||||
#
|
||||
# Send stdout of some commands to monitoring server.
|
||||
# Collect the reports with 'nc -u -k -l 1234' on 'sendto'.
|
||||
# Use /bin/nc.openbsd, /bin/nc.traditional seems not to work.
|
||||
#
|
||||
set -eu
|
||||
|
||||
sendto="collector.steinbeis.schule 1234"
|
||||
n=0
|
||||
|
||||
cmds=(
|
||||
'uname -a'
|
||||
'tail -1 /var/local/ansible-stamps'
|
||||
'ip route list default'
|
||||
'ip link show | \
|
||||
sed -nE -e "s/^[2-9]: (\S+): .+/\1/p" -e "s/.+ether ([0-9a-f:]+) .+/\1/p" | \
|
||||
paste - -'
|
||||
)
|
||||
# 'w'
|
||||
# 'uptime'
|
||||
# 'ls -d --full-time /home/ansible/.ansible/tmp/'
|
||||
# 'ip addr show'
|
||||
# 'apt list --upgradeable -o Apt::Cmd::Disable-Script-Warning=true'
|
||||
|
||||
r="$HOSTNAME ------- $(date --rfc-3339=seconds) -------
|
||||
$(for c in "${cmds[@]}" ; do
|
||||
n=$(( n + 1 ))
|
||||
echo -n "$n"
|
||||
eval "$c" | sed 's/^/\t/'
|
||||
done | sed "s/^/$HOSTNAME /")
|
||||
## -------------------------------------------------"
|
||||
echo "$r" | nc -w 1 -u $sendto
|
|
@ -1,6 +0,0 @@
|
|||
[Unit]
|
||||
Description=Run reporting script
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/local/sbin/reporter
|
|
@ -1,9 +0,0 @@
|
|||
[Unit]
|
||||
Description=Run reporter script every 15 min
|
||||
|
||||
[Timer]
|
||||
OnBootSec=5min
|
||||
OnUnitActiveSec=15min
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
|
@ -139,49 +139,6 @@
|
|||
"ProxyMode": "auto_detect"
|
||||
}
|
||||
|
||||
- name: Update all packages unattended
|
||||
ansible.builtin.replace:
|
||||
path: /etc/apt/apt.conf.d/50unattended-upgrades
|
||||
regexp: '^//(\s+"origin=.+-updates";)$'
|
||||
replace: ' \1'
|
||||
|
||||
- name: Copy some scripts
|
||||
ansible.builtin.copy:
|
||||
src: "{{ item }}"
|
||||
dest: /usr/local/sbin/
|
||||
mode: '0755'
|
||||
loop:
|
||||
- pwroff
|
||||
- bootorder.sh
|
||||
- reporter
|
||||
|
||||
- name: Provide services and timers for some scripts
|
||||
ansible.builtin.copy:
|
||||
src: "{{ item }}"
|
||||
dest: "/etc/systemd/system/{{ item }}"
|
||||
mode: '0644'
|
||||
loop:
|
||||
- pwroff.service
|
||||
- pwroff.timer
|
||||
- reporter.service
|
||||
- reporter.timer
|
||||
when: "'teacherlaptop' not in group_names"
|
||||
|
||||
- name: Enable pwroff.timer
|
||||
ansible.builtin.systemd:
|
||||
name: "{{ item }}"
|
||||
enabled: true
|
||||
loop:
|
||||
- pwroff.timer
|
||||
- reporter.timer
|
||||
when: "'teacherlaptop' not in group_names"
|
||||
|
||||
- name: PXE first boot order
|
||||
ansible.builtin.command: /usr/local/sbin/bootorder.sh
|
||||
register: cmd_result
|
||||
changed_when: cmd_result.stdout is not search('Nothing to do.')
|
||||
when: "'PCroom' in group_names"
|
||||
|
||||
- name: Copy dolphin config scripts
|
||||
ansible.builtin.copy:
|
||||
src: "{{ item }}"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue