Skip to content

Commit 24f4ab4

Browse files
authored
Merge pull request #625 from codemeister64/apcupsd-role
Add Apcupsd role
2 parents ed70b95 + 372851a commit 24f4ab4

File tree

10 files changed

+487
-0
lines changed

10 files changed

+487
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ If you have a spare domain name you can configure applications to be accessible
1818
## Available Applications
1919

2020
* [Airsonic](https://airsonic.github.io/) - catalog and stream music
21+
* [Apcupsd](http://www.apcupsd.org/) - A daemon for controlling APC UPSes
2122
* [Bazarr](https://github.com/morpheus65535/bazarr) - companion to Radarr and Sonarr for downloading subtitles
2223
* [Bitwarden](https://github.com/dani-garcia/vaultwarden) - Password Manger (Technically Vaultwarden, a lightweight implementation in Rust)
2324
* [Booksonic](https://booksonic.org/) - The selfhosted audiobook server

nas.yml

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@
5757
tags:
5858
- airsonic
5959

60+
- role: apcupsd
61+
tags:
62+
- apcupsd
63+
6064
- role: bazarr
6165
tags:
6266
- bazarr

roles/apcupsd/defaults/main.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
apcupsd_enabled: false
3+
4+
# directories
5+
apcupsd_data_directory: "{{ docker_home }}/apcupsd"
6+
7+
# network
8+
apcupsd_port: "3551"
9+
10+
# specs
11+
apcupsd_memory: 1g
12+
13+
# docker
14+
apcupsd_container_name: apcupsd
15+
16+
# ups config
17+
apcupsd_onbatterydelay: 6
18+
apcupsd_batterylevel: 5
19+
apcupsd_minutes: 5
20+
apcupsd_timeout: 0
21+
apcupsd_annoy: 300
22+
apcupsd_annoydelay: 60
23+
apcupsd_nologon: "disable"
24+
apcupsd_killdelay: 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
provisioner:
3+
inventory:
4+
group_vars:
5+
all:
6+
apcupsd_enabled: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
- name: Stop
3+
hosts: all
4+
become: true
5+
tasks:
6+
- name: "Include {{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }} role"
7+
include_role:
8+
name: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}"
9+
vars:
10+
apcupsd_enabled: false
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
- name: Verify
3+
hosts: all
4+
gather_facts: false
5+
tasks:
6+
- include_vars:
7+
file: ../../defaults/main.yml
8+
9+
- name: Get container state
10+
docker_container_info:
11+
name: "{{ apcupsd_container_name }}"
12+
register: result
13+
14+
- name: Check Apcupsd is running
15+
assert:
16+
that:
17+
- result.container['State']['Status'] == "running"
18+
- result.container['State']['Restarting'] == false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
- name: Verify
3+
hosts: all
4+
gather_facts: false
5+
tasks:
6+
- include_vars:
7+
file: ../../defaults/main.yml
8+
9+
- name: Try and stop and remove Apcupsd
10+
docker_container:
11+
name: "{{ apcupsd_container_name }}"
12+
state: absent
13+
register: result
14+
15+
- name: Check Apcupsd is stopped
16+
assert:
17+
that:
18+
- not result.changed

roles/apcupsd/tasks/main.yml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
3+
- name: Start Apcupsd
4+
block:
5+
- name: Create Apcupsd Directories
6+
ansible.builtin.file:
7+
path: "{{ item }}"
8+
state: directory
9+
with_items:
10+
- "{{ apcupsd_data_directory }}"
11+
12+
- name: "Check if Apcupsd config exists"
13+
ansible.builtin.stat:
14+
path: "{{ apcupsd_data_directory }}/apcupsd.conf"
15+
register: apcupsd_config_path
16+
17+
- name: Template Apcupsd config
18+
ansible.builtin.template:
19+
src: apcupsd.conf
20+
dest: "{{ apcupsd_data_directory }}/apcupsd.conf"
21+
when: not apcupsd_config_path.stat.exists
22+
23+
- name: Apcupsd Docker Container
24+
community.docker.docker_container:
25+
name: "{{ apcupsd_container_name }}"
26+
image: gregewing/apcupsd
27+
pull: true
28+
privileged: true
29+
volumes:
30+
- "/var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket"
31+
- "{{ apcupsd_data_directory }}/apcupsd.conf:/etc/apcupsd/apcupsd.conf"
32+
ports:
33+
- "{{ apcupsd_port }}:3551"
34+
devices:
35+
- "{{ apcupsd_device }}:{{ apcupsd_device }}"
36+
env:
37+
TZ: "{{ ansible_nas_timezone }}"
38+
restart_policy: unless-stopped
39+
memory: "{{ apcupsd_memory }}"
40+
when: apcupsd_enabled is true
41+
42+
- name: Stop Apcupsd
43+
block:
44+
- name: Stop Apcupsd
45+
community.docker.docker_container:
46+
name: "{{ apcupsd_container_name }}"
47+
state: absent
48+
when: apcupsd_enabled is false

0 commit comments

Comments
 (0)