From d4eee168fa72f1c6d4c5bf74d0bfc9b78bac222c Mon Sep 17 00:00:00 2001 From: Ricard Illa Date: Wed, 25 Jan 2023 17:01:36 +0100 Subject: [PATCH] nut for pikvm --- deploy.yml | 3 ++- hosts.yml | 17 +++++++++++++++++ roles/nut/tasks/main.yml | 13 ++++++++----- roles/nut/tasks/netclient.yml | 14 ++++++++++++++ roles/nut/tasks/upsd.yml | 14 ++++++++++++++ roles/nut/tasks/upsmon.yml | 6 +++--- 6 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 roles/nut/tasks/netclient.yml diff --git a/deploy.yml b/deploy.yml index 470db58..1ef8180 100644 --- a/deploy.yml +++ b/deploy.yml @@ -166,8 +166,9 @@ - name: set up NUT hosts: - - suricata - narwhal + - pikvm + - suricata become: true roles: - nut diff --git a/hosts.yml b/hosts.yml index 8a57679..0d5de83 100644 --- a/hosts.yml +++ b/hosts.yml @@ -11,6 +11,23 @@ all: dags: - 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: ansible_host: snitch ansible_user: ansible diff --git a/roles/nut/tasks/main.yml b/roles/nut/tasks/main.yml index c2111d2..5bcf13c 100644 --- a/roles/nut/tasks/main.yml +++ b/roles/nut/tasks/main.yml @@ -5,11 +5,10 @@ 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: install NUT for Arch + pacman: + name: nut + when: ansible_distribution == "Archlinux" - name: set NUT mode lineinfile: @@ -17,6 +16,10 @@ regexp: '^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 include_tasks: upsd.yml when: nut_mode in ["standalone", "netserver"] diff --git a/roles/nut/tasks/netclient.yml b/roles/nut/tasks/netclient.yml new file mode 100644 index 0000000..aaab108 --- /dev/null +++ b/roles/nut/tasks/netclient.yml @@ -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" diff --git a/roles/nut/tasks/upsd.yml b/roles/nut/tasks/upsd.yml index 069c9d8..4acfeb9 100644 --- a/roles/nut/tasks/upsd.yml +++ b/roles/nut/tasks/upsd.yml @@ -34,3 +34,17 @@ state: started enabled: true 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" diff --git a/roles/nut/tasks/upsmon.yml b/roles/nut/tasks/upsmon.yml index ca2bfce..78498dd 100644 --- a/roles/nut/tasks/upsmon.yml +++ b/roles/nut/tasks/upsmon.yml @@ -11,7 +11,7 @@ block: | 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: name: nut-upsmon runlevel: default @@ -19,9 +19,9 @@ enabled: true when: ansible_distribution == "Alpine" -- name: start and enable nut-monitor +- name: start and enable nut-monitor with systemd systemd: name: nut-monitor state: started enabled: true - when: ansible_distribution in ["Debian", "Ubuntu"] + when: ansible_distribution in ["Debian", "Ubuntu", "Archlinux"]