mirror of
https://github.com/proffalken/ansible-openhab
synced 2026-01-11 15:08:45 +01:00
Initial import of the role after tidying it up
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
.kitchen/**
|
||||
**/*.swp
|
||||
19
.kitchen.yml
Normal file
19
.kitchen.yml
Normal file
@@ -0,0 +1,19 @@
|
||||
---
|
||||
platforms:
|
||||
- name: ubuntu-14.04
|
||||
provision_command: sudo pip install netaddr
|
||||
driver:
|
||||
instance_type: c4.large
|
||||
tags:
|
||||
- Name: ubuntu-14.04-test-kitchen-openhab
|
||||
# - name: centos-7
|
||||
# provision_command: yum install -y rubygem-rake
|
||||
# tags:
|
||||
# - Name: centos-7-test-kitchen-nginx
|
||||
|
||||
suites:
|
||||
- name: openhab
|
||||
|
||||
verifier:
|
||||
sudo_command: sudo
|
||||
|
||||
98
README.md
Normal file
98
README.md
Normal file
@@ -0,0 +1,98 @@
|
||||
# OpenHAB
|
||||
|
||||
Install and configure the OpenHAB (www.openhab.org) software for Home
|
||||
Automation
|
||||
|
||||
## Requirements
|
||||
|
||||
To ensure that IP Address Ranges are mapped to their correct CIDR equivalents,
|
||||
you must install "netaddr" on the device that you use to run this Ansible role.
|
||||
|
||||
This is easily done from PIP with the following command on Linux:
|
||||
|
||||
```pip install netaddr```
|
||||
|
||||
## Usage
|
||||
|
||||
### Bindings, Actions, Persistence and IO Plugins
|
||||
|
||||
To install and configure bindings, you need to set variables either at a group,
|
||||
host or role level.
|
||||
|
||||
Each section of the variables is named after the configuration file section
|
||||
name, for example, the following installs and configures the "pushover"
|
||||
action, the rrd4j persistence layer and the lightwaverf and milight bindings:
|
||||
|
||||
```
|
||||
openhab_actions:
|
||||
pushover:
|
||||
- { key: defaultToken, value: pushover_token }
|
||||
- { key: defaultUser, value: pushover_user_token }
|
||||
openhab_persistence:
|
||||
rrd4j:
|
||||
- { key: der5min.def, value: "DERIVE,900,0,U,300" }
|
||||
- { key: der5min.archives, value: "AVERAGE,0.5,1,365:AVERAGE,0.5,7,300"}
|
||||
- { key: der5min.items, value: "Speedtest*,LW_WifiL*"}
|
||||
openhab_bindings:
|
||||
milight:
|
||||
- { key: "milight1.host", value: "192.168.1.102" }
|
||||
- { key: "milight1.port", value: "8899" }
|
||||
plex:
|
||||
- { key: host, value: 192.168.1.104 }
|
||||
- { key: port, value: 32400 }
|
||||
- { key: refresh, value: 5000 }
|
||||
lightwaverf:
|
||||
- { key: ip, value: 192.168.1.103 }
|
||||
- { key: receiveport, value: 9761 }
|
||||
- { key: sendport, value: 9760 }
|
||||
- { key: registeronstartup, value: true }
|
||||
- { key: senddelay, value: 2000 }
|
||||
- { key: okTimeout, value: 1000 }
|
||||
```
|
||||
|
||||
Note that the format is:
|
||||
|
||||
```
|
||||
openhab_<section_type>:
|
||||
<action/binding/persistence_name>:
|
||||
- { key: key_name, value: value_of_variable }
|
||||
```
|
||||
|
||||
### Sitemaps, rules, and other configuration files
|
||||
|
||||
I've not found a way to automate this nicely at the present time, so for now,
|
||||
create the files as you would if installing manually and place them in the
|
||||
relevant directory under `files`. They will automatically be copied in to
|
||||
place.
|
||||
|
||||
## Dependencies
|
||||
|
||||
Make sure that you have a role that installs Java. People appear to have
|
||||
widely differing opinions on which JVM should be installed (Oracle/OpenJDK etc)
|
||||
so I have left this choice up to you!
|
||||
|
||||
## Example Playbook
|
||||
|
||||
This playbook can be run in isolation, however, I would recommend that you
|
||||
ensure your baseline play installs and configures a firewall and that you
|
||||
enable the `openhab_use_firewall` variable to make your installation more
|
||||
secure.
|
||||
|
||||
To run the role, create a play with the following content:
|
||||
|
||||
- hosts: openhab_servers
|
||||
roles:
|
||||
- { role: <your_java_role> }
|
||||
- { role: openhab }
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
MIT
|
||||
|
||||
Author Information
|
||||
------------------
|
||||
|
||||
Matthew Macdonald-Wallace
|
||||
http://doics.co
|
||||
http://hackerdads.wordpress.com
|
||||
32
defaults/main.yml
Normal file
32
defaults/main.yml
Normal file
@@ -0,0 +1,32 @@
|
||||
---
|
||||
# defaults file for openhab
|
||||
openhab_security: OFF
|
||||
general_net_mask: "{{ ansible_default_ipv4.network }}/{{ ansible_default_ipv4.netmask }}"
|
||||
openhab_netmask: "{{ general_net_mask | ipaddr('net') }}"
|
||||
openhab_default_persistence: rrd4j
|
||||
openhab_configuration_refresh: 5
|
||||
openhab_service_discovery_bind_address: "{{ ansible_default_ipv4['address'] }}"
|
||||
openhab_chart_provider: rrd4j
|
||||
openhab_chart_height: 240
|
||||
openhab_chart_width: 480
|
||||
openhab_chart_scale: 1
|
||||
|
||||
## Configure your Actions here
|
||||
openhab_actions:
|
||||
mail:
|
||||
- { key: hostname, value: localhost }
|
||||
- { key: port, value: 25 }
|
||||
|
||||
## Configure Persistence here
|
||||
openhab_persistence:
|
||||
rrd4j:
|
||||
- { key: der5min.def, value: 'DERIVE,900,0,U,300' }
|
||||
- { key: der5min.archives, value: 'AVERAGE,0.5,1,365:AVERAGE,0.5,7,300' }
|
||||
- { key: der5min.items, value: 'Demo*' }
|
||||
logging:
|
||||
- {key: pattern, value: '%date{ISO8601} - %-25logger: %msg%n' }
|
||||
|
||||
## Configure your Bindings here
|
||||
openhab_bindings:
|
||||
bluetooth:
|
||||
- { key: refresh, value: 20 }
|
||||
2
files/items/README.md
Normal file
2
files/items/README.md
Normal file
@@ -0,0 +1,2 @@
|
||||
# items
|
||||
Put your OpenHAB items configurations in this directory
|
||||
2
files/persistence/README.md
Normal file
2
files/persistence/README.md
Normal file
@@ -0,0 +1,2 @@
|
||||
# persistence
|
||||
Put your OpenHAB persistence configurations in this directory
|
||||
2
files/rules/README.md
Normal file
2
files/rules/README.md
Normal file
@@ -0,0 +1,2 @@
|
||||
# rules
|
||||
Put your OpenHAB rules configurations in this directory
|
||||
2
files/sitemaps/README.md
Normal file
2
files/sitemaps/README.md
Normal file
@@ -0,0 +1,2 @@
|
||||
# sitemaps
|
||||
Put your OpenHAB sitemaps configurations in this directory
|
||||
6
handlers/main.yml
Normal file
6
handlers/main.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
# handlers file for openhab
|
||||
- name: Restart OpenHAB
|
||||
service:
|
||||
name: openhab
|
||||
state: restarted
|
||||
15
meta/main.yml
Normal file
15
meta/main.yml
Normal file
@@ -0,0 +1,15 @@
|
||||
---
|
||||
galaxy_info:
|
||||
author: Matthew Macdonald-Wallae
|
||||
description: Install the OpenHAB Home Automation Suite
|
||||
company:
|
||||
license: MIT
|
||||
min_ansible_version: 1.9
|
||||
platforms:
|
||||
- name: Ubuntu
|
||||
versions:
|
||||
- all
|
||||
- name: Debian
|
||||
versions:
|
||||
- all
|
||||
dependencies: []
|
||||
41
tasks/debian.yml
Normal file
41
tasks/debian.yml
Normal file
@@ -0,0 +1,41 @@
|
||||
---
|
||||
# Debian specfic tasks for OpenHAB
|
||||
- name: Add APT Key
|
||||
apt_key:
|
||||
url: "https://bintray.com/user/downloadSubjectPublicKey?username=openhab"
|
||||
state: present
|
||||
|
||||
- name: Add the APT Repo
|
||||
apt_repository:
|
||||
repo: "deb http://dl.bintray.com/openhab/apt-repo stable main"
|
||||
state: present
|
||||
|
||||
- name: Install OpenHAB
|
||||
apt:
|
||||
name: openhab-runtime
|
||||
state: present
|
||||
update_cache: yes
|
||||
|
||||
- name: Install OpenHAB Actions
|
||||
apt:
|
||||
name: "openhab-addon-action-{{ item.key }}"
|
||||
state: present
|
||||
update_cache: yes
|
||||
with_dict: "{{ openhab_actions }}"
|
||||
ignore_errors: True
|
||||
|
||||
- name: Install OpenHAB Bindings
|
||||
apt:
|
||||
name: "openhab-addon-binding-{{ item.key }}"
|
||||
state: present
|
||||
update_cache: yes
|
||||
with_dict: "{{ openhab_bindings }}"
|
||||
ignore_errors: True
|
||||
|
||||
- name: Install OpenHAB Persistence
|
||||
apt:
|
||||
name: "openhab-addon-persistence-{{ item.key }}"
|
||||
state: present
|
||||
update_cache: yes
|
||||
with_dict: "{{ openhab_persistence }}"
|
||||
ignore_errors: True
|
||||
59
tasks/main.yml
Normal file
59
tasks/main.yml
Normal file
@@ -0,0 +1,59 @@
|
||||
---
|
||||
# tasks file for openhab
|
||||
# include the distro-specific stuff
|
||||
- name: Include the Debian config
|
||||
include: debian.yml
|
||||
when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'
|
||||
|
||||
- name: Use the variables to build out the configuration file
|
||||
template:
|
||||
src: openhab.cfg.j2
|
||||
dest: /etc/openhab/configurations/openhab.cfg
|
||||
owner: openhab
|
||||
group: openhab
|
||||
|
||||
- name: Copy in the items files
|
||||
copy:
|
||||
src: "{{ item }}"
|
||||
dest: "/etc/openhab/configurations/items/"
|
||||
owner: openhab
|
||||
group: openhab
|
||||
mode: 0644
|
||||
with_fileglob:
|
||||
- items/*
|
||||
|
||||
- name: Copy in the Sitemaps
|
||||
copy:
|
||||
src: "{{ item }}"
|
||||
dest: "/etc/openhab/configurations/sitemaps/"
|
||||
owner: openhab
|
||||
group: openhab
|
||||
mode: 0644
|
||||
with_fileglob:
|
||||
- sitemaps/*
|
||||
|
||||
- name: Copy in the Persistence Config
|
||||
copy:
|
||||
src: "{{ item }}"
|
||||
dest: "/etc/openhab/configurations/persistence/"
|
||||
owner: openhab
|
||||
group: openhab
|
||||
mode: 0644
|
||||
with_fileglob:
|
||||
- persistence/*
|
||||
|
||||
- name: Copy in the Rules
|
||||
copy:
|
||||
src: "{{ item }}"
|
||||
dest: "/etc/openhab/configurations/rules/"
|
||||
owner: openhab
|
||||
group: openhab
|
||||
mode: 0644
|
||||
with_fileglob:
|
||||
- rules/*
|
||||
|
||||
- name: Enable and start the OpenHAB service
|
||||
service:
|
||||
name: openhab
|
||||
state: running
|
||||
enabled: True
|
||||
1
tasks/rhel.yml
Normal file
1
tasks/rhel.yml
Normal file
@@ -0,0 +1 @@
|
||||
---
|
||||
49
templates/openhab.cfg.j2
Normal file
49
templates/openhab.cfg.j2
Normal file
@@ -0,0 +1,49 @@
|
||||
###
|
||||
# {{ ansible_managed }}
|
||||
###
|
||||
|
||||
## General configurations
|
||||
folder:items=10,items
|
||||
folder:sitemaps=10,sitemap
|
||||
folder:rules=10,rules
|
||||
folder:scripts=10,script
|
||||
folder:persistence=10,persist
|
||||
|
||||
security:option={{ openhab_security | default("OFF") }}
|
||||
security:netmask={{ openhab_netmask | default("192.168.1.0/24") }}
|
||||
persistence:default={{ openhab_default_persistence | default("rrd4j") }}
|
||||
mainconfig:refresh={{ openhab_configuration_refresh | default("-1") }}
|
||||
|
||||
servicediscovery:bind_address={{ openhab_service_discovery_bind_address | default(ansible_default_ipv4['address']) }}
|
||||
|
||||
################################## Chart Servlet ######################################
|
||||
chart:provider={{ openhab_chart_provider | default("rrd4j") }}
|
||||
chart:defaultHeight={{ openhab_chart_height | default("240") }}
|
||||
chart:defaultWidth={{ openhab_chart_width | default("480") }}
|
||||
chart:scale={{ openhab_chart_scale | default("1") }}
|
||||
|
||||
|
||||
##### Action configurations
|
||||
|
||||
{% for action in openhab_actions %}
|
||||
########### {{ action }} ##################
|
||||
{% for acfg_item in openhab_actions[action] %}
|
||||
{{ action }}:{{ acfg_item['key'] }}={{ acfg_item['value'] }}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
|
||||
##### Persistence configurations
|
||||
{% for persist in openhab_persistence %}
|
||||
########### {{ persist }} ##################
|
||||
{% for pcfg_item in openhab_persistence[persist] %}
|
||||
{{ persist }}:{{ pcfg_item['key'] }}={{ pcfg_item['value'] }}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
|
||||
##### Binding configurations
|
||||
{% for binding in openhab_bindings %}
|
||||
########### {{ binding }} ##################
|
||||
{% for bcfg_item in openhab_bindings[binding] %}
|
||||
{{ binding }}:{{ bcfg_item['key'] }}={{ bcfg_item['value'] }}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
8
test/integration/openhab/default.yml
Normal file
8
test/integration/openhab/default.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
#
|
||||
# Copyright (c) 2015 by DevOpsGuys. All rights reserved.
|
||||
#
|
||||
---
|
||||
- hosts: all
|
||||
become: true
|
||||
roles:
|
||||
- openhab
|
||||
3
test/integration/openhab/serverspec/Gemfile
Normal file
3
test/integration/openhab/serverspec/Gemfile
Normal file
@@ -0,0 +1,3 @@
|
||||
source 'https://rubygems.org/'
|
||||
gem 'rake'
|
||||
gem 'busser'
|
||||
20
test/integration/openhab/serverspec/openhab_spec.rb
Normal file
20
test/integration/openhab/serverspec/openhab_spec.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
require 'serverspec'
|
||||
|
||||
# Required by serverspec
|
||||
set :backend, :exec
|
||||
|
||||
describe package('openhab') do
|
||||
it { should be_disabled }
|
||||
end
|
||||
|
||||
describe service('openhab') do
|
||||
it { should be_enabled }
|
||||
it { should be_running }
|
||||
end
|
||||
|
||||
describe port(80) do
|
||||
it { should be_listening }
|
||||
end
|
||||
describe port(443) do
|
||||
it { should be_listening }
|
||||
end
|
||||
2
vars/main.yml
Normal file
2
vars/main.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
---
|
||||
# vars file for openhab
|
||||
Reference in New Issue
Block a user