diff --git a/roles/USV_monitoring/files/99_nut-serialups.rules b/roles/USV_monitoring/files/99_nut-serialups.rules deleted file mode 100644 index 2b42d4a..0000000 --- a/roles/USV_monitoring/files/99_nut-serialups.rules +++ /dev/null @@ -1,4 +0,0 @@ -#This file is written by ansible. Manual changes will be reverted. 2.2018, pet - - -KERNEL=="ttyS0", GROUP="nut" diff --git a/roles/USV_monitoring/files/nut.conf b/roles/USV_monitoring/files/nut.conf deleted file mode 100755 index 08de6d6..0000000 --- a/roles/USV_monitoring/files/nut.conf +++ /dev/null @@ -1,4 +0,0 @@ -#This file is written by ansible. Manual changes will be reverted. 2.2018, pet - -#This is the master server for the UPS, all others should be netclient. -MODE=netserver diff --git a/roles/USV_monitoring/files/ups.conf b/roles/USV_monitoring/files/ups.conf deleted file mode 100644 index afea54b..0000000 --- a/roles/USV_monitoring/files/ups.conf +++ /dev/null @@ -1,6 +0,0 @@ -#This file is written by ansible. Manual changes will be reverted. 2.2018, pet - -[VSD1500] - driver = riello_ser - port = /dev/ttyS1 - desc = "Riello VSD 1500; RS-Components: 869-5016; bought: 1.2018" diff --git a/roles/USV_monitoring/files/upsd.conf b/roles/USV_monitoring/files/upsd.conf deleted file mode 100644 index 3d596b6..0000000 --- a/roles/USV_monitoring/files/upsd.conf +++ /dev/null @@ -1,4 +0,0 @@ -#This file is written by ansible. Manual changes will be reverted. 2.2018, pet - -LISTEN 192.168.86.116 3493 -LISTEN 127.0.0.1 3493 diff --git a/roles/USV_monitoring/files/upsd.users b/roles/USV_monitoring/files/upsd.users deleted file mode 100644 index 9cc22a2..0000000 --- a/roles/USV_monitoring/files/upsd.users +++ /dev/null @@ -1,10 +0,0 @@ -#This file is written by ansible. Manual changes will be reverted. 2.2018, pet - -[monmaster] - password = DorsAz4BK7XiMKDfPj - upsmon master - - -[monuser] - password = sEfguPcZbn99qnnTUj - upsmon slave diff --git a/roles/USV_monitoring/files/upsmon.conf b/roles/USV_monitoring/files/upsmon.conf deleted file mode 100644 index 917acbf..0000000 --- a/roles/USV_monitoring/files/upsmon.conf +++ /dev/null @@ -1,3 +0,0 @@ -#This file is written by ansible. Manual changes will be reverted. 2.2018, pet - -MONITOR VSD1500@lxc-pet-01 1 monmaster DorsAz4BK7XiMKDfPj master diff --git a/roles/USV_monitoring/tasks/main.yml b/roles/USV_monitoring/tasks/main.yml deleted file mode 100644 index ef193d2..0000000 --- a/roles/USV_monitoring/tasks/main.yml +++ /dev/null @@ -1,70 +0,0 @@ -- name: Check NUT (Network UPS Tools) installation - apt: - update_cache: yes - name: nut - -- name: NUT mode - /etc/nut/nut.conf - copy: - dest: /etc/nut/nut.conf - src: nut.conf - owner: root - group: nut - mode: 0640 - backup: yes - -- name: UPS conf - /etc/nut/ups.conf - copy: - dest: /etc/nut/ups.conf - src: ups.conf - owner: root - group: nut - mode: 0640 - backup: yes - -- name: UPS ip:port - /etc/nut/upsd.conf - copy: - dest: /etc/nut/upsd.conf - src: upsd.conf - owner: root - group: nut - mode: 0640 - backup: yes - -- name: NUT user - /etc/nut/upsd.users - copy: - dest: /etc/nut/upsd.users - src: upsd.users - owner: root - group: nut - mode: 0640 - backup: yes - -- name: NUT monitoring - /etc/nut/upsmon.conf - copy: - dest: /etc/nut/upsmon.conf - src: upsmon.conf - owner: root - group: nut - mode: 0640 - backup: yes - -#- name: Serial port configuration- /etc/udev/rules.d/99_nut-serialups.rules -# copy: -# dest: /etc/udev/rules.d/99_nut-serialups.rules -# src: 99_nut-serialups.rules -# owner: root -# group: nut -# mode: 0640 -# backup: yes -# -#- name: Force udev to reload Serialports -# command: "udevadm control --reload-rules" -# -#- name: Force udev to reload Serialports -# command: "udevadm trigger" - -- name: Stop the upsd - command: "upsd -c stop" - -- name: Start the upsd - command: upsd diff --git a/roles/ups/defaults/main.yml b/roles/ups/defaults/main.yml new file mode 100644 index 0000000..818f7ba --- /dev/null +++ b/roles/ups/defaults/main.yml @@ -0,0 +1,8 @@ +ups_desc: "Riello VSD 1500 from RS-Components(869-5016) installed in 2018_01" +ups_type: VSD1500 +ups_drv: riello_ser +ups_port: /etc/nut/ttyUSB0 +ups_port_dev: 188 0 + +ups_master_pw: Noongaig1quor9Waepe9 +ups_slave_pw: diff --git a/roles/ups/files/99_nut-serialups.rules b/roles/ups/files/99_nut-serialups.rules new file mode 100644 index 0000000..ffde95e --- /dev/null +++ b/roles/ups/files/99_nut-serialups.rules @@ -0,0 +1,3 @@ +# {{ ansible_managed }} + +KERNEL=="ttyS0", GROUP="nut" diff --git a/roles/ups/handlers/main.yml b/roles/ups/handlers/main.yml new file mode 100644 index 0000000..1f31ead --- /dev/null +++ b/roles/ups/handlers/main.yml @@ -0,0 +1,2 @@ +- name: restart nut + service: name=nut-server state=restarted diff --git a/roles/ups/tasks/main.yml b/roles/ups/tasks/main.yml new file mode 100644 index 0000000..b8624bc --- /dev/null +++ b/roles/ups/tasks/main.yml @@ -0,0 +1,70 @@ +- name: nut - install + apt: name=nut + +- name: nut - port access device + command: mknod {{ ups_port }} c {{ ups_port_dev }} creates={{ ups_port }} + notify: + restart nut + +- name: nut - port access file + file: path={{ ups_port }} owner=root group=nut mode=0660 + notify: + restart nut + +- name: nut - default + template: dest=/etc/default/nut src=nut.j2 owner=root group=root mode=0644 + notify: + restart nut + +- name: nut - nut.conf + template: dest=/etc/nut/nut.conf src=nut.conf.j2 owner=root group=nut mode=0640 + notify: + restart nut + +- name: nut - ups.conf + template: dest=/etc/nut/ups.conf src=ups.conf.j2 owner=root group=nut mode=0640 + notify: + restart nut + +- name: nut - upsd.conf + template: dest=/etc/nut/upsd.conf src=upsd.conf.j2 owner=root group=nut mode=0640 + notify: + restart nut + +- name: nut - upsd.users + template: dest=/etc/nut/upsd.users src=upsd.users.j2 owner=root group=nut mode=0640 + notify: + restart nut + +- name: nut - upsmon.conf + template: dest=/etc/nut/upsmon.conf src=upsmon.conf.j2 owner=root group=nut mode=0640 + notify: + restart nut + +- name: nut - upssched folder + file: path=/etc/nut/upssched owner=root group=nut mode=0750 state=directory + +- name: nut - upsscript + template: dest=/etc/nut/upssched/upsscript src=upsscript.j2 owner=root group=nut mode=0750 + notify: + restart nut + +- name: nut - upssched.conf + template: dest=/etc/nut/upssched.conf src=upssched.conf.j2 owner=root group=nut mode=0640 + notify: + restart nut + +#- name: Serial port configuration- /etc/udev/rules.d/99_nut-serialups.rules +# copy: +# dest: /etc/udev/rules.d/99_nut-serialups.rules +# src: 99_nut-serialups.rules +# owner: root +# group: nut +# mode: 0640 +# backup: yes +# +#- name: Force udev to reload Serialports +# command: "udevadm control --reload-rules" +# +#- name: Force udev to reload Serialports +# command: "udevadm trigger" diff --git a/roles/ups/templates/nut.conf.j2 b/roles/ups/templates/nut.conf.j2 new file mode 100644 index 0000000..95072d7 --- /dev/null +++ b/roles/ups/templates/nut.conf.j2 @@ -0,0 +1,5 @@ +# {{ ansible_managed }} + +# /etc/nut/nut.conf + +MODE=netserver diff --git a/roles/ups/templates/nut.j2 b/roles/ups/templates/nut.j2 new file mode 100644 index 0000000..776cc21 --- /dev/null +++ b/roles/ups/templates/nut.j2 @@ -0,0 +1,8 @@ +# {{ ansible_managed }} + +# /etc/default/nut + +START_UPSD=yes +UPSD_OPTIONS="" +START_UPSMON=yes +UPSMON_OPTIONS="" diff --git a/roles/ups/templates/ups.conf.j2 b/roles/ups/templates/ups.conf.j2 new file mode 100644 index 0000000..ee95d42 --- /dev/null +++ b/roles/ups/templates/ups.conf.j2 @@ -0,0 +1,8 @@ +# {{ ansible_managed }} + +# /etc/nut/ups.conf + +[{{ ups_type }}] + driver = {{ ups_drv }} + port = {{ ups_port }} + desc = {{ ups_desc }} diff --git a/roles/ups/templates/upsd.conf.j2 b/roles/ups/templates/upsd.conf.j2 new file mode 100644 index 0000000..fea0f7b --- /dev/null +++ b/roles/ups/templates/upsd.conf.j2 @@ -0,0 +1,6 @@ +# {{ ansible_managed }} + +# /etc/nut/upsd.conf + +LISTEN 127.0.0.1 3493 +LISTEN ::1 3493 diff --git a/roles/ups/templates/upsd.users.j2 b/roles/ups/templates/upsd.users.j2 new file mode 100644 index 0000000..dbd43b1 --- /dev/null +++ b/roles/ups/templates/upsd.users.j2 @@ -0,0 +1,12 @@ +# {{ ansible_managed }} + +# /etc/nut/upsd.users + +[master] + password = {{ ups_master_pw }} + upsmon master +{% if ups_slave_pw -%} +[slave] + password = {{ ups_slave_pw }} + upsmon slave +{% endif %} diff --git a/roles/ups/templates/upsmon.conf.j2 b/roles/ups/templates/upsmon.conf.j2 new file mode 100644 index 0000000..17377ab --- /dev/null +++ b/roles/ups/templates/upsmon.conf.j2 @@ -0,0 +1,7 @@ +# {{ ansible_managed }} + +# /etc/nut/upsmon.conf + +MONITOR {{ ups_type }}@localhost 1 master {{ ups_master_pw }} master +NOTIFYCMD /sbin/upssched +NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC diff --git a/roles/ups/templates/upssched.conf.j2 b/roles/ups/templates/upssched.conf.j2 new file mode 100644 index 0000000..b1ba5be --- /dev/null +++ b/roles/ups/templates/upssched.conf.j2 @@ -0,0 +1,10 @@ +# {{ ansible_managed }} + +# /etc/nut/upssched.conf + +CMDSCRIPT /etc/nut/upssched/upsscript +PIPEFN /etc/nut/upssched/upssched.pipe +LOCKFN /etc/nut/upssched/upssched.lock +AT ONBATT * START-TIMER onbatt 120 +AT ONLINE * CANCEL-TIMER onbatt +AT LOWBATT * EXEC lowbatt diff --git a/roles/ups/templates/upsscript.j2 b/roles/ups/templates/upsscript.j2 new file mode 100644 index 0000000..94030df --- /dev/null +++ b/roles/ups/templates/upsscript.j2 @@ -0,0 +1,14 @@ +# {{ ansible_managed }} + +# /etc/nut/upssched/upsscript + +#! /bin/sh +case $1 in + onbatt) + ssh + ;; + lowbatt) + /sbin/upssched fsd;; + *) + echo "wrong Parameter";; +esac diff --git a/site.yml b/site.yml index ac4a2d9..d850c4b 100644 --- a/site.yml +++ b/site.yml @@ -41,4 +41,4 @@ - hosts: lxc-pet-01 roles: - - USV_monitoring + - ups