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

Upgrade to openhab 2

letsencrypt
This commit is contained in:
Christian Schnidrig
2017-02-26 22:22:25 +01:00
parent 181acab247
commit 0b6010e3a6
30 changed files with 533 additions and 16 deletions

View File

@@ -0,0 +1,11 @@
---
- name: create backup script
template:
src: backup.sh.j2
dest: "/root/backup"
owner: root
group: root
mode: "u=rwx,g=r,o=r"
tags:
- backup

View File

@@ -0,0 +1,11 @@
---
- name: install dynv6 update script
template:
src: dynv6.sh.j2
dest: "/root/dynv6.sh"
owner: root
group: root
mode: "u=rwx,g=r,o=r"
tags:
- dynv6

View File

@@ -0,0 +1,32 @@
---
- name: download HABmin
get_url:
url: https://github.com/cdjackson/HABmin/archive/master.zip
dest: /root/habmin_master.zip
mode: 0444
tags:
- habmin
- name: unzip
unarchive:
remote_src: yes
src: /root/habmin_master.zip
dest: /usr/share/openhab/webapps/
creates: "/usr/share/openhab/webapps/habmin"
tags:
- habmin
- name: rename
command: creates="/usr/share/openhab/webapps/habmin" mv "/usr/share/openhab/webapps/HABmin-master" "/usr/share/openhab/webapps/habmin"
tags:
- habmin
- name: install addon
command: creates="/usr/share/openhab/addons/org.openhab.io.habmin-1.8.0.jar" mv "/usr/share/openhab/webapps/habmin/addons/org.openhab.io.habmin-1.7.0-SNAPSHOT.jar" "/usr/share/openhab/addons/org.openhab.io.habmin-1.8.0.jar"
tags:
- habmin

View File

@@ -0,0 +1,27 @@
---
- name: download certbot
get_url:
url: https://dl.eff.org/certbot-auto
dest: /root/certbot-auto
mode: 0540
tags:
- letsencrypt
- 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: '/root/certbot-auto -n run --nginx --agree-tos --email {{letsencrypt_email}} -d {{fqdn}}'
tags:
- letsencrypt
- name: cron job
cron:
name: "get new certificate"
minute: "0"
hour: "5"
day: "11"
job: '/root/certbot-auto -n certonly --nginx --agree-tos --email {{letsencrypt_email}} -d {{fqdn}}'
tags:
- letsencrypt

View File

@@ -0,0 +1,15 @@
---
- include: repo.yml
- include: packages.yml
- include: openhab.yml
#- include: habmin.yml
- include: nfs.yml
- include: mysql.yml
- include: backup.yml
- include: nginx.yml
- include: dynv6.yml
- include: letsencrypt.yml

View File

@@ -0,0 +1,29 @@
---
- name: install mysql packages
apt:
pkg: "{{item}}"
update_cache: "{{apt_config.update_cache}}"
cache_valid_time: "{{apt_config.cache_valid_time}}"
with_items:
- mysql-server
- python-mysqldb
tags:
- mysql
- name: Create openhab database
mysql_db:
name: openhab2
state: present
tags:
- mysql
- mysql_user:
name: openhab2
password: openhab2
priv: '*.*:ALL'
state: present
tags:
- mysql

View File

@@ -0,0 +1,31 @@
---
- 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
- openhab2
- 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/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

@@ -0,0 +1,83 @@
---
- name: create nginx config
template:
src: nginx.conf.j2
dest: "/etc/nginx/sites-available/openhab.conf"
owner: root
group: root
mode: "u=rwx,g=r,o=r"
notify: restart nginx
tags:
- nginx
- stat: path=/etc/letsencrypt/live/schnidrig.dynv6.net/fullchain.pem
register: letsencrypt_cert
tags:
- nginx
- name: overwrite nginx config for letsencrypt initialisation
template:
src: nginx.init.conf.j2
dest: "/etc/nginx/sites-available/openhab.conf"
owner: root
group: root
mode: "u=rwx,g=r,o=r"
notify: restart nginx
when: letsencrypt_cert.stat.exists == false
tags:
- nginx
- name: create nginx passwd file
htpasswd:
name: "{{nginx_user}}"
password: "{{nginx_password}}"
path: "/etc/nginx/htpasswd"
owner: root
group: root
mode: "u=rw"
notify: restart nginx
tags:
- nginx
- name: remove default site
file:
dest: /etc/nginx/sites-enabled/default
state: absent
notify: restart nginx
tags:
- nginx
- name: enable openhab site
file:
src: /etc/nginx/sites-available/openhab.conf
dest: /etc/nginx/sites-enabled/openhab.conf
state: link
notify: restart nginx
tags:
- nginx
- name: ssl dir
file:
dest: /etc/nginx/ssl
state: directory
tags:
- nginx
- 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"'
args:
creates: "/etc/nginx/ssl/nginx.crt"
tags:
- nginx
- name: gen dhparam
command: 'openssl dhparam -outform PEM -out /etc/nginx/ssl/dhparam2048.pem 2048'
args:
creates: "/etc/nginx/ssl/dhparam2048.pem"
notify: restart nginx
tags:
- nginx

View File

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

View File

@@ -0,0 +1,20 @@
---
- name: install openhab packages
apt:
pkg: "{{item}}"
update_cache: "{{apt_config.update_cache}}"
cache_valid_time: "{{apt_config.cache_valid_time}}"
with_items:
- "{{jdk}}"
- openhab2
- openhab2-addons
- openhab2-addons-legacy
- sysstat
- nginx
- python-passlib
tags:
- packages
- openhab2

View File

@@ -0,0 +1,22 @@
---
# http://docs.openhab.org/installation/linux.html#package-repository-installation
- name: install ppa key
apt_key:
url: "http://www.openhab.org/keys/public-key-snapshots.asc"
state: present
tags:
- repo
- openhab2
- name: install openhab2 repo
apt_repository:
repo: 'deb https://openhab.ci.cloudbees.com/job/openHAB-Distribution/ws/distributions/openhab-offline/target/apt-repo/ /'
state: present
update_cache: yes
filename: openhab2
tags:
- repo
- openhab2

View File

@@ -0,0 +1,22 @@
---
# http://docs.openhab.org/installation/linux.html#package-repository-installation
- name: install ppa key
apt_key:
url: "https://bintray.com/user/downloadSubjectPublicKey?username=openhab"
state: present
tags:
- repo
- openhab2
- name: install openhab2 repo
apt_repository:
repo: 'deb http://dl.bintray.com/openhab/apt-repo2 testing main'
state: present
update_cache: yes
filename: openhab2
tags:
- repo
- openhab2