From 103834c6f3dfe64aa5f6d5624c09913f17db1b0f Mon Sep 17 00:00:00 2001 From: Ricard Illa Date: Wed, 25 Jan 2023 15:55:20 +0100 Subject: [PATCH] nut for narwhal --- deploy.yml | 1 + hosts.yml | 21 ++++++++++++++++++++- roles/nut/tasks/main.yml | 17 ++++++++--------- roles/nut/tasks/upsd.yml | 6 ++++++ roles/nut/tasks/upsmon.yml | 14 +++++++++++++- roles/nut/vars/main.yml | 4 +++- 6 files changed, 51 insertions(+), 12 deletions(-) diff --git a/deploy.yml b/deploy.yml index 06ea4b7..470db58 100644 --- a/deploy.yml +++ b/deploy.yml @@ -167,6 +167,7 @@ - name: set up NUT hosts: - suricata + - narwhal become: true roles: - nut diff --git a/hosts.yml b/hosts.yml index efb9ed6..8a57679 100644 --- a/hosts.yml +++ b/hosts.yml @@ -173,7 +173,7 @@ all: - "hdmi_mode=4" nut_device: - name: nutdev1 + name: "cps-homelab" config: driver: "usbhid-ups" port: "auto" @@ -204,6 +204,8 @@ all: 465343465343038383961306132653066643933646237313234326435663834 3865663534 + nut_host: localhost + caladan: ansible_host: caladan ansible_user: ansible @@ -223,6 +225,23 @@ all: ansible_python_interpreter: /usr/bin/python3 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: ansible_host: fugu ansible_user: ansible diff --git a/roles/nut/tasks/main.yml b/roles/nut/tasks/main.yml index 1db9a7f..c2111d2 100644 --- a/roles/nut/tasks/main.yml +++ b/roles/nut/tasks/main.yml @@ -1,23 +1,22 @@ --- -- name: install NUT for alpine +- name: install NUT for Alpine apk: - name: - - nut + name: nut 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 lineinfile: path: /etc/nut/nut.conf regexp: '^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 include_tasks: upsd.yml when: nut_mode in ["standalone", "netserver"] diff --git a/roles/nut/tasks/upsd.yml b/roles/nut/tasks/upsd.yml index ddfdc8b..069c9d8 100644 --- a/roles/nut/tasks/upsd.yml +++ b/roles/nut/tasks/upsd.yml @@ -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 blockinfile: path: /etc/nut/ups.conf diff --git a/roles/nut/tasks/upsmon.yml b/roles/nut/tasks/upsmon.yml index 53d8057..ca2bfce 100644 --- a/roles/nut/tasks/upsmon.yml +++ b/roles/nut/tasks/upsmon.yml @@ -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 blockinfile: path: /etc/nut/upsmon.conf 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 service: @@ -13,3 +18,10 @@ state: started enabled: true when: ansible_distribution == "Alpine" + +- name: start and enable nut-monitor + systemd: + name: nut-monitor + state: started + enabled: true + when: ansible_distribution in ["Debian", "Ubuntu"] diff --git a/roles/nut/vars/main.yml b/roles/nut/vars/main.yml index 3a82dca..8cd8767 100644 --- a/roles/nut/vars/main.yml +++ b/roles/nut/vars/main.yml @@ -1,4 +1,6 @@ +--- + nut_types: standalone: primary netserver: primary - clientserver: secondary + netclient: secondary