diff --git a/README.md b/README.md index 44f36a1..0170283 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,14 @@ ansible role: akku warning ========================== +# rewrite in progress!!! +``` +cronjob is going to be removed! +systemd timer intruduces +variables may change! +``` + + This ansible role installs a bash script (per cronjob) which is executed every 3 minutes. This bash script checks if the battery level is below 25 percent and is currently not charging. If this is the case, the program [zenity](https://de.wikipedia.org/wiki/Zenity) installed by this role will generate a popup message stating that the battery is low. While the battery level is between 15 and 10 percent, it will also attempt to play a sound. But this does not (yet) work reliably. diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..59624e1 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,18 @@ +--- +- name: systemctl daemon-reload + become: true + ansible.builtin.systemd: + daemon_reload: true + +- name: systemctl start battery_check.service + become: true + ansible.builtin.systemd: + name: 'battery_check.service' + state: started + +- name: systemctl enable battery_check.timer + become: true + ansible.builtin.systemd: + name: 'battery_check.timer' + enabled: true + state: started diff --git a/tasks/timer.yml b/tasks/timer.yml index c3aecce..080d718 100644 --- a/tasks/timer.yml +++ b/tasks/timer.yml @@ -1,12 +1,24 @@ --- -- name: Check akku every 3 minutes +- name: setup battery_check.service become: true - ansible.builtin.cron: - name: check if akku still okay - job: /opt/akku.sh - minute: '*/3' - user: '{{ akku_user }}' - cron_file: /etc/crontab - state: absent - failed_when: false + ansible.builtin.template: + src: 'templates/battery_check.service.j2' + dest: '/usr/lib/systemd/system/battery_check.service' + mode: 0755 + owner: root + group: root + notify: + - systemctl daemon-reload + - systemctl start battery_check.service +- name: setup battery_check.timer + become: true + ansible.builtin.template: + src: 'templates/battery_check.timer.j2' + dest: '/usr/lib/systemd/system/battery_check.timer' + mode: 0755 + owner: root + group: root + notify: + - systemctl daemon-reload + - systemctl enable battery_check.timer diff --git a/templates/battery_check.service.j2 b/templates/battery_check.service.j2 new file mode 100644 index 0000000..1ad2514 --- /dev/null +++ b/templates/battery_check.service.j2 @@ -0,0 +1,10 @@ +[Unit] +Description=Check battery charging status + +[Service] +Type=simple +ExecStart=/opt/akku.sh +User={{ akku_user }} + +[Install] +WantedBy=multi-user.target diff --git a/templates/battery_check.timer.j2 b/templates/battery_check.timer.j2 new file mode 100644 index 0000000..0f7745c --- /dev/null +++ b/templates/battery_check.timer.j2 @@ -0,0 +1,5 @@ +[Unit] +Description=Check battery charging status every 3 Minutes + +[Timer] +OnCalendar=*:0/3 diff --git a/vars/main.yml b/vars/main.yml index 6d8c4bf..8e9a8b4 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,3 +1,3 @@ --- -playbook_version_number: 8175 +playbook_version_number: 8176 playbook_version_path: 'role-akku-warning_chaos-bodensee_github.com.version'