2
0
mirror of https://github.com/schnidrig/openhab-ansible synced 2026-01-12 00:48:46 +01:00

initial commit

This commit is contained in:
Christian Schnidrig
2016-11-29 00:08:10 +01:00
parent 8643000910
commit 3a665afb54
30 changed files with 533 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
- name: restart mqttwarn
service: name=mqttwarn state=restarted

View File

@@ -0,0 +1,4 @@
---
- include: mosquitto.yml
- include: mqttwarn.yml

View 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

View 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

View 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/#`

View 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

View File

@@ -0,0 +1,8 @@
---
- include: repo.yml
- include: packages.yml
- include: openhab.yml
- include: nfs.yml

View File

@@ -0,0 +1,30 @@
---
- name: ensure packages are installed
apt:
pkg: "{{item}}"
update_cache: "{{apt_config.update_cache}}"
cache_valid_time: "{{apt_config.cache_valid_time}}"
with_items:
- nfs-common
- nfs-kernel-server
tags:
- packages
- nfs
- openhab
- name: update /etc/exports
lineinfile:
dest=/etc/exports
regexp="^{{item.mount_point}}\s.*"
line="{{item.mount_point}} {{item.options}}"
notify: update exportfs
with_items:
- { mount_point: "/etc/openhab", options: "*(rw,sync,no_subtree_check,all_squash)" }
tags:
- nfs
- nfsconfig
- openhab

View File

@@ -0,0 +1,20 @@
---
- name:
user:
name: openhab
groups: "dialout"
append: yes
tags:
- openhab
- user
- name: "configure systemd"
systemd:
name: openhab
daemon_reload: yes
enabled: true
state: started
tags:
- openhab

View File

@@ -0,0 +1,38 @@
---
- name: install main packages
apt:
pkg: "{{item}}"
update_cache: "{{apt_config.update_cache}}"
cache_valid_time: "{{apt_config.cache_valid_time}}"
with_items:
- "{{jdk}}"
- openhab-runtime
tags:
- packages
- openhab
- name: install bindings
apt:
pkg: "openhab-addon-binding-{{item}}"
update_cache: "{{apt_config.update_cache}}"
cache_valid_time: "{{apt_config.cache_valid_time}}"
with_items: "{{bindings}}"
tags:
- packages
- bindings
- openhab
- name: install persistence add ons
apt:
pkg: "openhab-addon-persistence-{{item}}"
update_cache: "{{apt_config.update_cache}}"
cache_valid_time: "{{apt_config.cache_valid_time}}"
with_items: "{{persistence}}"
tags:
- packages
- persistence
- openhab

View File

@@ -0,0 +1,18 @@
---
- name: install ppa key
apt_key: url=https://bintray.com/user/downloadSubjectPublicKey?username=openhab state=present
tags:
- repo
- openhab
- name: install openhab repo
apt_repository:
repo='deb http://dl.bintray.com/openhab/apt-repo stable main'
state=present
update_cache=yes
filename=openhab
tags:
- repo
- openhab

View File

@@ -0,0 +1,9 @@
---
- name: restart ntp
service: name=ntp state=restarted
- name: update exportfs
shell: exportfs -rav

View File

@@ -0,0 +1,28 @@
---
- name: setup /etc/locale.gen
lineinfile:
dest: "/etc/locale.gen"
regexp: '\s*#\s*({{locale}}.*)'
line: '\1'
backrefs: yes
tags:
- locale
- name: generate locale
locale_gen: name="{{locale}}" state=present
tags:
- locale
- name: set environment file
template:
src: environment
dest: "/etc/environment"
owner: root
group: root
mode: "u=rw,g=r,o=r"
tags:
- locale

View File

@@ -0,0 +1,9 @@
---
- include: packages.yml
- include: ntp.yml
- include: timezone.yml
- include: locale.yml

View File

@@ -0,0 +1,28 @@
---
- name: update ntp.conf
lineinfile:
dest=/etc/ntp.conf
regexp="^server\s+.*debian.pool.ntp.org.*"
insertafter="^server\s.*"
state=absent
notify: restart ntp
tags:
- ntp
- ntpconfig
- name: update ntp.conf
lineinfile:
dest=/etc/ntp.conf
insertafter="# pool:"
line="server {{item}} iburst"
with_items: "{{ntp}}"
notify: restart ntp
tags:
- ntp
- ntpconfig
- name: Start the ntp service
service: name=ntp state=started enabled=true
tags: ntp

View File

@@ -0,0 +1,16 @@
---
- name: ensure packages are installed
apt:
pkg: "{{item}}"
update_cache: "{{apt_config.update_cache}}"
cache_valid_time: "{{apt_config.cache_valid_time}}"
with_items:
- apt-transport-https
- ntp
- tmux
- python-pip
- git
tags:
- packages

View File

@@ -0,0 +1,22 @@
---
- name: fix /etc/localtime
file:
state: link
path: "/etc/localtime"
src: "/usr/share/zoneinfo/{{timezone}}"
owner: root
group: root
force: true
tags:
- timezone
- name: fix /etc/timezone
copy:
dest: "/etc/timezone"
content: "{{timezone}}"
owner: root
group: root
mode: "u=rw,g=r,o=r"
tags:
- timezone

View File

@@ -0,0 +1,2 @@
LANG={{locale}}
LC_ALL={{locale}}