commit afec22d7b1cafee9a5707b4a0ca7f23cab28caa9
parent 6da5004c988c076b3d3bac5ccf9a730f689740bc
Author: Paco Esteban <paco@e1e0.net>
Date: Thu, 30 Jan 2020 14:24:06 +0100
nut role and added to pi2
Diffstat:
12 files changed, 118 insertions(+), 2 deletions(-)
diff --git a/localutils.yml b/localutils.yml
@@ -7,3 +7,4 @@
- motd-figlet
- upsc_exporter
- node-exporter
+ - nut
diff --git a/roles/nut/defaults/main.yml b/roles/nut/defaults/main.yml
@@ -0,0 +1,38 @@
+---
+nut_ups:
+ - name: ups
+ driver: blazer_usb
+ port: auto
+ desc: "Conceptronic 1200VA 600W"
+
+nut_acl: |
+ ACL all 0.0.0.0/0
+ ACL syno 10.42.30.51/32
+ ACL localhost 127.0.0.1/32
+ ACCEPT localhost
+ ACCEPT syno
+ REJECT all
+
+# put the first element the one that will go on upsmon.conf
+nut_users:
+ - name: local_mon
+ password: !vault |
+ $ANSIBLE_VAULT;1.1;AES256
+ 62363133343038333639356431323334383330633366353330323164323464613438356566383031
+ 6164303832656630376431366466346136663465343332300a656435336637306262653536656234
+ 66336365323939633966343037613432636231346133316230326434323361623335323237373739
+ 6435623033373463650a303639646430663139656532366530653666656137633231306634353733
+ 36346338323239316662383038376438663135393564383666316630393430313937373736366566
+ 3038666331373062623132613330316564623339343637643630
+ allowfrom: localhost
+ upsmon: master
+ - name: monuser
+ password: !vault |
+ $ANSIBLE_VAULT;1.1;AES256
+ 32623837363139373237326334306431656637653535653330663036633934363564343766323962
+ 6465343934616263316265383665333465376131313330610a366633626166333964393763336633
+ 39326638353330346364653030326634386432643466393138646130633861303261613738656462
+ 3835373739396466370a376435366338343430633163366439626637303530343635343736653137
+ 3564
+ allowfrom: 10.42.30.51
+ upsmon: slave
diff --git a/roles/nut/handlers/main.yml b/roles/nut/handlers/main.yml
@@ -0,0 +1,12 @@
+---
+- name: restart nut
+ service:
+ name: "{{ item }}"
+ state: restarted
+ with_items:
+ - nut-driver
+ - nut-monitor
+
+- name: restart udev
+ shell:
+ cmd: udevadm control --reload-rules && udevadm trigger
diff --git a/roles/nut/tasks/main.yml b/roles/nut/tasks/main.yml
@@ -0,0 +1,33 @@
+---
+- name: install NUT packages
+ package:
+ name:
+ - nut
+ state: latest
+
+- name: set udev rules
+ template:
+ src: templates/udev-rules.j2
+ dest: /etc/udev/rules.d/99-nut.rules
+ owner: root
+ group: root
+ mode: 0644
+ notify:
+ - restart udev
+
+- name: set config in place
+ template:
+ src: "templates/{{ item }}.j2"
+ dest: "/etc/nut/{{ item}}"
+ owner: root
+ group: nut
+ mode: 0640
+ with_items:
+ - nut.conf
+ - ups.conf
+ - upsd.conf
+ - upsd.users
+ - upsmon.conf
+ - upssched.conf
+ notify:
+ - restart nut
diff --git a/roles/nut/templates/nut.conf.j2 b/roles/nut/templates/nut.conf.j2
@@ -0,0 +1 @@
+MODE=standalone
diff --git a/roles/nut/templates/udev-rules.j2 b/roles/nut/templates/udev-rules.j2
@@ -0,0 +1,2 @@
+KERNEL=="hidraw0", GROUP="nut", MODE="0666"
+KERNEL=="hiddev0", GROUP="nut", MODE="0666"
diff --git a/roles/nut/templates/ups.conf.j2 b/roles/nut/templates/ups.conf.j2
@@ -0,0 +1,7 @@
+maxretry = 3
+{% for ups in nut_ups %}
+[{{ ups.name }}]
+ driver = {{ ups.driver }}
+ port = {{ ups.port }}
+ desc = "{{ ups.desc }}"
+{% endfor %}
diff --git a/roles/nut/templates/upsd.conf.j2 b/roles/nut/templates/upsd.conf.j2
@@ -0,0 +1,2 @@
+LISTEN 0.0.0.0 3493
+{{ nut_acl }}
diff --git a/roles/nut/templates/upsd.users.j2 b/roles/nut/templates/upsd.users.j2
@@ -0,0 +1,7 @@
+{% for user in nut_users %}
+[{{ user.name }}]
+ password = {{ user.password }}
+ allowfrom = {{ user.allowfrom }}
+ upsmon {{ user.upsmon }}
+
+{% endfor %}
diff --git a/roles/nut/templates/upsmon.conf.j2 b/roles/nut/templates/upsmon.conf.j2
@@ -0,0 +1,12 @@
+### pwd and the like
+MONITOR ups@localhost 1 {{ nut_users[0].name }} {{ nut_users[0].password }} master
+MINSUPPLIES 1
+SHUTDOWNCMD "/sbin/shutdown -h +0"
+POLLFREQ 5
+POLLFREQALERT 5
+HOSTSYNC 45
+DEADTIME 15
+POWERDOWNFLAG /tmp/killpower
+RBWARNTIME 43200
+NOCOMMWARNTIME 300
+FINALDELAY 5
diff --git a/roles/nut/templates/upssched.conf.j2 b/roles/nut/templates/upssched.conf.j2
@@ -0,0 +1 @@
+CMDSCRIPT /bin/upssched-cmd
diff --git a/roles/upsc_exporter/defaults/main.yml b/roles/upsc_exporter/defaults/main.yml
@@ -1,5 +1,5 @@
---
exporter_port: 8081
-version: "v0.1.0"
-checksum: "20c4abc0825be7340807d889ce1e3c6c415d5636e02ff4018a3c3b5d252af6fc"
+version: "v0.1.1"
+checksum: "5e19b8b1b2850b1748e25a10287963897bd8ef2b3e7d9c8e4278499ffe9a7b2c"
ups: "ups@localhost"