nut for narwhal

main
Ricard Illa 2023-01-25 15:55:20 +01:00
parent 3053ddd02c
commit 103834c6f3
6 changed files with 51 additions and 12 deletions

View File

@ -167,6 +167,7 @@
- name: set up NUT - name: set up NUT
hosts: hosts:
- suricata - suricata
- narwhal
become: true become: true
roles: roles:
- nut - nut

View File

@ -173,7 +173,7 @@ all:
- "hdmi_mode=4" - "hdmi_mode=4"
nut_device: nut_device:
name: nutdev1 name: "cps-homelab"
config: config:
driver: "usbhid-ups" driver: "usbhid-ups"
port: "auto" port: "auto"
@ -204,6 +204,8 @@ all:
465343465343038383961306132653066643933646237313234326435663834 465343465343038383961306132653066643933646237313234326435663834
3865663534 3865663534
nut_host: localhost
caladan: caladan:
ansible_host: caladan ansible_host: caladan
ansible_user: ansible ansible_user: ansible
@ -223,6 +225,23 @@ all:
ansible_python_interpreter: /usr/bin/python3 ansible_python_interpreter: /usr/bin/python3
ansible_become_method: doas ansible_become_method: doas
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"
fugu: fugu:
ansible_host: fugu ansible_host: fugu
ansible_user: ansible ansible_user: ansible

View File

@ -1,23 +1,22 @@
--- ---
- name: install NUT for alpine - name: install NUT for Alpine
apk: apk:
name: name: nut
- nut
when: ansible_distribution == "Alpine" when: ansible_distribution == "Alpine"
- name: keep nut-server uninstalled from Debian/Ubuntu in client mode
apt:
name: nut-server
state: absent
when: ansible_distribution in ["Debian", "Ubuntu"] and nut_mode == "netclient"
- name: set NUT mode - name: set NUT mode
lineinfile: lineinfile:
path: /etc/nut/nut.conf path: /etc/nut/nut.conf
regexp: '^MODE=' regexp: '^MODE='
line: "MODE={{ nut_mode }}" line: "MODE={{ nut_mode }}"
- name: set up /etc/nut/upsmon.conf
blockinfile:
path: /etc/nut/upsmon.conf
block: |
MONITOR {{ nut_device.name }} 1 {{ nut_upsmon_password }} {{ nut_types[nut_mode] }}
- 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

@ -1,5 +1,11 @@
--- ---
- name: install server for Debian / Ubuntu
apt:
name:
- nut-server
when: ansible_distribution in ["Debian", "Ubuntu"]
- name: add UPS device(s) config to /etc/nut/ups.conf - name: add UPS device(s) config to /etc/nut/ups.conf
blockinfile: blockinfile:
path: /etc/nut/ups.conf path: /etc/nut/ups.conf

View File

@ -1,10 +1,15 @@
--- ---
- name: install client for Debian / Ubuntu
apt:
name: nut-client
when: ansible_distribution in ["Debian", "Ubuntu"]
- name: set up /etc/nut/upsmon.conf - name: set up /etc/nut/upsmon.conf
blockinfile: blockinfile:
path: /etc/nut/upsmon.conf path: /etc/nut/upsmon.conf
block: | block: |
MONITOR {{ nut_device.name }} 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
service: service:
@ -13,3 +18,10 @@
state: started state: started
enabled: true enabled: true
when: ansible_distribution == "Alpine" when: ansible_distribution == "Alpine"
- name: start and enable nut-monitor
systemd:
name: nut-monitor
state: started
enabled: true
when: ansible_distribution in ["Debian", "Ubuntu"]

View File

@ -1,4 +1,6 @@
---
nut_types: nut_types:
standalone: primary standalone: primary
netserver: primary netserver: primary
clientserver: secondary netclient: secondary