mirror of
https://github.com/schnidrig/openhab-ansible
synced 2026-01-12 00:48:46 +01:00
initial commit
This commit is contained in:
5
roles/mqttwarn/handlers/main.yml
Normal file
5
roles/mqttwarn/handlers/main.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
|
||||
- name: restart mqttwarn
|
||||
service: name=mqttwarn state=restarted
|
||||
|
||||
4
roles/mqttwarn/tasks/main.yml
Normal file
4
roles/mqttwarn/tasks/main.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
|
||||
- include: mosquitto.yml
|
||||
- include: mqttwarn.yml
|
||||
16
roles/mqttwarn/tasks/mosquitto.yml
Normal file
16
roles/mqttwarn/tasks/mosquitto.yml
Normal file
@@ -0,0 +1,16 @@
|
||||
---
|
||||
|
||||
- name: install main packages
|
||||
apt:
|
||||
pkg: "{{item}}"
|
||||
update_cache: "{{apt_config.update_cache}}"
|
||||
cache_valid_time: "{{apt_config.cache_valid_time}}"
|
||||
with_items:
|
||||
- mosquitto
|
||||
- mosquitto-clients
|
||||
tags:
|
||||
- packages
|
||||
- mosquitto
|
||||
|
||||
|
||||
|
||||
56
roles/mqttwarn/tasks/mqttwarn.yml
Normal file
56
roles/mqttwarn/tasks/mqttwarn.yml
Normal file
@@ -0,0 +1,56 @@
|
||||
---
|
||||
|
||||
- pip:
|
||||
name: "paho-mqtt"
|
||||
tags:
|
||||
- mqttwarn
|
||||
|
||||
|
||||
- git:
|
||||
repo: "https://github.com/jpmens/mqttwarn.git"
|
||||
dest: "/opt/mqttwarn"
|
||||
version: "0c030a94a7e3590ea3485f460be555cee027d8a8"
|
||||
tags:
|
||||
- mqttwarn
|
||||
|
||||
- name: install config file
|
||||
template:
|
||||
src: mqttwarn.ini
|
||||
dest: "/opt/mqttwarn/mqttwarn.ini"
|
||||
owner: root
|
||||
group: root
|
||||
mode: "u=rw,g=r,o=r"
|
||||
notify: restart mqttwarn
|
||||
tags:
|
||||
- mqttwarn
|
||||
- mqttwarnconfig
|
||||
|
||||
- name: create log file
|
||||
file:
|
||||
state: touch
|
||||
path: "/opt/mqttwarn/mqttwarn.log"
|
||||
owner: pi
|
||||
group: pi
|
||||
tags:
|
||||
- mqttwarn
|
||||
|
||||
- name: install service file
|
||||
template:
|
||||
src: mqttwarn.service
|
||||
dest: "/etc/systemd/system/mqttwarn.service"
|
||||
owner: root
|
||||
group: root
|
||||
mode: "u=rw,g=r,o=r"
|
||||
tags:
|
||||
- mqttwarn
|
||||
|
||||
- name: "configure systemd"
|
||||
systemd:
|
||||
name: mqttwarn
|
||||
daemon_reload: yes
|
||||
enabled: true
|
||||
state: started
|
||||
tags:
|
||||
- mqttwarn
|
||||
|
||||
|
||||
51
roles/mqttwarn/templates/mqttwarn.ini
Normal file
51
roles/mqttwarn/templates/mqttwarn.ini
Normal file
@@ -0,0 +1,51 @@
|
||||
[defaults]
|
||||
hostname = 'localhost'
|
||||
port = 1883
|
||||
clientid = 'mqttwarn'
|
||||
|
||||
|
||||
; logging
|
||||
logformat = '%(asctime)-15s %(levelname)-5s [%(module)s] %(message)s'
|
||||
logfile = 'mqttwarn.log'
|
||||
|
||||
; one of: CRITICAL, DEBUG, ERROR, INFO, WARN
|
||||
;loglevel = DEBUG
|
||||
loglevel = ERROR
|
||||
|
||||
; name the service providers you will be using.
|
||||
launch = file, log, carbon
|
||||
|
||||
[config:file]
|
||||
append_newline = True
|
||||
targets = {
|
||||
'f01' : ['/tmp/f.01'],
|
||||
'log-me' : ['/tmp/log.me'],
|
||||
'mqttwarn' : ['/tmp/mqttwarn.err'],
|
||||
}
|
||||
|
||||
[config:log]
|
||||
targets = {
|
||||
'debug' : [ 'debug' ],
|
||||
'info' : [ 'info' ],
|
||||
'warn' : [ 'warn' ],
|
||||
'crit' : [ 'crit' ],
|
||||
'error' : [ 'error' ]
|
||||
}
|
||||
|
||||
|
||||
; special config for 'failover' events
|
||||
[failover]
|
||||
targets = log:error, file:mqttwarn
|
||||
|
||||
|
||||
[config:carbon]
|
||||
targets = {
|
||||
'openhab' : [ '{{graphite_server}}',2003 ],
|
||||
}
|
||||
|
||||
|
||||
[/openhab/graphite/#]
|
||||
targets = carbon:openhab
|
||||
;targets = log:info, file:f01, carbon:openhab
|
||||
|
||||
# instead of logging run `mosquitto_sub -t openhab/graphite/#`
|
||||
13
roles/mqttwarn/templates/mqttwarn.service
Normal file
13
roles/mqttwarn/templates/mqttwarn.service
Normal file
@@ -0,0 +1,13 @@
|
||||
[Unit]
|
||||
Description=MQTTwarn
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=pi
|
||||
Group=pi
|
||||
WorkingDirectory=/opt/mqttwarn
|
||||
ExecStart=/opt/mqttwarn/mqttwarn.py
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
|
||||
Reference in New Issue
Block a user