1
0
Fork 0
mirror of https://github.com/roles-ansible/role_akku_warning.git synced 2024-08-16 10:09:50 +02:00

Create ansible submodule for akku warning

This commit is contained in:
L3D 2019-04-07 18:52:35 +02:00
parent 517c5704ce
commit ecf6ae5594
4 changed files with 77 additions and 0 deletions

8
defaults/main.yml Normal file
View file

@ -0,0 +1,8 @@
---
# should we install cronie?
install_and_enable_cronie: false
# play a video in the background with sound
multimedia_akku_warning: true

14
files/akku.sh Normal file
View file

@ -0,0 +1,14 @@
#!/bin/bash
power="$((`cat /sys/class/power_supply/BAT0/energy_now` * 100 / `cat /sys/class/power_supply/BAT0/energy_full_design`))"
if (( $power < 25 && $power > 15 )); then
zenity --warning --title="Low Power" --text="$power percent remaining.\n\nPlease recharge soon!" --display=:0.0
elif (( $power < 15 && $power > 9 )); then
zenity --warning --title="Low Power" --text="$power percent remaining.\n\nPlease recharge soon!" --display=:0.0
mpv /opt/low_battery.mkv -fs --volume 130 --start 00:00:18 --vo=tct > /dev/null
elif (( $power < 9 && $power > 5 )); then
zenity --warning --title="Critical Power" --text="$power percent remaining.\n\nPlease recharge NOW!" --display=:0.0
elif (( $power < 5 )); then
zenity --warning --title="Critical Power" --text="$power percent remaining.\n\nRECHARGE!\nNOW!" --display=:0.0
fi

BIN
files/low_battery.mkv Normal file

Binary file not shown.

55
tasks/main.yml Normal file
View file

@ -0,0 +1,55 @@
---
- name: copy sound warning script
become: yes
copy:
src: 'files/akku.sh'
dest: '/opt/akku.sh'
owner: 'root'
group: 'root'
mode: '0755'
- name: copy sound warning video
become: yes
copy:
src: 'files/low_battery.mkv'
dest: '/opt/low_battery.mkv'
owner: 'root'
group: 'root'
mode: '0644'
when: multimedia_akku_warning
- name: install zenity and mpv for notifications
become: yes
package:
name:
- zenity
- mpv
state: present
- name: Check akku every 2 minutes
become: yes
cron:
name: check if akku still okay
job: /opt/akku.sh
minute: '*/3'
user: '{{ user }}'
cron_file: /etc/crontab
- name: Make sure cron is installed
become: true
when: install_and_enable_cronie
package:
name:
- cronie
state: present
- name: Make sure cron is running
become: true
when: install_and_enable_cronie
systemd:
name: cronie.service
state: started
enabled: yes
daemon_reload: yes