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

openhab 2.5 on raspi4

This commit is contained in:
Christian Schnidrig
2020-01-01 20:34:53 +01:00
parent caf4dcd77a
commit 0c652dfbd2
30 changed files with 203 additions and 185 deletions

View File

@@ -1,4 +1,6 @@
[defaults] [defaults]
interpreter_python = auto_silent
#interpreter_python = /usr/bin/python3
retry_files_enabled = False retry_files_enabled = False
vault_password_file = vault_password vault_password_file = vault_password

View File

@@ -7,17 +7,8 @@ apt_config:
update_cache: yes update_cache: yes
cache_valid_time: 7200 cache_valid_time: 7200
jdk:
- oracle-java8-jdk
#- oracle-java7-installer
#- oracle-java7-set-default
ntp: ntp:
- "ntp.bluewin.ch" - "ntp.bluewin.ch"
#- "0.ch.pool.ntp.org"
#- "1.ch.pool.ntp.org"
#- "2.ch.pool.ntp.org"
#- "3.ch.pool.ntp.org"
letsencrypt_email: christian.schnidrig@gmail.com letsencrypt_email: christian.schnidrig@gmail.com

View File

@@ -19,7 +19,9 @@ nginx_user: "{{ vault_nginx_user }}"
nginx_password: "{{ vault_nginx_password }}" nginx_password: "{{ vault_nginx_password }}"
dynv6_name: "schnidrig.dynv6.net" dynv6_name: "schnidrig.dynv6.net"
#dynv6_name: "raspi4.dynv6.net"
dynv6_device: "{{ vault_dynv6_device }}" dynv6_device: "{{ vault_dynv6_device }}"
dynv6_token: "{{ vault_dynv6_token }}" dynv6_token: "{{ vault_dynv6_token }}"
fqdn: "schnidrig.dynv6.net" fqdn: "schnidrig.dynv6.net"
#fqdn: "raspi4.dynv6.net"

View File

@@ -1,6 +1,7 @@
[controller] [controller]
192.168.1.7 ansible_ssh_user=pi 192.168.1.7 ansible_ssh_user=pi
192.168.1.12 ansible_ssh_user=pi 192.168.1.12 ansible_ssh_user=pi
192.168.1.9 ansible_ssh_user=pi
[raspis] [raspis]
#192.168.1.5 ansible_ssh_user=pi #192.168.1.5 ansible_ssh_user=pi

View File

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

View File

@@ -1,16 +1,12 @@
--- ---
- name: install main packages - name: install mosquitto packages
apt: apt:
pkg: "{{item}}" pkg:
- mosquitto
- mosquitto-clients
update_cache: "{{apt_config.update_cache}}" update_cache: "{{apt_config.update_cache}}"
cache_valid_time: "{{apt_config.cache_valid_time}}" cache_valid_time: "{{apt_config.cache_valid_time}}"
with_items:
- mosquitto
- mosquitto-clients
tags:
- packages
- mosquitto

View File

@@ -0,0 +1,50 @@
---
- name: install packages
apt:
pkg:
- python3-paho-mqtt
update_cache: "{{apt_config.update_cache}}"
cache_valid_time: "{{apt_config.cache_valid_time}}"
- name: install mqttwarn
vars:
ansible_python_interpreter: /usr/bin/python3
pip:
name: mqttwarn
- name: install config file
template:
src: mqttwarn.ini
dest: "/etc/mqttwarn.ini"
owner: root
group: root
mode: "u=rw,g=r,o=r"
notify: restart mqttwarn
tags:
- mqttwarnconfig
- name: create log dir
file:
dest: "/var/log/mqttwarn"
state: directory
owner: pi
group: pi
- 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"
notify: restart mqttwarn
- name: "configure systemd"
systemd:
name: mqttwarn
daemon_reload: yes
enabled: true
state: started

View File

@@ -1,10 +1,12 @@
--- ---
- pip: - name: install packages
name: "paho-mqtt" apt:
tags: pkg:
- mqttwarn - python-paho-mqtt
- python3-paho-mqtt
update_cache: "{{apt_config.update_cache}}"
cache_valid_time: "{{apt_config.cache_valid_time}}"
- git: - git:
repo: "https://github.com/jpmens/mqttwarn.git" repo: "https://github.com/jpmens/mqttwarn.git"

View File

@@ -6,7 +6,10 @@ After=mosquitto.service
Type=simple Type=simple
User=pi User=pi
Group=pi Group=pi
#WorkingDirectory=/home/pi
WorkingDirectory=/opt/mqttwarn WorkingDirectory=/opt/mqttwarn
#Environment="MQTTWARNINI=/etc/mqttwarn.ini"
#ExecStart=/usr/local/bin/mqttwarn
ExecStart=/opt/mqttwarn/mqttwarn.py ExecStart=/opt/mqttwarn/mqttwarn.py
[Install] [Install]

View File

@@ -7,5 +7,3 @@
owner: root owner: root
group: root group: root
mode: "u=rwx,g=r,o=r" mode: "u=rwx,g=r,o=r"
tags:
- backup

View File

@@ -7,8 +7,6 @@
owner: root owner: root
group: root group: root
mode: "u=rwx,g=r,o=r" mode: "u=rwx,g=r,o=r"
tags:
- dynv6
- name: Cron file for dynv6 - name: Cron file for dynv6
cron: cron:
@@ -16,6 +14,4 @@
user: root user: root
job: "/root/dynv6.sh" job: "/root/dynv6.sh"
cron_file: dynv6 cron_file: dynv6
tags:
- dynv6

View File

@@ -1,29 +1,24 @@
--- ---
- name: download certbot - name: ensure packages are installed
get_url: apt:
url: https://dl.eff.org/certbot-auto pkg:
dest: /root/certbot-auto - certbot
mode: 0540 - python-certbot-nginx
tags: - python3-certbot-nginx
- letsencrypt update_cache: "{{apt_config.update_cache}}"
cache_valid_time: "{{apt_config.cache_valid_time}}"
- name: get certificate - name: get certificate
#shell: '/root/certbot-auto -n run --test-cert --nginx --agree-tos --email {{letsencrypt_email}} --cert-path /etc/nginx/ssl/cert.pem --key-path /etc/nginx/ssl/cert.key --fullchain-path /etc/nginx/ssl/chain.pem -d {{fqdn}}' shell: 'certbot -n run --nginx --agree-tos --email {{letsencrypt_email}} -d {{fqdn}}'
shell: '/root/certbot-auto -n run --nginx --agree-tos --email {{letsencrypt_email}} -d {{fqdn}}'
tags:
- letsencrypt
- name: cron job # - name: cron job
cron: # cron:
name: "get new certificate" # name: "get new certificate"
minute: "0" # minute: "0"
hour: "5" # hour: "5"
day: "11" # day: "11"
job: '/root/certbot-auto -n certonly --nginx --agree-tos --email {{letsencrypt_email}} -d {{fqdn}}' # job: 'certbot -n certonly --nginx --agree-tos --email {{letsencrypt_email}} -d {{fqdn}}'
cron_file: letsencrypt # cron_file: letsencrypt
user: root # user: root
tags:
- letsencrypt
- letsencrypt_cron

View File

@@ -1,19 +1,50 @@
--- ---
- include: repo.yml - include: repo.yml
tags:
- repo
- openhab2
- include: packages.yml - include: packages.yml
tags:
- packages
- openhab2
- include: openhab.yml - include: openhab.yml
tags:
- openhab
- openhab2
#- include: habmin.yml #- include: habmin.yml
- include: nfs.yml - include: nfs.yml
tags:
- nfs
- openhab2
- include: mysql.yml - include: mysql.yml
tags:
- mysql
- openhab2
- include: backup.yml - include: backup.yml
tags:
- backup
- openhab2
- include: nginx.yml - include: nginx.yml
tags:
- nginx
- openhab2
- include: dynv6.yml - include: dynv6.yml
tags:
- dynv6
- openhab2
- include: letsencrypt.yml - include: letsencrypt.yml
tags:
- letsencrypt
- openhab2
- include: scripts.yml - include: scripts.yml
tags:
- scripts
- openhab2
- include: gardena.yml - include: gardena.yml
tags: tags:
- gardena - gardena
- openhab2

View File

@@ -2,15 +2,11 @@
- name: install mysql packages - name: install mysql packages
apt: apt:
pkg: "{{item}}" pkg:
- default-mysql-server
- python-mysqldb
update_cache: "{{apt_config.update_cache}}" update_cache: "{{apt_config.update_cache}}"
cache_valid_time: "{{apt_config.cache_valid_time}}" cache_valid_time: "{{apt_config.cache_valid_time}}"
with_items:
- mysql-server
- python-mysqldb
tags:
- mysql
- packages
- name: Create openhab database - name: Create openhab database
mysql_db: mysql_db:
@@ -24,7 +20,5 @@
password: openhab2 password: openhab2
priv: '*.*:ALL' priv: '*.*:ALL'
state: present state: present
tags:
- mysql

View File

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

View File

@@ -8,15 +8,11 @@
group: root group: root
mode: "u=rwx,g=r,o=r" mode: "u=rwx,g=r,o=r"
notify: restart nginx notify: restart nginx
tags:
- nginx
- stat: path=/etc/letsencrypt/live/schnidrig.dynv6.net/fullchain.pem - stat: path=/etc/letsencrypt/live/schnidrig.dynv6.net/fullchain.pem
register: letsencrypt_cert register: letsencrypt_cert
tags:
- nginx
- name: overwrite nginx config for letsencrypt initialisation - name: overwrite nginx config for letsencrypt initialization
template: template:
src: nginx.init.conf.j2 src: nginx.init.conf.j2
dest: "/etc/nginx/sites-available/openhab.conf" dest: "/etc/nginx/sites-available/openhab.conf"
@@ -25,8 +21,6 @@
mode: "u=rwx,g=r,o=r" mode: "u=rwx,g=r,o=r"
notify: restart nginx notify: restart nginx
when: letsencrypt_cert.stat.exists == false when: letsencrypt_cert.stat.exists == false
tags:
- nginx
- name: create nginx passwd file - name: create nginx passwd file
htpasswd: htpasswd:
@@ -37,16 +31,12 @@
group: root group: root
mode: "u=rw" mode: "u=rw"
notify: restart nginx notify: restart nginx
tags:
- nginx
- name: remove default site - name: remove default site
file: file:
dest: /etc/nginx/sites-enabled/default dest: /etc/nginx/sites-enabled/default
state: absent state: absent
notify: restart nginx notify: restart nginx
tags:
- nginx
- name: enable openhab site - name: enable openhab site
file: file:
@@ -54,30 +44,21 @@
dest: /etc/nginx/sites-enabled/openhab.conf dest: /etc/nginx/sites-enabled/openhab.conf
state: link state: link
notify: restart nginx notify: restart nginx
tags:
- nginx
- name: ssl dir - name: ssl dir
file: file:
dest: /etc/nginx/ssl dest: /etc/nginx/ssl
state: directory state: directory
tags:
- nginx
- name: create self singed certificate - name: create self singed certificate
command: 'openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt -subj "/C=CH/ST=AG/L=Niederlenz/O=none/OU=none/CN=schnidrig.dynv6.net"' command: 'openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt -subj "/C=CH/ST=AG/L=Niederlenz/O=none/OU=none/CN=schnidrig.dynv6.net"'
args: args:
creates: "/etc/nginx/ssl/nginx.crt" creates: "/etc/nginx/ssl/nginx.crt"
tags:
- nginx
- name: gen dhparam - name: gen dhparam
command: 'openssl dhparam -outform PEM -out /etc/nginx/ssl/dhparam2048.pem 2048' command: 'openssl dhparam -outform PEM -out /etc/nginx/ssl/dhparam2048.pem 2048'
args: args:
creates: "/etc/nginx/ssl/dhparam2048.pem" creates: "/etc/nginx/ssl/dhparam2048.pem"
notify: restart nginx notify: restart nginx
tags:
- nginx

View File

@@ -3,11 +3,12 @@
- name: - name:
user: user:
name: openhab name: openhab
groups: "dialout" groups:
- dialout
- tty
- bluetooth
- audio
append: yes append: yes
tags:
- openhab2
- user
- name: "configure systemd" - name: "configure systemd"
systemd: systemd:
@@ -15,19 +16,14 @@
daemon_reload: yes daemon_reload: yes
enabled: true enabled: true
state: started state: started
tags:
- openhab2
- name: Download Rollershutters dependencies - name: Download Rollershutters dependencies
get_url: get_url:
url: "{{ item.src }}" url: "{{ item.src }}"
dest: "/usr/share/openhab2/runtime/lib/boot/{{ item.name }}" dest: "/usr/share/openhab2/runtime/lib/boot/{{ item.name }}"
loop: loop:
#- { name: "jython-standalone-2.7.0.jar", src: 'http://search.maven.org/remotecontent?filepath=org/python/jython-standalone/2.7.0/jython-standalone-2.7.0.jar' } - { name: "jython-standalone-2.7.1.jar", src: 'http://search.maven.org/remotecontent?filepath=org/python/jython-standalone/2.7.1/jython-standalone-2.7.1.jar' }
- { name: "snakeyaml-1.18.jar", src: "http://central.maven.org/maven2/org/yaml/snakeyaml/1.18/snakeyaml-1.18.jar" } - { name: "snakeyaml-1.25.jar", src: "http://central.maven.org/maven2/org/yaml/snakeyaml/1.25/snakeyaml-1.25.jar" }
tags:
- openhab2
- jython
- name: cron job - name: cron job
cron: cron:
@@ -36,11 +32,8 @@
hour: "5" hour: "5"
weekday: "0" weekday: "0"
job: 'systemctl restart nginx.service' job: 'systemctl restart nginx.service'
cron_file: openhab cron_file: openhab2
user: root user: root
tags:
- openhab2
- openhab_cron
- name: cron job - name: cron job
cron: cron:
@@ -49,12 +42,8 @@
hour: "5" hour: "5"
weekday: "0" weekday: "0"
job: 'touch /etc/openhab2/automation/jsr223/shutters.py' job: 'touch /etc/openhab2/automation/jsr223/shutters.py'
cron_file: openhab cron_file: openhab2
user: root user: root
tags:
- openhab2
- openhab_cron
- name: install python modules for jython - name: install python modules for jython
pip: pip:
@@ -62,16 +51,12 @@
virtualenv_command: "/usr/bin/virtualenv" virtualenv_command: "/usr/bin/virtualenv"
virtualenv_python: "/usr/bin/python2.7" virtualenv_python: "/usr/bin/python2.7"
name: jsonmerge name: jsonmerge
tags:
- openhab2
- name: enable virtual env from above in jython - name: set EXTRA_JAVA_OPTS
lineinfile: lineinfile:
path: "/etc/default/openhab2" path: "/etc/default/openhab2"
regexp: '^EXTRA_JAVA_OPTS=' regexp: '^EXTRA_JAVA_OPTS='
line: 'EXTRA_JAVA_OPTS="-Dpython.path=/etc/openhab2/automation/lib/python/lib/python2.7/site-packages/"' line: 'EXTRA_JAVA_OPTS="-Dpython.path=/etc/openhab2/automation/lib/python/lib/python2.7/site-packages/ -Dgnu.io.rxtx.SerialPorts=/dev/ttyACM0:/dev/ttyACM1:/dev/ttyUSB0:/dev/ttyUSB1:/dev/ttyS0:/dev/ttyS2:/dev/ttyAMA0"'
tags:
- openhab2

View File

@@ -2,21 +2,17 @@
- name: install openhab packages - name: install openhab packages
apt: apt:
pkg: "{{item}}" pkg:
- zulu-embedded-8 # java 8
- openhab2
- openhab2-addons
- openhab2-addons-legacy
- sysstat
- nginx
- python-pip # jython only supports 2.7
- virtualenv
- python-passlib
update_cache: "{{apt_config.update_cache}}" update_cache: "{{apt_config.update_cache}}"
cache_valid_time: "{{apt_config.cache_valid_time}}" cache_valid_time: "{{apt_config.cache_valid_time}}"
with_items:
- "{{jdk}}"
- openhab2
- openhab2-addons
- openhab2-addons-legacy
- sysstat
- nginx
- python-passlib
#- jython
#- jython-doc
tags:
- packages
- openhab2

View File

@@ -6,18 +6,26 @@
apt_key: apt_key:
url: "https://bintray.com/user/downloadSubjectPublicKey?username=openhab" url: "https://bintray.com/user/downloadSubjectPublicKey?username=openhab"
state: present state: present
tags:
- repo
- openhab2
- name: install openhab2 repo - name: install openhab2 repo
apt_repository: apt_repository:
repo: 'deb https://dl.bintray.com/openhab/apt-repo2 stable main' repo: 'deb https://dl.bintray.com/openhab/apt-repo2 stable main'
#repo: 'deb http://openhab.jfrog.io/openhab/openhab-linuxpkg unstable main'
state: present state: present
update_cache: yes update_cache: yes
filename: openhab2 filename: openhab2
tags:
- repo
- openhab2
# Zulu
# https://docs.azul.com/zulu/zuludocs/ZuluUserGuide/PrepareZuluPlatform/AttachAPTRepositoryUbuntuOrDebianSys.htm
- name: install zulu key
apt_key:
keyserver: hkp://keyserver.ubuntu.com:80
id: B1998361219BD9C9
state: present
- name: install zulu repo
apt_repository:
repo: 'deb http://repos.azulsystems.com/debian stable main'
state: present
update_cache: yes
filename: zulu

View File

@@ -4,8 +4,6 @@
file: file:
dest: /root/bin dest: /root/bin
state: directory state: directory
tags:
- scripts
- name: create scripts - name: create scripts
template: template:
@@ -16,5 +14,3 @@
mode: "u=rwx,g=r,o=r" mode: "u=rwx,g=r,o=r"
loop: loop:
- karaf.sh - karaf.sh
tags:
- scripts

View File

@@ -1,11 +1,10 @@
server { server {
listen [::]:80; listen [::]:80 ipv6only=off;
server_name {{fqdn}}; server_name {{fqdn}};
return 301 https://$server_name$request_uri; return 301 https://$server_name$request_uri;
} }
server { server {
#listen [::]:80; listen [::]:443 ipv6only=off ssl;
listen [::]:443 ssl;
server_name {{fqdn}}; server_name {{fqdn}};
ssl_certificate /etc/letsencrypt/live/schnidrig.dynv6.net/fullchain.pem; ssl_certificate /etc/letsencrypt/live/schnidrig.dynv6.net/fullchain.pem;

View File

@@ -1,6 +1,6 @@
server { server {
listen [::]:80; listen [::]:80 ipv6only=off;
listen [::]:443 ssl; listen [::]:443 ipv6only=off ssl;
server_name schnidrig.dynv6.net; server_name schnidrig.dynv6.net;
ssl_certificate /etc/nginx/ssl/nginx.crt; ssl_certificate /etc/nginx/ssl/nginx.crt;

View File

@@ -1,9 +1,7 @@
--- ---
- name: restart ntp - name: timedatectl
service: name=ntp state=restarted command: timedatectl set-ntp true
- name: update exportfs - name: update exportfs
shell: exportfs -rav shell: exportfs -rav

View File

@@ -13,8 +13,6 @@
- name: generate locale - name: generate locale
locale_gen: name="{{locale}}" state=present locale_gen: name="{{locale}}" state=present
tags:
- locale
- name: set environment file - name: set environment file
template: template:

View File

@@ -1,10 +1,17 @@
--- ---
- include: packages.yml - include: packages.yml
- include: ntp.yml tags:
- include: timezone.yml - packages
- include: locale.yml - include: timedate.yml
tags:
- ntp
# - include: locale.yml
# tags:
# - locale
- include: skeleton.yml - include: skeleton.yml
tags:
- skeleton

View File

@@ -2,25 +2,15 @@
- name: ensure packages are installed - name: ensure packages are installed
apt: apt:
pkg: "{{item}}" pkg:
update_cache: "{{apt_config.update_cache}}"
cache_valid_time: "{{apt_config.cache_valid_time}}"
with_items:
- apt-transport-https - apt-transport-https
- ntp
- tmux - tmux
- python-pip
- python3-pip - python3-pip
- git - git
- multitail - multitail
- python3-requests - python3-requests
tags: - python3-websocket
- packages update_cache: "{{apt_config.update_cache}}"
cache_valid_time: "{{apt_config.cache_valid_time}}"
- name: install python 3 modules with pip
pip:
name: websocket-client
executable: pip3
tags:
- packages

View File

@@ -3,17 +3,8 @@
- name: alias - name: alias
copy: copy:
src: alias src: alias
dest: "/home/pi/.alias" dest: "/home/pi/.bash_aliases"
owner: pi owner: pi
group: pi group: pi
mode: "u=rw,g=r,o=r" mode: "u=rw,g=r,o=r"
tags:
- alias
- name: update bashrc
lineinfile:
dest=/home/pi/.bashrc
line="test -s ~/.alias && . ~/.alias"
tags:
- alias

View File

@@ -0,0 +1,13 @@
---
- name: update ntp.conf
lineinfile:
dest: "/etc/systemd/timesyncd.conf"
regexp: '^#*\s*NTP='
line: "NTP={{ ntp | join(' ') }}"
notify: timedatectl
- name: "set Timezone"
timezone:
name: "{{ timezone }}"
notify: timedatectl