nut for pikvm

main
Ricard Illa 2023-01-25 17:01:36 +01:00
parent 103834c6f3
commit d4eee168fa
6 changed files with 58 additions and 9 deletions

View File

@ -166,8 +166,9 @@
- name: set up NUT - name: set up NUT
hosts: hosts:
- suricata
- narwhal - narwhal
- pikvm
- suricata
become: true become: true
roles: roles:
- nut - nut

View File

@ -11,6 +11,23 @@ all:
dags: dags:
- acme_rsync - acme_rsync
nut_mode: netclient
nut_upsmon_password: !vault |
$ANSIBLE_VAULT;1.1;AES256
313636333565356536333862386361393439666563353938343934623532366
433363738623862623035663138643532346330346339376437353563633365
320a33356464656230316565376339333331373832643631366562666331333
137386235666437663766313833616135303339643539353931313966623638
3962360a3131383461393435633363366437663535306430343631313935343
465343465343038383961306132653066643933646237313234326435663834
3865663534
nut_device:
name: "cps-homelab"
nut_host: "nut.monotremata.xyz"
snitch: snitch:
ansible_host: snitch ansible_host: snitch
ansible_user: ansible ansible_user: ansible

View File

@ -5,11 +5,10 @@
name: nut name: nut
when: ansible_distribution == "Alpine" when: ansible_distribution == "Alpine"
- name: keep nut-server uninstalled from Debian/Ubuntu in client mode - name: install NUT for Arch
apt: pacman:
name: nut-server name: nut
state: absent when: ansible_distribution == "Archlinux"
when: ansible_distribution in ["Debian", "Ubuntu"] and nut_mode == "netclient"
- name: set NUT mode - name: set NUT mode
lineinfile: lineinfile:
@ -17,6 +16,10 @@
regexp: '^MODE=' regexp: '^MODE='
line: "MODE={{ nut_mode }}" line: "MODE={{ nut_mode }}"
- name: prevent nut-server when using netclient mode
include_tasks: netclient.yml
when: nut_mode == "netclient"
- name: set up upsd - name: set up upsd
include_tasks: upsd.yml include_tasks: upsd.yml
when: nut_mode in ["standalone", "netserver"] when: nut_mode in ["standalone", "netserver"]

View File

@ -0,0 +1,14 @@
---
- name: keep nut-server uninstalled from Debian/Ubuntu in client mode
apt:
name: nut-server
state: absent
when: ansible_distribution in ["Debian", "Ubuntu"]
- name: mask nut-server when using client-only with Arch
systemd:
name: nut-server
state: stopped
masked: true
when: ansible_distribution == "Archlinux"

View File

@ -34,3 +34,17 @@
state: started state: started
enabled: true enabled: true
when: ansible_distribution == "Alpine" when: ansible_distribution == "Alpine"
- name: start and enable nut-server
systemd:
name: nut-server
state: started
enabled: true
when: ansible_distribution in ["Debian", "Ubuntu"]
- name: start and enable nut-driver-enumerator
systemd:
name: nut-driver-enumerator
state: started
enabled: true
when: ansible_distribution == "Archlinux"

View File

@ -11,7 +11,7 @@
block: | block: |
MONITOR {{ nut_device.name }}@{{ nut_host }} 1 upsmon {{ nut_upsmon_password }} {{ nut_types[nut_mode] }} MONITOR {{ nut_device.name }}@{{ nut_host }} 1 upsmon {{ nut_upsmon_password }} {{ nut_types[nut_mode] }}
- name: start and enable nut-upsmon - name: start and enable nut-upsmon with openrc
service: service:
name: nut-upsmon name: nut-upsmon
runlevel: default runlevel: default
@ -19,9 +19,9 @@
enabled: true enabled: true
when: ansible_distribution == "Alpine" when: ansible_distribution == "Alpine"
- name: start and enable nut-monitor - name: start and enable nut-monitor with systemd
systemd: systemd:
name: nut-monitor name: nut-monitor
state: started state: started
enabled: true enabled: true
when: ansible_distribution in ["Debian", "Ubuntu"] when: ansible_distribution in ["Debian", "Ubuntu", "Archlinux"]