Skip to content

Commit

Permalink
Merge pull request #625 from codemeister64/apcupsd-role
Browse files Browse the repository at this point in the history
Add Apcupsd role
  • Loading branch information
davestephens authored Oct 9, 2024
2 parents ed70b95 + 372851a commit 24f4ab4
Show file tree
Hide file tree
Showing 10 changed files with 487 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ If you have a spare domain name you can configure applications to be accessible
## Available Applications

* [Airsonic](https://airsonic.github.io/) - catalog and stream music
* [Apcupsd](http://www.apcupsd.org/) - A daemon for controlling APC UPSes
* [Bazarr](https://github.com/morpheus65535/bazarr) - companion to Radarr and Sonarr for downloading subtitles
* [Bitwarden](https://github.com/dani-garcia/vaultwarden) - Password Manger (Technically Vaultwarden, a lightweight implementation in Rust)
* [Booksonic](https://booksonic.org/) - The selfhosted audiobook server
Expand Down
4 changes: 4 additions & 0 deletions nas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
tags:
- airsonic

- role: apcupsd
tags:
- apcupsd

- role: bazarr
tags:
- bazarr
Expand Down
24 changes: 24 additions & 0 deletions roles/apcupsd/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
apcupsd_enabled: false

# directories
apcupsd_data_directory: "{{ docker_home }}/apcupsd"

# network
apcupsd_port: "3551"

# specs
apcupsd_memory: 1g

# docker
apcupsd_container_name: apcupsd

# ups config
apcupsd_onbatterydelay: 6
apcupsd_batterylevel: 5
apcupsd_minutes: 5
apcupsd_timeout: 0
apcupsd_annoy: 300
apcupsd_annoydelay: 60
apcupsd_nologon: "disable"
apcupsd_killdelay: 0
6 changes: 6 additions & 0 deletions roles/apcupsd/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
provisioner:
inventory:
group_vars:
all:
apcupsd_enabled: true
10 changes: 10 additions & 0 deletions roles/apcupsd/molecule/default/side_effect.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: Stop
hosts: all
become: true
tasks:
- name: "Include {{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }} role"
include_role:
name: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}"
vars:
apcupsd_enabled: false
18 changes: 18 additions & 0 deletions roles/apcupsd/molecule/default/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
- name: Verify
hosts: all
gather_facts: false
tasks:
- include_vars:
file: ../../defaults/main.yml

- name: Get container state
docker_container_info:
name: "{{ apcupsd_container_name }}"
register: result

- name: Check Apcupsd is running
assert:
that:
- result.container['State']['Status'] == "running"
- result.container['State']['Restarting'] == false
18 changes: 18 additions & 0 deletions roles/apcupsd/molecule/default/verify_stopped.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
- name: Verify
hosts: all
gather_facts: false
tasks:
- include_vars:
file: ../../defaults/main.yml

- name: Try and stop and remove Apcupsd
docker_container:
name: "{{ apcupsd_container_name }}"
state: absent
register: result

- name: Check Apcupsd is stopped
assert:
that:
- not result.changed
48 changes: 48 additions & 0 deletions roles/apcupsd/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---

- name: Start Apcupsd
block:
- name: Create Apcupsd Directories
ansible.builtin.file:
path: "{{ item }}"
state: directory
with_items:
- "{{ apcupsd_data_directory }}"

- name: "Check if Apcupsd config exists"
ansible.builtin.stat:
path: "{{ apcupsd_data_directory }}/apcupsd.conf"
register: apcupsd_config_path

- name: Template Apcupsd config
ansible.builtin.template:
src: apcupsd.conf
dest: "{{ apcupsd_data_directory }}/apcupsd.conf"
when: not apcupsd_config_path.stat.exists

- name: Apcupsd Docker Container
community.docker.docker_container:
name: "{{ apcupsd_container_name }}"
image: gregewing/apcupsd
pull: true
privileged: true
volumes:
- "/var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket"
- "{{ apcupsd_data_directory }}/apcupsd.conf:/etc/apcupsd/apcupsd.conf"
ports:
- "{{ apcupsd_port }}:3551"
devices:
- "{{ apcupsd_device }}:{{ apcupsd_device }}"
env:
TZ: "{{ ansible_nas_timezone }}"
restart_policy: unless-stopped
memory: "{{ apcupsd_memory }}"
when: apcupsd_enabled is true

- name: Stop Apcupsd
block:
- name: Stop Apcupsd
community.docker.docker_container:
name: "{{ apcupsd_container_name }}"
state: absent
when: apcupsd_enabled is false
Loading

0 comments on commit 24f4ab4

Please sign in to comment.