diff --git a/README.md b/README.md index 9e2eaa1..b68cc97 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,14 @@ # openhab-ansible -Ansible playbooks to setup openhab on a raspberry pi. It'll install mosquitto and mqttwarn as well. Mqttwarn is configured to send data to graphite. +Ansible playbooks to setup openhab on a raspberry pi. ## Prepare Raspberry Pi - ### Install raspian +Using the [Raspberry Pi Imager](https://www.raspberrypi.org/software/) install the latest (buster) version. -Download it from [https://www.raspberrypi.org/downloads/raspbian/](https://www.raspberrypi.org/downloads/raspbian/) - -Unzip and copy it onto an sdcard - -e.g on a mac with sdcard reader that would be: - - sudo dd bs=1m if=2016-09-23-raspbian-jessie-lite.img of=/dev/rdiskXYZ - - -mount sdcard and create an empty file `ssh` at the top level directory. +Mount sd-card and create an empty file `ssh` at the top level directory. Eject card and then insert sdcard into rasberry pi and boot. - -### Configure fixed ip address +### Optional: Configure fixed ip address Edit the file `/etc/dhcpcd.conf` and add the following lines (according to your network) and reboot. @@ -29,19 +19,25 @@ Edit the file `/etc/dhcpcd.conf` and add the following lines (according to your ### User setup -- Change password of user pi. -- Install ssh public key for user pi +- Install /home/pi/.ssh/authorized_keys for user pi +- delete password for user pi: `passwd --delete pi` -## memory split +### Dist Upgrade - sudo raspi-config +Upgrade all packages to newest version: -Then from the advanced menu, change the memory split for the GPU to "16" -restart. + apt update + apt dist-upgrade -y ## Run ansible playbook +first install some galaxy roles: + + ansible-galaxy collection install community.general + ansible-galaxy collection install community.docker + Edit group_vars/all/vault. +Edit inventory. Check/change other values in group_vars ansible-playbook -i inventory raspi.yml @@ -50,8 +46,20 @@ ansible-playbook -i inventory raspi.yml https://github.com/openhab/openhab/wiki/Hardware-FAQ -# install docker -https://www.raspberrypi.org/blog/docker-comes-to-raspberry-pi/ -curl -sSL https://get.docker.com | sh +## Logging Config +add the following to /home/pi/userdata/etc/log4j2.xml + + + + + + + + + + + + + diff --git a/ansible.cfg b/ansible.cfg index 65e67b5..4e95c57 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -1,6 +1,6 @@ [defaults] -interpreter_python = auto_silent -#interpreter_python = /usr/bin/python3 +#interpreter_python = auto_silent +interpreter_python = /usr/bin/python3 retry_files_enabled = False vault_password_file = vault_password diff --git a/group_vars/all/defaults b/group_vars/all/defaults index 39ca86e..b516e30 100644 --- a/group_vars/all/defaults +++ b/group_vars/all/defaults @@ -1,5 +1,13 @@ --- +jdk: "zulu11.45.27-ca-jdk11.0.10-linux_aarch32hf" +jdk_url: "https://cdn.azul.com/zulu-embedded/bin/{{ jdk }}.tar.gz" + +openhab_version: "3.0.1" +openhab_userid: "1000" +openhab_groupid: "1000" +openhab_root_dir: "/home/pi/openhab" + timezone: "Europe/Zurich" locale: "en_US.UTF-8" @@ -8,7 +16,7 @@ apt_config: cache_valid_time: 7200 ntp: - - "ntp.bluewin.ch" + - "ch.pool.ntp.org" letsencrypt_email: christian.schnidrig@gmail.com diff --git a/group_vars/all/vault b/group_vars/all/vault index b53c666..fbd7973 100644 --- a/group_vars/all/vault +++ b/group_vars/all/vault @@ -1,24 +1,24 @@ $ANSIBLE_VAULT;1.1;AES256 -65343063363130666335313366396139653130333535653437376464666230653230656662663738 -3239336161333434336264386436393738653637346561370a626437323632323866366139613339 -36343964666562636666663766613032333133303931356537353334353635333236396630323963 -6133666333633837370a376266346364396264626136363766383735383362343366373134616231 -33303732316632376563373330336534623934393166346233633666343136653735653363653538 -38613733393366303730323466383136346563386531376338333731643762326232373631653563 -64333965313730363133663663613563396664613463333936363833396333363131313164646463 -62393861633133366539656662643037616362633964626335373338383563663865306339616438 -31373063623635316232313262353563646331346438376538343635373966313235623038643763 -35633139363636663837323166393563616132663633633331363136326634363562376138356437 -33303166306562663061306437353566386563633030623835376633393865303238313866656262 -32653632643765343062363264623338336664656432373934656433663639313635383364646430 -37653037386664333437663737626535373463656564623262613638313333643336613663393835 -32613663393865643665393931323235653937626533366363326266663666393438623937643265 -66626330363238663866393662636561623934633232646536393831623735343162303339313238 -30376536343766333234396539386237333132356637623336313535356564356437303763383332 -31383437313963306231343166623532383064383938636433313365363333646636383631326330 -36653630653733383232663639303762653237306333393564323335333130356639393535613030 -32386338326264343333396233633138363633663234346535346138326661643931306439316261 -62373831373462326263316232613338626132353564383262643332623563626465363938623932 -62303436363863386464343135306362636232363833303237393562393037663436353136336538 -66646333653031306362393539363836333063353765313464366363353361616464333733303463 -376331376261323236333164343761663362 +34363564646666363162653136653537316337633261336362616364656530636162653963646330 +3361613432316635303066353866303666656562343634610a656266653533653639613262386434 +62386533636564316236313932326365613833366438333862376538623132646430336230326436 +3939636266313732340a353834633862343339646631353230366163393636333937323663633038 +64653237616539393035613663303636323066323163356133326630656262623433336239363766 +62663464663664333261353230303139633666376662323038363166366661356232623635643031 +30666564373865663439616638656138393165613566333161363765356637313963366232336238 +31323234373337343764363432313138656166616338376134633963363437373835643530336466 +32373039613361616365613835313765326635383161336462366238343264613235643432303232 +34306130346562313266393030616236386666366431333435646663646261343432376231353739 +61313230313031303538393266326164653965303661323834323963343163356332393164616638 +63353661303461346566663039653731316534376631336434636431323564383362636264333231 +66643835366531613535303164613166333864383064373363386332656638636230646365666335 +34326435343339373931646661326636646633313536633334356435373831613966323365383334 +39636430343362346435306538393233343831353162303732623133663736616662616535333131 +36613935323336353230636230373931666438336331333034306437393038323664353334373364 +31336633663934653438653162376666303464306438353231613863623934306366386237363961 +32363663666235363763333265663431333366646534373730343837616431626233346135363464 +62653936616636613032316264376634376464373964363235356263346138396564643137313265 +31313335313866656664323936633566386466366163303030306665343366623638626230386431 +31383030613739663638333062623462326163346263616239316263343563396364633732613335 +31393338343863343866343438306264383163303164363137363533373965356434306264633832 +633138313233363566396463633661393538 diff --git a/group_vars/all/vault.sample b/group_vars/all/vault.sample index 536919e..79671eb 100644 --- a/group_vars/all/vault.sample +++ b/group_vars/all/vault.sample @@ -2,8 +2,6 @@ # uncomment the variables and add info -vault_openhab_config_repo: "ssh://>@:/path/repo.git" - vault_nginx_user: vault_nginx_password: diff --git a/group_vars/controller b/group_vars/raspberry similarity index 61% rename from group_vars/controller rename to group_vars/raspberry index 62e1731..5bc2135 100644 --- a/group_vars/controller +++ b/group_vars/raspberry @@ -1,16 +1,6 @@ --- -#bindings: -# - astro -# - ntp -# - rfxcom -# - weather -# - mqtt -# - zwave - -#persistence: -# - mqtt -# - mysql +user_name: pi #graphite_server: 'grafana.dynv6.net' graphite_server: "192.168.1.96" @@ -19,9 +9,7 @@ nginx_user: "{{ vault_nginx_user }}" nginx_password: "{{ vault_nginx_password }}" dynv6_name: "schnidrig.dynv6.net" -#dynv6_name: "raspi4.dynv6.net" dynv6_device: "{{ vault_dynv6_device }}" dynv6_token: "{{ vault_dynv6_token }}" fqdn: "schnidrig.dynv6.net" -#fqdn: "raspi4.dynv6.net" \ No newline at end of file diff --git a/inventory b/inventory index b29c337..3be3f89 100644 --- a/inventory +++ b/inventory @@ -1,9 +1,3 @@ -[controller] -192.168.1.7 ansible_ssh_user=pi -192.168.1.12 ansible_ssh_user=pi -192.168.1.9 ansible_ssh_user=pi - -[raspis] -#192.168.1.5 ansible_ssh_user=pi -192.168.1.7 ansible_ssh_user=pi -192.168.1.12 ansible_ssh_user=pi +[raspberry] +openhab ansible_ssh_user=pi +raspi4 ansible_ssh_user=pi diff --git a/raspi.yml b/openhab.yml similarity index 56% rename from raspi.yml rename to openhab.yml index 92d74f9..e161f60 100644 --- a/raspi.yml +++ b/openhab.yml @@ -1,11 +1,11 @@ --- -- hosts: controller +- hosts: raspberry become: true gather_facts: no roles: - raspberry - - mqttwarn - - openhab2 + #- mqttwarn + - openhab diff --git a/roles/openhab2/handlers/main.yml b/roles/openhab/handlers/main.yml similarity index 100% rename from roles/openhab2/handlers/main.yml rename to roles/openhab/handlers/main.yml diff --git a/roles/openhab2/tasks/dynv6.yml b/roles/openhab/tasks/dynv6.yml similarity index 100% rename from roles/openhab2/tasks/dynv6.yml rename to roles/openhab/tasks/dynv6.yml diff --git a/roles/openhab/tasks/habmin.yml b/roles/openhab/tasks/habmin.yml deleted file mode 100644 index a88dfd1..0000000 --- a/roles/openhab/tasks/habmin.yml +++ /dev/null @@ -1,32 +0,0 @@ ---- - - -- 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 - - diff --git a/roles/openhab/tasks/jdk.yml b/roles/openhab/tasks/jdk.yml new file mode 100644 index 0000000..2892af7 --- /dev/null +++ b/roles/openhab/tasks/jdk.yml @@ -0,0 +1,22 @@ + +- name: create directories + file: + path: "{{ item }}" + owner: root + group: root + mode: '0755' + state: directory + loop: + - "/opt/jdk" + +- name: Get JDK + ansible.builtin.unarchive: + src: "{{ jdk_url }}" + dest: "/opt/jdk" + remote_src: yes + creates: "/opt/jdk/{{ jdk }}" + +- name: Set alternatives + shell: "update-alternatives --install /usr/bin/java java /opt/jdk/{{ jdk }}/bin/java 1" +- name: Set alternatives + shell: "update-alternatives --install /usr/bin/javac javac /opt/jdk/{{ jdk }}/bin/javac 1" diff --git a/roles/openhab2/tasks/letsencrypt.yml b/roles/openhab/tasks/letsencrypt.yml similarity index 95% rename from roles/openhab2/tasks/letsencrypt.yml rename to roles/openhab/tasks/letsencrypt.yml index a74400d..2850c0b 100644 --- a/roles/openhab2/tasks/letsencrypt.yml +++ b/roles/openhab/tasks/letsencrypt.yml @@ -4,7 +4,7 @@ apt: pkg: - certbot - - python-certbot-nginx + #- python-certbot-nginx - python3-certbot-nginx update_cache: "{{apt_config.update_cache}}" cache_valid_time: "{{apt_config.cache_valid_time}}" diff --git a/roles/openhab/tasks/main.yml b/roles/openhab/tasks/main.yml index 200b4c1..a8ac0b2 100644 --- a/roles/openhab/tasks/main.yml +++ b/roles/openhab/tasks/main.yml @@ -1,10 +1,37 @@ --- -- include: repo.yml -- include: packages.yml +- include: jdk.yml + tags: + - jdk + - openhab_all - include: openhab.yml -- include: habmin.yml -- include: nfs.yml -- include: mysql.yml + tags: + - openhab + - openhab_all +- include: rollershutters.yml + tags: + - rollershutters + - openhab_all +- include: nginx.yml + tags: + - nginx + - openhab_all +- include: dynv6.yml + tags: + - dynv6 + - openhab_all +- include: letsencrypt.yml + tags: + - letsencrypt + - openhab_all +- include: scripts.yml + tags: + - scripts + - openhab_all +# - include: gardena.yml +# tags: +# - gardena +# - openhab_all + diff --git a/roles/openhab/tasks/mysql.yml b/roles/openhab/tasks/mysql.yml deleted file mode 100644 index 99f8b49..0000000 --- a/roles/openhab/tasks/mysql.yml +++ /dev/null @@ -1,29 +0,0 @@ ---- - -- 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: openhab - state: present - tags: - - mysql - -- mysql_user: - name: openhab - password: openhab - priv: '*.*:ALL' - state: present - tags: - - mysql - - diff --git a/roles/openhab/tasks/nfs.yml b/roles/openhab/tasks/nfs.yml deleted file mode 100644 index 79ba0a4..0000000 --- a/roles/openhab/tasks/nfs.yml +++ /dev/null @@ -1,30 +0,0 @@ ---- - -- 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 - - - diff --git a/roles/openhab2/tasks/nginx.yml b/roles/openhab/tasks/nginx.yml similarity index 89% rename from roles/openhab2/tasks/nginx.yml rename to roles/openhab/tasks/nginx.yml index 94ed03c..074c8d4 100644 --- a/roles/openhab2/tasks/nginx.yml +++ b/roles/openhab/tasks/nginx.yml @@ -1,5 +1,13 @@ --- +- name: ensure packages are installed + apt: + pkg: + - nginx + - python3-passlib + update_cache: "{{apt_config.update_cache}}" + cache_valid_time: "{{apt_config.cache_valid_time}}" + - name: create nginx config template: src: nginx.conf.j2 diff --git a/roles/openhab/tasks/openhab.yml b/roles/openhab/tasks/openhab.yml index 5539709..6e0ae8c 100644 --- a/roles/openhab/tasks/openhab.yml +++ b/roles/openhab/tasks/openhab.yml @@ -1,20 +1,61 @@ ---- -- name: - user: - name: openhab - groups: "dialout" - append: yes - tags: - - openhab - - user +- name: Add Openhab Repo Key + ansible.builtin.apt_key: + url: https://bintray.com/user/downloadSubjectPublicKey?username=openhab + state: present -- name: "configure systemd" - systemd: - name: openhab +- name: Add Openhab Repo + ansible.builtin.apt_repository: + repo: "deb https://dl.bintray.com/openhab/apt-repo2 stable main" + state: present + filename: openhab + +- name: ensure packages are installed + apt: + pkg: + - openhab + update_cache: "{{apt_config.update_cache}}" + cache_valid_time: "{{apt_config.cache_valid_time}}" + + +- name: Create a symbolic links + ansible.builtin.file: + src: "{{ item.src }}" + dest: "{{ item.dest }}" + owner: pi + group: pi + state: link + loop: + - {"src": "/usr/share/openhab", "dest": "/home/pi/openhab_bin"} + - {"src": "/usr/share/openhab/addons", "dest": "/home/pi/addons"} + - {"src": "/etc/openhab", "dest": "/home/pi/conf"} + - {"src": "/var/log/openhab", "dest": "/home/pi/logs"} + - {"src": "/var/lib/openhab", "dest": "/home/pi/userdata"} + - {"src": "/var/lib/openhab/backups", "dest": "/home/pi/backups"} + - {"src": "/usr/share/openhab/runtime/bin/client", "dest": "/home/pi/bin/client"} + - {"src": "/usr/share/openhab/runtime/bin/restore", "dest": "/home/pi/bin/restore"} + +- name: add directories + file: + path: "{{ item }}" + owner: root + group: root + mode: '0755' + state: directory + loop: + - "/etc/systemd/system/openhab.service.d" + +# original file from '/lib/systemd/system/openhab.service' +- name: openhab service + template: + src: openhab.service + dest: /etc/systemd/system/openhab.service.d/override.conf + +- name: force systemd to reread configs + ansible.builtin.systemd: daemon_reload: yes - enabled: true - state: started - tags: - - openhab +- name: Enable openhab service + ansible.builtin.service: + name: openhab + enabled: yes diff --git a/roles/openhab/tasks/packages.yml b/roles/openhab/tasks/packages.yml deleted file mode 100644 index d99c5ca..0000000 --- a/roles/openhab/tasks/packages.yml +++ /dev/null @@ -1,39 +0,0 @@ ---- - -- 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 - - sysstat - 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 - - - diff --git a/roles/openhab/tasks/repo.yml b/roles/openhab/tasks/repo.yml deleted file mode 100644 index 4384504..0000000 --- a/roles/openhab/tasks/repo.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- - -- 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 - diff --git a/roles/openhab/tasks/rollershutters.yml b/roles/openhab/tasks/rollershutters.yml new file mode 100644 index 0000000..7230d1b --- /dev/null +++ b/roles/openhab/tasks/rollershutters.yml @@ -0,0 +1,15 @@ + +- name: Download Rollershutters dependencies + get_url: + url: "{{ item.src }}" + dest: "/usr/share/openhab/addons/{{ item.name }}" + mode: "0644" + loop: + # https://mvnrepository.com/artifact/org.apache.servicemix.bundles/org.apache.servicemix.bundles.quartz + - name: "org.apache.servicemix.bundles.quartz-2.3.2_1.jar" + src: "https://repo1.maven.org/maven2/org/apache/servicemix/bundles/org.apache.servicemix.bundles.quartz/2.3.2_1/org.apache.servicemix.bundles.quartz-2.3.2_1.jar" + # seems to be included in openhab already + #- name: "snakeyaml-1.27.jar" + # src: "https://repo1.maven.org/maven2/org/yaml/snakeyaml/1.27/snakeyaml-1.27.jar" + tags: + - javalibs diff --git a/roles/openhab2/tasks/scripts.yml b/roles/openhab/tasks/scripts.yml similarity index 51% rename from roles/openhab2/tasks/scripts.yml rename to roles/openhab/tasks/scripts.yml index 13dd129..3a693c6 100644 --- a/roles/openhab2/tasks/scripts.yml +++ b/roles/openhab/tasks/scripts.yml @@ -2,15 +2,15 @@ - name: create scripts dir file: - dest: /root/bin + dest: "/home/pi/bin" state: directory - name: create scripts template: - src: "{{ item }}" - dest: "/root/bin/{{ item }}" + src: "{{ item }}.sh" + dest: "/home/pi/bin/{{ item }}" owner: root group: root - mode: "u=rwx,g=r,o=r" + mode: "u=rwx,g=xr,o=rx" loop: - - karaf.sh + - backup diff --git a/roles/openhab/templates/backup.sh b/roles/openhab/templates/backup.sh new file mode 100644 index 0000000..2fcb3a5 --- /dev/null +++ b/roles/openhab/templates/backup.sh @@ -0,0 +1,8 @@ + +BACKUP_DIR=" /var/lib/openhab/backups" +BACKUP_SERVER_URL="christian@ds3018:/volume1/backup/openhab" + +sudo /usr/share/openhab/runtime/bin/backup + +BACKUP_FILE=$(/bin/ls -tr ${BACKUP_DIR}/ |tail -1) +scp ${BACKUP_DIR}/${BACKUP_FILE} ${BACKUP_SERVER_URL}/ diff --git a/roles/openhab2/templates/dynv6.sh.j2 b/roles/openhab/templates/dynv6.sh.j2 similarity index 100% rename from roles/openhab2/templates/dynv6.sh.j2 rename to roles/openhab/templates/dynv6.sh.j2 diff --git a/roles/openhab2/templates/nginx.conf.j2 b/roles/openhab/templates/nginx.conf.j2 similarity index 55% rename from roles/openhab2/templates/nginx.conf.j2 rename to roles/openhab/templates/nginx.conf.j2 index 176c485..449d404 100644 --- a/roles/openhab2/templates/nginx.conf.j2 +++ b/roles/openhab/templates/nginx.conf.j2 @@ -1,12 +1,22 @@ + +# redirect http to https server { listen [::]:80 ipv6only=off; server_name {{fqdn}}; return 301 https://$server_name$request_uri; } + server { listen [::]:443 ipv6only=off ssl; server_name {{fqdn}}; + # Cross-Origin Resource Sharing + add_header 'Access-Control-Allow-Origin' '*' always; + add_header 'Access-Control-Allow_Credentials' 'true' always; + add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range' always; + add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH' always; + + # certificate ssl_certificate /etc/letsencrypt/live/schnidrig.dynv6.net/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/schnidrig.dynv6.net/privkey.pem; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; @@ -24,14 +34,31 @@ server { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; + proxy_read_timeout 3600; auth_basic "Openhab"; auth_basic_user_file /etc/nginx/htpasswd; } + + location /logs/ { + proxy_pass http://localhost:9001/; + sub_filter_once off; + sub_filter_types text/html; + sub_filter 'href="/' 'href="/logs/'; + sub_filter 'src="/' 'src="/logs/'; + sub_filter "path: '/socket.io'" "path: '/logs/socket.io'"; + + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + + auth_basic "Openhab"; + auth_basic_user_file /etc/nginx/htpasswd; + + } + location /.well-known/acme-challenge/ { root /var/www/html; } } - - diff --git a/roles/openhab2/templates/nginx.init.conf.j2 b/roles/openhab/templates/nginx.init.conf.j2 similarity index 100% rename from roles/openhab2/templates/nginx.init.conf.j2 rename to roles/openhab/templates/nginx.init.conf.j2 diff --git a/roles/openhab/templates/openhab.service b/roles/openhab/templates/openhab.service new file mode 100644 index 0000000..86c3b18 --- /dev/null +++ b/roles/openhab/templates/openhab.service @@ -0,0 +1,5 @@ +[Service] +User= +User=pi +Group= +Group=pi diff --git a/roles/openhab2/tasks/backup.yml b/roles/openhab2/tasks/backup.yml deleted file mode 100644 index a70474d..0000000 --- a/roles/openhab2/tasks/backup.yml +++ /dev/null @@ -1,9 +0,0 @@ ---- - -- name: create backup script - template: - src: backup.sh.j2 - dest: "/root/backup" - owner: root - group: root - mode: "u=rwx,g=r,o=r" diff --git a/roles/openhab2/tasks/gardena.yml b/roles/openhab2/tasks/gardena.yml deleted file mode 100644 index a85efb6..0000000 --- a/roles/openhab2/tasks/gardena.yml +++ /dev/null @@ -1,41 +0,0 @@ - -- name: install gardena service file - template: - src: "gardena/gardena.service" - dest: "/etc/systemd/system/gardena.service" - mode: u=rw,g=rw,o=r - -- name: install gardena service script - template: - src: "gardena/gardena_monitor_collector.py" - dest: "/etc/openhab2/automation/gardena/gardena_monitor_collector.py" - mode: u=rwx,g=rx,o=rx - group: root - owner: root - -- name: install gardena service config - template: - src: "gardena/gardena.yml" - dest: "/etc/openhab2/automation/gardena/gardena.yml" - mode: u=rw,g=r,o=r - group: openhab - owner: openhab - -- name: install gardena jsr223 script - template: - src: "gardena/gardena.py" - dest: "/etc/openhab2/automation/jsr223/gardena.py" - mode: u=rw,g=r,o=r - group: openhab - owner: openhab - -- name: enable gardena service - systemd: - daemon_reload: yes - -- name: Make sure gardena service is running - systemd: - state: started - name: gardena - - diff --git a/roles/openhab2/tasks/habmin.yml b/roles/openhab2/tasks/habmin.yml deleted file mode 100644 index a88dfd1..0000000 --- a/roles/openhab2/tasks/habmin.yml +++ /dev/null @@ -1,32 +0,0 @@ ---- - - -- 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 - - diff --git a/roles/openhab2/tasks/main.yml b/roles/openhab2/tasks/main.yml deleted file mode 100644 index a405d62..0000000 --- a/roles/openhab2/tasks/main.yml +++ /dev/null @@ -1,50 +0,0 @@ ---- - -- include: repo.yml - tags: - - repo - - openhab2 -- include: packages.yml - tags: - - packages - - openhab2 -- include: openhab.yml - tags: - - openhab - - openhab2 -#- include: habmin.yml -- include: nfs.yml - tags: - - nfs - - openhab2 -- include: mysql.yml - tags: - - mysql - - openhab2 -- include: backup.yml - tags: - - backup - - openhab2 -- include: nginx.yml - tags: - - nginx - - openhab2 -- include: dynv6.yml - tags: - - dynv6 - - openhab2 -- include: letsencrypt.yml - tags: - - letsencrypt - - openhab2 -- include: scripts.yml - tags: - - scripts - - openhab2 -- include: gardena.yml - tags: - - gardena - - openhab2 - - - diff --git a/roles/openhab2/tasks/mysql.yml b/roles/openhab2/tasks/mysql.yml deleted file mode 100644 index 8289d1f..0000000 --- a/roles/openhab2/tasks/mysql.yml +++ /dev/null @@ -1,24 +0,0 @@ ---- - -- name: install mysql packages - apt: - pkg: - - default-mysql-server - - python-mysqldb - update_cache: "{{apt_config.update_cache}}" - cache_valid_time: "{{apt_config.cache_valid_time}}" - -- name: Create openhab database - mysql_db: - name: openhab2 - state: present - tags: - - mysql - -- mysql_user: - name: openhab2 - password: openhab2 - priv: '*.*:ALL' - state: present - - diff --git a/roles/openhab2/tasks/nfs.yml b/roles/openhab2/tasks/nfs.yml deleted file mode 100644 index 289e370..0000000 --- a/roles/openhab2/tasks/nfs.yml +++ /dev/null @@ -1,22 +0,0 @@ ---- - -- name: ensure packages are installed - apt: - pkg: - - nfs-common - - nfs-kernel-server - update_cache: "{{apt_config.update_cache}}" - cache_valid_time: "{{apt_config.cache_valid_time}}" - -- 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)" } - - - diff --git a/roles/openhab2/tasks/openhab.yml b/roles/openhab2/tasks/openhab.yml deleted file mode 100644 index 2c7542d..0000000 --- a/roles/openhab2/tasks/openhab.yml +++ /dev/null @@ -1,62 +0,0 @@ ---- - -- name: - user: - name: openhab - groups: - - dialout - - tty - - bluetooth - - audio - append: yes - -- name: "configure systemd" - systemd: - name: openhab2 - daemon_reload: yes - enabled: true - state: started - -- name: Download Rollershutters dependencies - get_url: - url: "{{ item.src }}" - dest: "/usr/share/openhab2/runtime/lib/boot/{{ item.name }}" - loop: - - { 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.25.jar", src: "http://central.maven.org/maven2/org/yaml/snakeyaml/1.25/snakeyaml-1.25.jar" } - -- name: cron job - cron: - name: "restart openhab" - minute: "10" - hour: "5" - weekday: "0" - job: 'systemctl restart nginx.service' - cron_file: openhab2 - user: root - -- name: cron job - cron: - name: "touch shutters" - minute: "20" - hour: "5" - weekday: "0" - job: 'touch /etc/openhab2/automation/jsr223/shutters.py' - cron_file: openhab2 - user: root - -- name: install python modules for jython - pip: - virtualenv: "/etc/openhab2/automation/lib/python" - virtualenv_command: "/usr/bin/virtualenv" - virtualenv_python: "/usr/bin/python2.7" - name: jsonmerge - -- name: set EXTRA_JAVA_OPTS - lineinfile: - path: "/etc/default/openhab2" - regexp: '^EXTRA_JAVA_OPTS=' - 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"' - - - diff --git a/roles/openhab2/tasks/packages.yml b/roles/openhab2/tasks/packages.yml deleted file mode 100644 index f3f6d3d..0000000 --- a/roles/openhab2/tasks/packages.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- - -- name: install openhab packages - apt: - 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}}" - cache_valid_time: "{{apt_config.cache_valid_time}}" - - diff --git a/roles/openhab2/tasks/repo.old.yml b/roles/openhab2/tasks/repo.old.yml deleted file mode 100644 index c4da271..0000000 --- a/roles/openhab2/tasks/repo.old.yml +++ /dev/null @@ -1,22 +0,0 @@ ---- - -# 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 - diff --git a/roles/openhab2/tasks/repo.yml b/roles/openhab2/tasks/repo.yml deleted file mode 100644 index ef5e32e..0000000 --- a/roles/openhab2/tasks/repo.yml +++ /dev/null @@ -1,31 +0,0 @@ ---- - -# 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 - -- name: install openhab2 repo - apt_repository: - repo: 'deb https://dl.bintray.com/openhab/apt-repo2 stable main' - state: present - update_cache: yes - filename: 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 diff --git a/roles/openhab2/templates/backup.sh.j2 b/roles/openhab2/templates/backup.sh.j2 deleted file mode 100644 index 0e7cbee..0000000 --- a/roles/openhab2/templates/backup.sh.j2 +++ /dev/null @@ -1,12 +0,0 @@ -# stop openhab instance (here: systemd service) -#sudo systemctl stop openhab2.service - -# backup current installation with settings -TIMESTAMP=`date +%Y%m%d`; -tar -C / -czf /tmp/openhab2-backup-$TIMESTAMP.tgz etc/openhab2 var/lib/openhab2 - -echo "Now save the file /tmp/openhab2-backup-$TIMESTAMP.tgz" -echo " as regular user run: scp /tmp/openhab2-backup-$TIMESTAMP.tgz christian@ds3018:/volume1/backup" - -# start openhab instance -#sudo systemctl start openhab2.service diff --git a/roles/openhab2/templates/gardena/gardena.py b/roles/openhab2/templates/gardena/gardena.py deleted file mode 100644 index 0e188e5..0000000 --- a/roles/openhab2/templates/gardena/gardena.py +++ /dev/null @@ -1,180 +0,0 @@ -# Copyright (c) 2019 by Christian Schnidrig. - -# https://github.com/TooTallNate/Java-WebSocket - -# jython imports -from org.slf4j import LoggerFactory -import uuid -import math -import sys -import traceback -import time -import json -import jsonmerge - -# java imports -#from org.eclipse.smarthome.core.scheduler import CronExpression -import profile -from org.yaml.snakeyaml import Yaml -from java.nio.file.StandardWatchEventKinds import ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY -try: - from org.openhab.core.service import AbstractWatchService -except: - from org.eclipse.smarthome.core.service import AbstractWatchService - -####################################################### -####################################################### -####################################################### -# constants - -module_name = "gardena" -logger_name = "jython." + module_name -module_prefix = module_name + "_" - -# location of script -openhab_base_dir = '/etc/openhab2' -automationDir = openhab_base_dir + '/automation' -gardenaDir = automationDir + '/gardena' -gardena_config_file_name = 'gardena.yml' -gardena_config_file = gardenaDir + '/' + gardena_config_file_name -gardena_data_file_name = 'gardena.json' -gardena_data_file = gardenaDir + '/' + gardena_data_file_name - -####################################################### -# some globals -config = None -data = None - -# default logger -logger = LoggerFactory.getLogger(logger_name) - -####################################################### -####################################################### -####################################################### -# config -class Config(): - def __init__(self): - self.logger = LoggerFactory.getLogger(logger_name + ".Config") - self.gardenaConfig = Yaml().load(open(gardena_config_file)) - self.logger.info("Config loaded") - - def getDeviceMapping(self): - return self.gardenaConfig['device_mapping'] - - def getItemNamePrefix(self): - return self.gardenaConfig['item_name_prefix'] - - def getValueMapping(self): - return self.gardenaConfig['value_mapping'] - -####################################################### -####################################################### -####################################################### -# gardena monitor - -def gardena_monitor(): - logger = LoggerFactory.getLogger(logger_name + ".gardena_monitor") - config = Config() - - device_mapping = config.getDeviceMapping() - - data = {} - - with open (gardena_data_file, "r") as data_file: - lines=data_file.readlines() - for line in lines: - json_line = json.loads(line) - if 'attributes' in json_line.keys(): - data = jsonmerge.merge(data, {json_line['type']: { json_line['id']: json_line['attributes'] }}) - - logger.debug(json.dumps(data, indent=4)) - value_mapping = config.getValueMapping() - prefix = config.getItemNamePrefix() - for type in value_mapping: - for value_set in data[type]: - valve_number = None - id = value_set - if type == "VALVE": - id, valve_number = id.split(':') - if id in device_mapping: - device_name = device_mapping[id] - if type == "VALVE": - device_name = device_name + "_" + str(valve_number) - logger.debug("Found device: " + device_name + " of type: " + type) - for value_name in value_mapping[type]: - if not value_name.endswith('_map'): - if value_name in data[type][value_set]: - item_suffix = value_mapping[type][value_name] - item_name = prefix + "_" + device_name + "_" + item_suffix - item = ir.get(item_name) - if item == None: - logger.info("Item not found: " + item_name) - else: - value = str(data[type][value_set][value_name]['value']) - if value_name + '_map' in value_mapping[type]: - value = str(value_mapping[type][value_name + '_map'][value]) - logger.info("Set item " + item_name + " = " + value) - events.postUpdate(item_name, value) - -####################################################### -####################################################### -####################################################### -# fileWatcher - -class FileWatcher(AbstractWatchService): - def __init__(self, path, event_kinds=[ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY], watch_subdirectories=False): - AbstractWatchService.__init__(self, path) - self.logger = LoggerFactory.getLogger(logger_name + ".FileWatcher") - self.event_kinds = event_kinds - self.watch_subdirectories = watch_subdirectories - self.logger.debug("new fileWatcher for " + str(path) + " created.") - - def getWatchEventKinds(self, path): - return self.event_kinds - - def watchSubDirectories(self): - return self.watch_subdirectories - - def processWatchEvent(self, event, kind, path): - try: - self.logger.debug(event.toString()) - self.logger.debug(kind.toString()) - self.logger.debug(path.toString()) - if str(path.toString()) == gardena_config_file or str(path.toString()) == gardena_data_file: - logger.info("File " + str(path.toString()) + " changed. Reloading.") - try: - gardena_monitor() - except: - logger.error("gardena_monitor failed.") - logger.error(traceback.format_exc()) - except: - self.logger.error("processWatchEvent callback failed.") - self.logger.error(traceback.format_exc()) - self.deactivate() - self.activate() - -####################################################### -####################################################### -####################################################### -# __main__ - -fileWatcherGardena = None - -####################################################### -# script load/unload hooks -def scriptLoaded(id): - try: - logger.info("scriptLoaded()") - fileWatcherGardena = FileWatcher(gardenaDir) - fileWatcherGardena.activate() - gardena_monitor() - except: - logger.error(traceback.format_exc()) - if fileWatcherGardena is not None: - fileWatcherGardena.deactivate() - -def scriptUnloaded(): - logger.info("scriptUnloaded()") - if fileWatcherGardena is not None: - fileWatcherGardena.deactivate() - diff --git a/roles/openhab2/templates/gardena/gardena.service b/roles/openhab2/templates/gardena/gardena.service deleted file mode 100644 index cecc498..0000000 --- a/roles/openhab2/templates/gardena/gardena.service +++ /dev/null @@ -1,8 +0,0 @@ -[Unit] -Description=Service monitoring gardena web service - -[Service] -ExecStart=/etc/openhab2/automation/gardena/gardena_monitor_collector.py - -[Install] -WantedBy=multi-user.target diff --git a/roles/openhab2/templates/gardena/gardena.yml b/roles/openhab2/templates/gardena/gardena.yml deleted file mode 100644 index 513a300..0000000 --- a/roles/openhab2/templates/gardena/gardena.yml +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright (c) 2019 by Christian Schnidrig. - -######################## -device_mapping: - 164f4132-08e0-4d5f-b7f7-85048dd88281: sensor1 - ab9633cd-9a2a-4937-ac38-4f58717493b7: ic24 - -item_name_prefix: "gardena" - -value_mapping: - SENSOR: - soilHumidity: soil_humidity - soilTemperature: soil_temperature - lightIntensity: light_intensity - ambientTemperature: ambient_temperature - VALVE: - activity: state - activity_map: - CLOSED: "CLOSED" - MANUAL_WATERING: "OPEN" - SCHEDULED_WATERING: "OPEN" - name: name - COMMON: - batteryLevel: battery_level - rfLinkLevel: link_level - diff --git a/roles/openhab2/templates/gardena/gardena_monitor_collector.py b/roles/openhab2/templates/gardena/gardena_monitor_collector.py deleted file mode 100755 index d25ec22..0000000 --- a/roles/openhab2/templates/gardena/gardena_monitor_collector.py +++ /dev/null @@ -1,135 +0,0 @@ -#!/usr/bin/python3 - -import websocket -from threading import Thread -import time -import sys -import requests -import logging -import datetime - -logging.basicConfig(level=logging.DEBUG) - -############################## -# account specific values -USERNAME = '{{ vault_gardena_user }}' -PASSWORD = '{{ vault_gardena_password }}' -API_KEY = '{{ vault_gardena_api_key }}' - -############################## -# other constants -AUTHENTICATION_HOST = 'https://api.authentication.husqvarnagroup.dev' -SMART_HOST = 'https://api.smart.gardena.dev' - -dataFileName = "/etc/openhab2/automation/gardena/gardena.json" -logFileName = "/etc/openhab2/automation/gardena/gardena.json.log" - -############################## -module_name = "monitor" -logger_name = "gardena." + module_name -# default logger -logger = logging.getLogger(logger_name) - -############################## -class Client: - - def __init__(self, dataFile, logFile): - self.dataFileName = dataFileName - self.logFile = logFile - self.logger = logging.getLogger(logger_name + '.Client') - self.dataFile = None - - def on_message(self, message): - if self.dataFile != None: - self.dataFile.write(message) - self.dataFile.write('\n') - self.dataFile.flush() - logFile.write(message) - logFile.write('\n') - logFile.flush() - - def on_error(self, error): - self.logger.error(error) - - def on_close(self): - self.live = False - self.logger.info("### closed ###") - self.dataFile.close() - - def on_open(self): - self.logger.info("### connected ###") - self.dataFile = open(dataFileName, "w") - - self.live = True - - def run(*args): - while self.live: - time.sleep(1) - - Thread(target=run).start() - - - -############################## -if __name__ == "__main__": - - while True: - - try: - start = time.time() - logger.info(datetime.datetime.now()) - logFile = open(logFileName, "a") - - payload = {'grant_type': 'password', 'username': USERNAME, 'password': PASSWORD, - 'client_id': API_KEY} - - logger.debug("Logging into gardena system...") - r = requests.post('{}/v1/oauth2/token'.format(AUTHENTICATION_HOST), data=payload) - assert r.status_code == 200, r - auth_token = r.json()["access_token"] - logger.debug("Got token: {}".format(auth_token)) - - headers = { - "Content-Type": "application/vnd.api+json", - "x-api-key": API_KEY, - "Authorization-Provider": "husqvarna", - "Authorization": "Bearer " + auth_token - } - - r = requests.get('{}/v1/locations'.format(SMART_HOST), headers=headers) - assert r.status_code == 200, r - assert len(r.json()["data"]) > 0, 'location missing - user has not setup system' - location_id = r.json()["data"][0]["id"] - - payload = { - "data": { - "type": "WEBSOCKET", - "attributes": { - "locationId": location_id - }, - "id": "does-not-matter" - } - } - logger.debug("Logged in (%s), getting WebSocket ID..." % auth_token) - r = requests.post('{}/v1/websocket'.format(SMART_HOST), json=payload, headers=headers) - - assert r.status_code == 201, r - logger.info("WebSocket ID obtained, connecting...") - response = r.json() - websocket_url = response["data"]["attributes"]["url"] - - # websocket.enableTrace(True) - client = Client(dataFileName, logFile) - ws = websocket.WebSocketApp( - websocket_url, - on_message=client.on_message, - on_error=client.on_error, - on_close=client.on_close) - ws.on_open = client.on_open - ws.run_forever(ping_interval=150, ping_timeout=1) - - except: - delay = 15 * 60 - (time.time() - start) - if (delay > 0): - logger.info("Sleeping for: {} seconds before retrying.".format(delay)) - time.sleep(delay) diff --git a/roles/openhab2/templates/karaf.sh b/roles/openhab2/templates/karaf.sh deleted file mode 100644 index 21b62c6..0000000 --- a/roles/openhab2/templates/karaf.sh +++ /dev/null @@ -1 +0,0 @@ -ssh -p 8101 openhab@localhost diff --git a/roles/raspberry/files/alias b/roles/raspberry/files/alias deleted file mode 100644 index 8f3831d..0000000 --- a/roles/raspberry/files/alias +++ /dev/null @@ -1,5 +0,0 @@ -alias openhablog='tail -n 100 -f /var/log/openhab2/openhab.log -f /var/log/openhab2/events.log' -alias openhablog2='multitail /var/log/openhab2/openhab.log /var/log/openhab2/events.log' -alias openhablog3='multitail /var/log/openhab2/openhab.log -ci yellow -I /var/log/openhab2/events.log' -alias ls='/bin/ls -aF --color=auto' -alias karafshell="sudo su -s /bin/bash -c '/usr/share/openhab2/runtime/bin/client' openhab" diff --git a/roles/raspberry/handlers/main.yml b/roles/raspberry/handlers/main.yml index c89160b..70a3d08 100644 --- a/roles/raspberry/handlers/main.yml +++ b/roles/raspberry/handlers/main.yml @@ -5,3 +5,8 @@ - name: update exportfs shell: exportfs -rav + +- name: restart collectd + ansible.builtin.service: + name: collectd + state: restarted diff --git a/roles/raspberry/tasks/_attic/ntp.yml b/roles/raspberry/tasks/_attic/ntp.yml deleted file mode 100644 index ba9e516..0000000 --- a/roles/raspberry/tasks/_attic/ntp.yml +++ /dev/null @@ -1,28 +0,0 @@ ---- - -- 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 - diff --git a/roles/raspberry/tasks/_attic/timezone.yml b/roles/raspberry/tasks/_attic/timezone.yml deleted file mode 100644 index b2535d7..0000000 --- a/roles/raspberry/tasks/_attic/timezone.yml +++ /dev/null @@ -1,22 +0,0 @@ ---- - -- 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 diff --git a/roles/raspberry/tasks/collectd.yml b/roles/raspberry/tasks/collectd.yml new file mode 100644 index 0000000..ecf17f5 --- /dev/null +++ b/roles/raspberry/tasks/collectd.yml @@ -0,0 +1,17 @@ +- name: ensure packages are installed + apt: + pkg: + - collectd + update_cache: "{{apt_config.update_cache}}" + cache_valid_time: "{{apt_config.cache_valid_time}}" + +- name: collectd config + template: + src: collectd.conf + dest: /etc/collectd/collectd.conf + notify: restart collectd + +- name: remove local rrd files + file: + dest: /var/lib/collectd/rrd + state: absent diff --git a/roles/raspberry/tasks/main.yml b/roles/raspberry/tasks/main.yml index 687624c..d905f97 100644 --- a/roles/raspberry/tasks/main.yml +++ b/roles/raspberry/tasks/main.yml @@ -3,16 +3,20 @@ - include: packages.yml tags: - packages -- include: timedate.yml - tags: - - ntp -# - include: locale.yml -# tags: -# - locale + - include: skeleton.yml tags: - skeleton +- include: ufw.yml + tags: + - ufw +- include: timedate.yml + tags: + - timedate +- include: collectd.yml + tags: + - collectd diff --git a/roles/raspberry/tasks/packages.yml b/roles/raspberry/tasks/packages.yml index 143e0af..c8d674d 100644 --- a/roles/raspberry/tasks/packages.yml +++ b/roles/raspberry/tasks/packages.yml @@ -6,11 +6,19 @@ - apt-transport-https - tmux - python3-pip - - git - - multitail - python3-requests - python3-websocket + - ufw + - docker-compose + - python-docker + - socat + - tcpdump update_cache: "{{apt_config.update_cache}}" cache_valid_time: "{{apt_config.cache_valid_time}}" +- name: set to iptables to legacy + command: "update-alternatives --set iptables /usr/sbin/iptables-legacy" + +- name: set to ip6tables to legacy + command: "update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy" diff --git a/roles/raspberry/tasks/skeleton.yml b/roles/raspberry/tasks/skeleton.yml index 7fd4ff7..8695edb 100644 --- a/roles/raspberry/tasks/skeleton.yml +++ b/roles/raspberry/tasks/skeleton.yml @@ -1,10 +1,19 @@ --- - name: alias - copy: + template: src: alias - dest: "/home/pi/.bash_aliases" - owner: pi - group: pi + dest: "{{ item.homedir }}/.bash_aliases" + owner: "{{ item.name }}" mode: "u=rw,g=r,o=r" + loop: + - {name: "{{ user_name }}", homedir: "/home/{{ user_name }}" } + - {name: "root", homedir: "/root" } +- name: root_bashrc + template: + src: root.bashrc + dest: "/root/.bashrc" + owner: root + group: root + mode: "u=rw,g=r,o=r" diff --git a/roles/raspberry/tasks/ufw.yml b/roles/raspberry/tasks/ufw.yml new file mode 100644 index 0000000..ed15eaf --- /dev/null +++ b/roles/raspberry/tasks/ufw.yml @@ -0,0 +1,37 @@ +--- + +- name: "Allow SSH" + community.general.ufw: + rule: allow + name: OpenSSH + +- name: "Allow HTTP for letsencrypt" + community.general.ufw: + rule: allow + port: "80" + proto: tcp + +- name: "Allow HTTPS" + community.general.ufw: + rule: allow + port: "443" + proto: tcp + +- name: "Allow all private IPv4 networks" + community.general.ufw: + rule: allow + src: '{{ item }}' + with_items: + - 10.0.0.0/8 + - 172.16.0.0/12 + - 192.168.0.0/16 + +- name: "Set logging" + community.general.ufw: + logging: "on" + +- name: "Enable UFW" + community.general.ufw: + state: enabled + policy: deny + diff --git a/roles/raspberry/templates/alias b/roles/raspberry/templates/alias new file mode 100644 index 0000000..e8861bd --- /dev/null +++ b/roles/raspberry/templates/alias @@ -0,0 +1,5 @@ +alias ls='/bin/ls -aF --color=auto' +#alias openhablog='tail -n 100 -f /var/log/openhab2/openhab.log -f /var/log/openhab2/events.log' +#alias openhablog2='multitail /var/log/openhab2/openhab.log /var/log/openhab2/events.log' +#alias openhablog3='multitail /var/log/openhab2/openhab.log -ci yellow -I /var/log/openhab2/events.log' +#alias karafshell="sudo su -s /bin/bash -c '/usr/share/openhab2/runtime/bin/client' openhab" diff --git a/roles/raspberry/templates/collectd.conf b/roles/raspberry/templates/collectd.conf new file mode 100644 index 0000000..db85436 --- /dev/null +++ b/roles/raspberry/templates/collectd.conf @@ -0,0 +1,1649 @@ +# Config file for collectd(1). +# +# Some plugins need additional configuration and are disabled by default. +# Please read collectd.conf(5) for details. +# +# You should also read /usr/share/doc/collectd-core/README.Debian.plugins +# before enabling any more plugins. + +############################################################################## +# Global # +#----------------------------------------------------------------------------# +# Global settings for the daemon. # +############################################################################## + +#Hostname "localhost" +FQDNLookup true +#BaseDir "/var/lib/collectd" +#PluginDir "/usr/lib/collectd" +#TypesDB "/usr/share/collectd/types.db" "/etc/collectd/my_types.db" + +#----------------------------------------------------------------------------# +# When enabled, plugins are loaded automatically with the default options # +# when an appropriate block is encountered. # +# Disabled by default. # +#----------------------------------------------------------------------------# +#AutoLoadPlugin false + +#----------------------------------------------------------------------------# +# When enabled, internal statistics are collected, using "collectd" as the # +# plugin name. # +# Disabled by default. # +#----------------------------------------------------------------------------# +#CollectInternalStats false + +#----------------------------------------------------------------------------# +# Interval at which to query values. This may be overwritten on a per-plugin # +# base by using the 'Interval' option of the LoadPlugin block: # +# # +# Interval 60 # +# # +#----------------------------------------------------------------------------# +#Interval 10 + +#MaxReadInterval 86400 +#Timeout 2 +#ReadThreads 5 +#WriteThreads 5 + +# Limit the size of the write queue. Default is no limit. Setting up a limit +# is recommended for servers handling a high volume of traffic. +#WriteQueueLimitHigh 1000000 +#WriteQueueLimitLow 800000 + +############################################################################## +# Logging # +#----------------------------------------------------------------------------# +# Plugins which provide logging functions should be loaded first, so log # +# messages generated when loading or configuring other plugins can be # +# accessed. # +############################################################################## + +#LoadPlugin logfile +LoadPlugin syslog +#LoadPlugin log_logstash + +# +# LogLevel "info" +# File STDOUT +# Timestamp true +# PrintSeverity false +# + + + LogLevel info + + +# +# LogLevel info +# File "/var/log/collectd.json.log" +# + +############################################################################## +# LoadPlugin section # +#----------------------------------------------------------------------------# +# Specify what features to activate. # +############################################################################## + +#LoadPlugin aggregation +#LoadPlugin amqp +#LoadPlugin apache +#LoadPlugin apcups +#LoadPlugin ascent +#LoadPlugin barometer +LoadPlugin battery +#LoadPlugin bind +#LoadPlugin ceph +#LoadPlugin cgroups +#LoadPlugin chrony +#LoadPlugin conntrack +LoadPlugin contextswitch +LoadPlugin cpu +#LoadPlugin cpufreq +#LoadPlugin cpusleep +#LoadPlugin csv +#LoadPlugin curl +#LoadPlugin curl_json +#LoadPlugin curl_xml +#LoadPlugin dbi +LoadPlugin df +LoadPlugin disk +#LoadPlugin dns +#LoadPlugin dpdkevents +#LoadPlugin dpdkstat +#LoadPlugin drbd +#LoadPlugin email +LoadPlugin entropy +#LoadPlugin ethstat +#LoadPlugin exec +#LoadPlugin fhcount +#LoadPlugin filecount +#LoadPlugin fscache +#LoadPlugin gmond +#LoadPlugin gps +#LoadPlugin hugepages +#LoadPlugin grpc +#LoadPlugin hddtemp +#LoadPlugin intel_rdt +LoadPlugin interface +#LoadPlugin ipc +#LoadPlugin ipmi +#LoadPlugin iptables +#LoadPlugin ipvs +LoadPlugin irq +LoadPlugin java +LoadPlugin load +#LoadPlugin lua +#LoadPlugin lvm +#LoadPlugin madwifi +#LoadPlugin mbmon +#LoadPlugin mcelog +#LoadPlugin md +#LoadPlugin memcachec +#LoadPlugin memcached +LoadPlugin memory +#LoadPlugin modbus +#LoadPlugin mqtt +#LoadPlugin multimeter +#LoadPlugin mysql +#LoadPlugin netlink +#LoadPlugin network +#LoadPlugin nfs +LoadPlugin nginx +#LoadPlugin notify_desktop +#LoadPlugin notify_email +#LoadPlugin notify_nagios +#LoadPlugin ntpd +#LoadPlugin numa +#LoadPlugin nut +#LoadPlugin olsrd +#LoadPlugin onewire +#LoadPlugin openldap +#LoadPlugin openvpn +#LoadPlugin ovs_events +#LoadPlugin ovs_stats +#LoadPlugin perl +#LoadPlugin pinba +#LoadPlugin ping +#LoadPlugin postgresql +#LoadPlugin powerdns +LoadPlugin processes +#LoadPlugin protocols +#LoadPlugin python +#LoadPlugin redis +#LoadPlugin rrdcached +#LoadPlugin rrdtool +LoadPlugin sensors +#LoadPlugin serial +#LoadPlugin sigrok +#LoadPlugin smart +#LoadPlugin snmp +#LoadPlugin snmp_agent +#LoadPlugin statsd +LoadPlugin swap +#LoadPlugin table +#LoadPlugin tail +#LoadPlugin tail_csv +#LoadPlugin tcpconns +#LoadPlugin teamspeak2 +#LoadPlugin ted +#LoadPlugin thermal +#LoadPlugin tokyotyrant +#LoadPlugin turbostat +#LoadPlugin unixsock +LoadPlugin uptime +LoadPlugin users +#LoadPlugin uuid +#LoadPlugin varnish +#LoadPlugin virt +#LoadPlugin vmem +#LoadPlugin vserver +#LoadPlugin wireless +LoadPlugin write_graphite +#LoadPlugin write_http +#LoadPlugin write_kafka +#LoadPlugin write_log +#LoadPlugin write_mongodb +#LoadPlugin write_prometheus +#LoadPlugin write_redis +#LoadPlugin write_riemann +#LoadPlugin write_sensu +#LoadPlugin write_tsdb +#LoadPlugin xencpu +#LoadPlugin zfs_arc +#LoadPlugin zookeeper + +############################################################################## +# Plugin configuration # +#----------------------------------------------------------------------------# +# In this section configuration stubs for each plugin are provided. A desc- # +# ription of those options is available in the collectd.conf(5) manual page. # +############################################################################## + +# +# +# #Host "unspecified" +# Plugin "cpu" +# PluginInstance "/[0,2,4,6,8]$/" +# Type "cpu" +# #TypeInstance "unspecified" +# +# SetPlugin "cpu" +# SetPluginInstance "even-%{aggregation}" +# +# GroupBy "Host" +# GroupBy "TypeInstance" +# +# CalculateNum false +# CalculateSum false +# CalculateAverage true +# CalculateMinimum false +# CalculateMaximum false +# CalculateStddev false +# +# + +# +# +# Host "localhost" +# Port "5672" +# VHost "/" +# User "guest" +# Password "guest" +# Exchange "amq.fanout" +# RoutingKey "collectd" +# Persistent false +# StoreRates false +# ConnectionRetryDelay 0 +# +# + +# +# +# URL "http://localhost/server-status?auto" +# User "www-user" +# Password "secret" +# VerifyPeer false +# VerifyHost false +# CACert "/etc/ssl/ca.crt" +# Server "apache" +# +# +# +# URL "http://some.domain.tld/status?auto" +# Host "some.domain.tld" +# Server "lighttpd" +# +# + +# +# Host "localhost" +# Port "3551" +# ReportSeconds true +# PersistentConnection true +# + +# +# URL "http://localhost/ascent/status/" +# User "www-user" +# Password "secret" +# VerifyPeer false +# VerifyHost false +# CACert "/etc/ssl/ca.crt" +# + +# +# Device "/dev/i2c-0"; +# Oversampling 512 +# PressureOffset 0.0 +# TemperatureOffset 0.0 +# Normalization 2 +# Altitude 238.0 +# TemperatureSensor "myserver/onewire-F10FCA000800/temperature" +# + +# +# ValuesPercentage false +# ReportDegraded false +# QueryStateFS false +# + +# +# URL "http://localhost:8053/" +# +# ParseTime false +# +# OpCodes true +# QTypes true +# ServerStats true +# ZoneMaintStats true +# ResolverStats false +# MemoryStats true +# +# +# QTypes true +# ResolverStats true +# CacheRRSets true +# +# Zone "127.in-addr.arpa/IN" +# +# + +# +# LongRunAvgLatency false +# ConvertSpecialMetricTypes true +# +# SocketPath "/var/run/ceph/ceph-osd.0.asok" +# +# +# SocketPath "/var/run/ceph/ceph-osd.1.asok" +# +# +# SocketPath "/var/run/ceph/ceph-mon.ceph1.asok" +# +# +# SocketPath "/var/run/ceph/ceph-mds.ceph1.asok" +# +# + +# +# Host "localhost" +# Port "323" +# Timeout "2" +# + +# +# CGroup "libvirt" +# IgnoreSelected false +# + +# +# ReportByCpu true +# ReportByState true +# ValuesPercentage false +# ReportNumCpu false +# ReportGuestState false +# SubtractGuestState true +# + +# +# DataDir "/var/lib/collectd/csv" +# StoreRates false +# + +# +# +# URL "http://finance.google.com/finance?q=NYSE%3AAMD" +# User "foo" +# Password "bar" +# Digest false +# VerifyPeer true +# VerifyHost true +# CACert "/path/to/ca.crt" +# Header "X-Custom-Header: foobar" +# Post "foo=bar" +# +# MeasureResponseTime false +# MeasureResponseCode false +# +# Regex "]*> *([0-9]*\\.[0-9]+) *" +# DSType "GaugeAverage" +# Type "stock_value" +# Instance "AMD" +# +# +# + +# +## See: http://wiki.apache.org/couchdb/Runtime_Statistics +# +# Instance "httpd" +# +# Type "http_requests" +# +# +# +# Type "http_request_methods" +# +# +# +# Type "http_response_codes" +# +# +## Database status metrics: +# +# Instance "dbs" +# +# Type "gauge" +# +# +# Type "counter" +# +# +# Type "bytes" +# +# +# + +# +# +# Host "my_host" +# #Plugin "stats" +# Instance "some_instance" +# User "collectd" +# Password "thaiNg0I" +# Digest false +# VerifyPeer true +# VerifyHost true +# CACert "/path/to/ca.crt" +# Header "X-Custom-Header: foobar" +# Post "foo=bar" +# +# +# Type "magic_level" +# InstancePrefix "prefix-" +# InstanceFrom "td[1]" +# #PluginInstanceFrom "td[1]" +# ValuesFrom "td[2]/span[@class=\"level\"]" +# +# +# + +# +# +# Statement "SELECT 'customers' AS c_key, COUNT(*) AS c_value \ +# FROM customers_tbl" +# MinVersion 40102 +# MaxVersion 50042 +# +# Type "gauge" +# InstancePrefix "customer" +# InstancesFrom "c_key" +# ValuesFrom "c_value" +# +# +# +# +# #Plugin "mycompany" +# Driver "mysql" +# DriverOption "host" "localhost" +# DriverOption "username" "collectd" +# DriverOption "password" "secret" +# DriverOption "dbname" "custdb0" +# SelectDB "custdb0" +# Query "num_of_customers" +# Query "..." +# Host "..." +# +# + + +# Device "/dev/sda1" +# Device "192.168.0.2:/mnt/nfs" +# MountPoint "/home" +# FSType "ext3" + + # ignore rootfs; else, the root file-system would appear twice, causing + # one of the updates to fail and spam the log + FSType rootfs + # ignore the usual virtual / temporary file-systems + FSType sysfs + FSType proc + FSType devtmpfs + FSType devpts + FSType tmpfs + FSType fusectl + FSType cgroup + IgnoreSelected true + +# ReportByDevice false +# ReportInodes false + +# ValuesAbsolute true +# ValuesPercentage false + + +# +# Disk "hda" +# Disk "/sda[23]/" +# IgnoreSelected false +# UseBSDName false +# UdevNameAttr "DEVNAME" +# + +# +# Interface "eth0" +# IgnoreSource "192.168.0.1" +# SelectNumericQueryTypes false +# + +# +# +# Coremask "0x1" +# MemoryChannels "4" +# FilePrefix "rte" +# +# +# SendEventsOnUpdate true +# EnabledPortMask 0xffff +# PortName "interface1" +# PortName "interface2" +# SendNotification false +# +# +# SendEventsOnUpdate true +# LCoreMask "0xf" +# KeepAliveShmName "/dpdk_keepalive_shm_name" +# SendNotification false +# +# + +# +# +# Coremask "0x2" +# MemoryChannels "4" +# FilePrefix "rte" +# LogLevel "7" +# RteDriverLibPath "/usr/lib/dpdk-pmd" +# +# SharedMemObj "dpdk_collectd_stats_0" +# EnabledPortMask 0xffff +# PortName "interface1" +# PortName "interface2" +# + +# +# SocketFile "/var/run/collectd-email" +# SocketGroup "collectd" +# SocketPerms "0770" +# MaxConns 5 +# + +# +# Interface "eth0" +# Map "rx_csum_offload_errors" "if_rx_errors" "checksum_offload" +# Map "multicast" "if_multicast" +# MappedOnly false +# + +# +# Exec user "/path/to/exec" +# Exec "user:group" "/path/to/exec" +# NotificationExec user "/path/to/exec" +# + +# +# ValuesAbsolute true +# ValuesPercentage false +# + +# +# +# #Plugin "foo" +# Instance "foodir" +# Name "*.conf" +# MTime "-5m" +# Size "+10k" +# Recursive true +# IncludeHidden false +# RegularOnly true +# #FilesSizeType "bytes" +# #FilesCountType "files" +# #TypeInstance "instance" +# +# + +# +# MCReceiveFrom "239.2.11.71" "8649" +# +# +# Type "swap" +# TypeInstance "total" +# DataSource "value" +# +# +# +# Type "swap" +# TypeInstance "free" +# DataSource "value" +# +# + +# +# Host "127.0.0.1" +# Port "2947" +# Timeout 0.015 +# PauseConnect 5 +# + +# +# Host "127.0.0.1" +# Port 7634 +# + +# +# +# EnableSSL true +# SSLCACertificateFile "/path/to/root.pem" +# SSLCertificateFile "/path/to/server.pem" +# SSLCertificateKeyFile "/path/to/server.key" +# +# +# EnableSSL true +# SSLCACertificateFile "/path/to/root.pem" +# SSLCertificateFile "/path/to/client.pem" +# SSLCertificateKeyFile "/path/to/client.key" +# +# + +# +# ReportPerNodeHP true +# ReportRootHP true +# ValuesPages true +# ValuesBytes false +# ValuesPercentage false +# + +# +# Cores "0-2" +# + +# +# Interface "eth0" +# IgnoreSelected false +# ReportInactive true +# UniqueName false +# + +# +# +# Sensor "some_sensor" +# Sensor "another_one" +# IgnoreSelected false +# NotifySensorAdd false +# NotifySensorRemove true +# NotifySensorNotPresent false +# NotifyIPMIConnectionState false +# SELEnabled false +# SELClearEvent false +# +# +# Host "server.example.com" +# Address "1.2.3.4" +# Username "user" +# Password "secret" +# #AuthType "md5" +# Sensor "some_sensor" +# Sensor "another_one" +# IgnoreSelected false +# NotifySensorAdd false +# NotifySensorRemove true +# NotifySensorNotPresent false +# NotifyIPMIConnectionState false +# SELEnabled false +# SELClearEvent false +# +# + +# +# Chain "table" "chain" +# Chain6 "table" "chain" +# + +# +# Irq 7 +# Irq 8 +# Irq 9 +# IgnoreSelected true +# + +# +# JVMArg "-verbose:jni" +# JVMArg "-Djava.class.path=/usr/share/collectd/java/collectd-api.jar" +# +# LoadPlugin "org.collectd.java.GenericJMX" +# +# # See /usr/share/doc/collectd/examples/GenericJMX.conf +# # for an example config. +# +# + +# +# ReportRelative true +# + +# +# BasePath "/usr/share/collectd/lua" +# Script "script1.lua" +# Script "script2.lua" +# + +# +# Interface "wlan0" +# IgnoreSelected false +# Source "SysFS" +# WatchSet "None" +# WatchAdd "node_octets" +# WatchAdd "node_rssi" +# WatchAdd "is_rx_acl" +# WatchAdd "is_scan_active" +# + +# +# Host "127.0.0.1" +# Port 411 +# + +# +# +# McelogClientSocket "/var/run/mcelog-client" +# PersistentNotification false +# +# McelogLogfile "/var/log/mcelog" +# + +# +# Device "/dev/md0" +# IgnoreSelected false +# + +# +# +# Server "localhost" +# Key "page_key" +# +# Regex "(\\d+) bytes sent" +# ExcludeRegex "" +# DSType CounterAdd +# Type "ipt_octets" +# Instance "type_instance" +# +# +# + +# +# +# Socket "/var/run/memcached.sock" +# or: +# #Host "memcache.example.com" +# Address "127.0.0.1" +# Port "11211" +# +# + +# +# ValuesAbsolute true +# ValuesPercentage false +# + +# +# +# RegisterBase 1234 +# RegisterCmd ReadHolding +# RegisterType float +# Type gauge +# Instance "..." +# +# +# +# Address "addr" +# Port "1234" +# Interval 60 +# +# +# Instance "foobar" # optional +# Collect "data_name" +# +# +# + +# +# +# Host "localhost" +# Port 1883 +# ClientId "localhost" +# User "user" +# Password "secret" +# QoS 0 +# Prefix "collectd" +# StoreRates true +# Retain false +# CACert "/etc/ssl/ca.crt" +# CertificateFile "/etc/ssl/client.crt" +# CertificateKeyFile "/etc/ssl/client.pem" +# TLSProtocol "tlsv1.2" +# CipherSuite "ciphers" +# +# +# Host "localhost" +# Port 1883 +# ClientId "localhost" +# User "user" +# Password "secret" +# QoS 2 +# Topic "collectd/#" +# CleanSession true +# +# + +# +# +# Host "database.serv.er" +# Port "3306" +# User "db_user" +# Password "secret" +# Database "db_name" +# SSLKey "/path/to/key.pem" +# SSLCert "/path/to/cert.pem" +# SSLCA "/path/to/ca.pem" +# SSLCAPath "/path/to/cas/" +# SSLCipher "DHE-RSA-AES256-SHA" +# MasterStats true +# ConnectTimeout 10 +# InnodbStats true +# +# +# +# Alias "squeeze" +# Host "localhost" +# Socket "/var/run/mysql/mysqld.sock" +# SlaveStats true +# SlaveNotifications true +# +# +# +# Alias "galera" +# Host "localhost" +# Socket "/var/run/mysql/mysqld.sock" +# WsrepStats true +# +# + +# +# Interface "All" +# VerboseInterface "All" +# QDisc "eth0" "pfifo_fast-1:0" +# Class "ppp0" "htb-1:10" +# Filter "ppp0" "u32-1:0" +# IgnoreSelected false +# + +# +# # client setup: +# Server "ff18::efc0:4a42" "25826" +# +# SecurityLevel Encrypt +# Username "user" +# Password "secret" +# Interface "eth0" +# ResolveInterval 14400 +# +# TimeToLive 128 +# +# # server setup: +# Listen "ff18::efc0:4a42" "25826" +# +# SecurityLevel Sign +# AuthFile "/etc/collectd/passwd" +# Interface "eth0" +# +# MaxPacketSize 1452 +# +# # proxy setup (client and server as above): +# Forward true +# +# # statistics about the network plugin itself +# ReportStats false +# +# # "garbage collection" +# CacheFlush 1800 +# + +# +# ReportV2 false +# ReportV3 false +# ReportV4 false +# + +# +# URL "http://localhost/status?auto" +# User "www-user" +# Password "secret" +# VerifyPeer false +# VerifyHost false +# CACert "/etc/ssl/ca.crt" +# + +# +# OkayTimeout 1000 +# WarningTimeout 5000 +# FailureTimeout 0 +# + +# +# SMTPServer "localhost" +# SMTPPort 25 +# SMTPUser "my-username" +# SMTPPassword "my-password" +# From "collectd@main0server.com" +# # on . +# # Beware! Do not use not more than two placeholders (%)! +# Subject "[collectd] %s on %s!" +# Recipient "email1@domain1.net" +# Recipient "email2@domain2.com" +# + +# +# CommandFile "/var/lib/icinga/rw/icinga.cmd" +# + +# +# Host "localhost" +# Port 123 +# ReverseLookups false +# IncludeUnitID true +# + +# +# UPS "upsname@hostname:port" +# ForceSSL true +# VerifyPeer true +# CAPath "/path/to/folder" +# #ConnectTimeout 5000 +# + +# +# Host "127.0.0.1" +# Port "2006" +# CollectLinks "Summary" +# CollectRoutes "Summary" +# CollectTopology "Summary" +# + +# +# Device "-s localhost:4304" +# Sensor "F10FCA000800" +# IgnoreSelected false +# + +# +# +# URL "ldap://localhost:389" +# StartTLS false +# VerifyHost true +# CACert "/path/to/ca.crt" +# Timeout -1 +# Version 3 +# +# + +# +# StatusFile "/etc/openvpn/openvpn-status.log" +# ImprovedNamingSchema false +# CollectCompression true +# CollectIndividualUsers true +# CollectUserCount false +# + +# +# Port "6640" +# Address "127.0.0.1" +# Socket "/var/run/openvswitch/db.sock" +# Interfaces "br0" "veth0" +# SendNotification true +# DispatchValues false +# +# +# +# Port "6640" +# Address "127.0.0.1" +# Socket "/var/run/openvswitch/db.sock" +# Bridges "br0" "br_ext" +# + +# +# IncludeDir "/my/include/path" +# BaseName "Collectd::Plugins" +# EnableDebugger "" +# LoadPlugin Monitorus +# LoadPlugin OpenVZ +# +# +# Foo "Bar" +# Qux "Baz" +# +# + +# +# Address "::0" +# Port "30002" +# +# Host "host name" +# Server "server name" +# Script "script name" +# +# + +# +# Host "host.foo.bar" +# Host "host.baz.qux" +# Interval 1.0 +# Timeout 0.9 +# TTL 255 +# SourceAddress "1.2.3.4" +# Device "eth0" +# MaxMissed -1 +# + +# +# +# Statement "SELECT magic FROM wizard WHERE host = $1;" +# Param hostname +# +# +# Type gauge +# InstancePrefix "magic" +# ValuesFrom "magic" +# +# +# +# +# Statement "SELECT COUNT(type) AS count, type \ +# FROM (SELECT CASE \ +# WHEN resolved = 'epoch' THEN 'open' \ +# ELSE 'resolved' END AS type \ +# FROM tickets) type \ +# GROUP BY type;" +# +# +# Type counter +# InstancePrefix "rt36_tickets" +# InstancesFrom "type" +# ValuesFrom "count" +# +# +# +# +# # See /usr/share/doc/collectd-core/examples/postgresql/collectd_insert.sql for details +# Statement "SELECT collectd_insert($1, $2, $3, $4, $5, $6, $7, $8, $9);" +# StoreRates true +# +# +# +# #Plugin "kingdom" +# Host "hostname" +# Port 5432 +# User "username" +# Password "secret" +# +# SSLMode "prefer" +# KRBSrvName "kerberos_service_name" +# +# Query magic +# +# +# +# Interval 60 +# Service "service_name" +# +# Query backends # predefined +# Query rt36_tickets +# +# +# +# Service "collectd_store" +# Writer sqlstore +# # see collectd.conf(5) for details +# CommitInterval 30 +# +# + +# +# +# Collect "latency" +# Collect "udp-answers" "udp-queries" +# Socket "/var/run/pdns.controlsocket" +# +# +# Collect "questions" +# Collect "cache-hits" "cache-misses" +# Socket "/var/run/pdns_recursor.controlsocket" +# +# LocalSocket "/opt/collectd/var/run/collectd-powerdns" +# + +# +# CollectFileDescriptor true +# CollectContextSwitch true +# CollectMemoryMaps true +# Process "name" +# ProcessMatch "foobar" "/usr/bin/perl foobar\\.pl.*" +# +# CollectFileDescriptor false +# CollectContextSwitch false +# +# +# CollectFileDescriptor false +# CollectContextSwitch true +# +# + +# +# Value "/^Tcp:/" +# IgnoreSelected false +# + +# +# ModulePath "/path/to/your/python/modules" +# LogTraces true +# Interactive true +# Import "spam" +# +# +# spam "wonderful" "lovely" +# +# + +# +# +# Host "redis.example.com" +# Port "6379" +# Timeout 2000 +# +# + +# +# DaemonAddress "unix:/var/run/rrdcached.sock" +# DataDir "/var/lib/rrdcached/db/collectd" +# CreateFiles true +# CreateFilesAsync false +# CollectStatistics true +# +# The following settings are rather advanced +# and should usually not be touched: +# StepSize 10 +# HeartBeat 20 +# RRARows 1200 +# RRATimespan 158112000 +# XFF 0.1 +# + + + DataDir "/var/lib/collectd/rrd" +# CacheTimeout 120 +# CacheFlush 900 +# WritesPerSecond 30 +# CreateFilesAsync false +# RandomTimeout 0 +# +# The following settings are rather advanced +# and should usually not be touched: +# StepSize 10 +# HeartBeat 20 +# RRARows 1200 +# RRATimespan 158112000 +# XFF 0.1 + + +# +# SensorConfigFile "/etc/sensors3.conf" +# Sensor "it8712-isa-0290/temperature-temp1" +# Sensor "it8712-isa-0290/fanspeed-fan3" +# Sensor "it8712-isa-0290/voltage-in8" +# IgnoreSelected false +# + +# +# LogLevel 3 +# +# Driver "fluke-dmm" +# MinimumInterval 10 +# Conn "/dev/ttyUSB2" +# +# +# Driver "cem-dt-885x" +# Conn "/dev/ttyUSB1" +# +# + +# +# Disk "/^[hs]d[a-f][0-9]?$/" +# IgnoreSelected false +# + +# See /usr/share/doc/collectd/examples/snmp-data.conf.gz for a +# comprehensive sample configuration. +# +# +# Type "voltage" +# Table false +# Instance "input_line1" +# Scale 0.1 +# Values "SNMPv2-SMI::enterprises.6050.5.4.1.1.2.1" +# +# +# Type "users" +# Table false +# Instance "" +# Shift -1 +# Values "HOST-RESOURCES-MIB::hrSystemNumUsers.0" +# +# +# Type "if_octets" +# Table true +# InstancePrefix "traffic" +# Instance "IF-MIB::ifDescr" +# Values "IF-MIB::ifInOctets" "IF-MIB::ifOutOctets" +# +# +# +# Address "192.168.0.2" +# Version 1 +# Community "community_string" +# Collect "std_traffic" +# Inverval 120 +# Timeout 10 +# Retries 1 +# +# +# Address "192.168.0.42" +# Version 2 +# Community "another_string" +# Collect "std_traffic" "hr_users" +# +# +# Address "192.168.0.3" +# Version 1 +# Community "more_communities" +# Collect "powerplus_voltge_input" +# Interval 300 +# Timeout 5 +# Retries 5 +# +# + +# +# +# Plugin "memory" +# Type "memory" +# TypeInstance "free" +# OIDs "1.3.6.1.4.1.2021.4.6.0" +# +# +# IndexOID "IF-MIB::ifIndex" +# SizeOID "IF-MIB::ifNumber" +# +# Instance true +# Plugin "interface" +# OIDs "IF-MIB::ifDescr" +# +# +# Plugin "interface" +# Type "if_octets" +# TypeInstance "" +# OIDs "IF-MIB::ifInOctets" "IF-MIB::ifOutOctets" +# +#
+#
+ +# +# Host "::" +# Port "8125" +# DeleteCounters false +# DeleteTimers false +# DeleteGauges false +# DeleteSets false +# CounterSum false +# TimerPercentile 90.0 +# TimerPercentile 95.0 +# TimerPercentile 99.0 +# TimerLower false +# TimerUpper false +# TimerSum false +# TimerCount false +# + +# +# ReportByDevice false +# ReportBytes true +# ValuesAbsolute true +# ValuesPercentage false +# ReportIO true +# + +# +# +# #Plugin "table" +# Instance "slabinfo" +# Separator " " +# +# Type gauge +# InstancePrefix "active_objs" +# InstancesFrom 0 +# ValuesFrom 1 +# +# +# Type gauge +# InstancePrefix "objperslab" +# InstancesFrom 0 +# ValuesFrom 4 +# +#
+#
+ +# +# +# Instance "exim" +# Interval 60 +# +# Regex "S=([1-9][0-9]*)" +# DSType "CounterAdd" +# Type "ipt_bytes" +# Instance "total" +# +# +# Regex "\\" +# ExcludeRegex "\\.*mail_spool defer" +# DSType "CounterInc" +# Type "counter" +# Instance "local_user" +# +# +# +# #Use the following log format in nginx: +# #log_format response_time '[$host] "$upstream_response_time" ...' +# Instance "apache" +# +# Regex "^\\S+ \"([0-9.]+)\"" +# +# Percentile 80 # -> latency-foo-80 +# Percentile 95 # -> latency-foo-95 +# Percentile 99 # -> latency-foo-99 +# Bucket 0 0.1 # -> bucket-latency-foo-0_0.1 +# Bucket 0.1 0.2 # -> bucket-latency-foo-0.1_0.2 +# Bucket 0.2 0.5 # -> bucket-latency-foo-0.2_0.5 +# Bucket 0.5 1.0 # -> bucket-latency-foo-0.5_1 +# Bucket 1.0 2.0 # -> bucket-latency-foo-1_2 +# Bucket 2.0 0 # -> bucket-latency-foo-2_inf +# #BucketType "bucket" +# +# Type "latency" +# Instance "foo" +# +# +# + +# +# +# Type "percent" +# Instance "dropped" +# ValueFrom 1 +# +# +# Type "bytes" +# Instance "wire-realtime" +# ValueFrom 2 +# +# +# Type "alerts_per_second" +# ValueFrom 3 +# +# +# Type "kpackets_wire_per_sec.realtime" +# ValueFrom 4 +# +# +# Instance "snort-eth0" +# Interval 600 +# Collect "dropped" "mbps" "alerts" "kpps" +# TimeFrom 0 +# +# + +# +# ListeningPorts false +# AllPortsSummary false +# LocalPort "25" +# RemotePort "25" +# + +# +# Host "127.0.0.1" +# Port "51234" +# Server "8767" +# + +# +# Device "/dev/ttyUSB0" +# Retries 0 +# + +# +# ForceUseProcfs false +# Device "THRM" +# IgnoreSelected false +# + +# +# Host "localhost" +# Port "1978" +# + +# +## None of the following option should be set manually +## This plugin automatically detect most optimal options +## Only set values here if: +## - The module asks you to +## - You want to disable the collection of some data +## - Your (Intel) CPU is not supported (yet) by the module +## - The module generates a lot of errors 'MSR offset 0x... read failed' +## In the last two cases, please open a bug request +# +# TCCActivationTemp "100" +# CoreCstates "392" +# PackageCstates "396" +# SystemManagementInterrupt true +# DigitalTemperatureSensor true +# PackageThermalManagement true +# RunningAveragePowerLimit "7" +# + +# +# SocketFile "/var/run/collectd-unixsock" +# SocketGroup "collectd" +# SocketPerms "0660" +# DeleteSocket false +# + +# +# UUIDFile "/etc/uuid" +# + +# +# This tag support an argument if you want to +# monitor the local instance just use +# If you prefer defining another instance you can do +# so by using +# +# CollectBackend true +# CollectBan false # Varnish 3 and above +# CollectCache true +# CollectConnections true +# CollectDirectorDNS false # Varnish 3 only +# CollectESI false +# CollectFetch false +# CollectHCB false +# CollectObjects false +# CollectPurge false # Varnish 2 only +# CollectSession false +# CollectSHM true +# CollectSMA false # Varnish 2 & 4 only +# CollectSMS false +# CollectSM false # Varnish 2 only +# CollectStruct false +# CollectTotals false +# CollectUptime false # Varnish 3 and above +# CollectVCL false +# CollectVSM false # Varnish 4 only +# CollectWorkers false +# CollectLock false # Varnish 4 only +# CollectMempool false # Varnish 4 only +# CollectManagement false # Varnish 4 only +# CollectSMF false # Varnish 4 only +# CollectVBE false # Varnish 4 only +# CollectMSE false # Varnish-Plus 4 only +# +# + +# +# Connection "xen:///" +# RefreshInterval 60 +# Domain "name" +# BlockDevice "name:device" +# BlockDeviceFormat target +# BlockDeviceFormatBasename false +# InterfaceDevice "name:device" +# IgnoreSelected false +# HostnameFormat name +# InterfaceFormat name +# PluginInstanceFormat name +# Instances 1 +# ExtraStats "cpu_util disk disk_err domain_state fs_info job_stats_background pcpu perf vcpupin" +# + +# +# Verbose false +# + + + + Host "192.168.1.96" + Port "2003" + Protocol "tcp" + ReconnectInterval 0 + LogSendErrors true + Prefix "raspberry_" +# Postfix "collectd" +# StoreRates true +# AlwaysAppendDS false +# EscapeCharacter "_" +# SeparateInstances false +# PreserveSeparator false +# DropDuplicateFields false + + + +# +# +# URL "http://example.com/collectd-post" +# User "collectd" +# Password "secret" +# VerifyPeer true +# VerifyHost true +# CACert "/etc/ssl/ca.crt" +# CAPath "/etc/ssl/certs/" +# ClientKey "/etc/ssl/client.pem" +# ClientCert "/etc/ssl/client.crt" +# ClientKeyPass "secret" +# Header "X-Custom-Header: custom_value" +# SSLVersion "TLSv1" +# Format "Command" +# Prefix "collectd" # metric prefix, only available for KAIROSDB format +# Attribute "key" "value" # only available for KAIROSDB format +# TTL 0 # data ttl, only available for KAIROSDB format +# Metrics true +# Notifications false +# StoreRates false +# BufferSize 4096 +# LowSpeedLimit 0 +# Timeout 0 +# Prefix "collectd/" +# +# + +# +# Property "metadata.broker.list" "localhost:9092" +# +# Format JSON +# +# + +# +# +# Host "localhost" +# Port "27017" +# Timeout 1000 +# StoreRates false +# Database "auth_db" +# User "auth_user" +# Password "auth_passwd" +# +# + +# +# Port "9103" +# + +# +# +# Host "localhost" +# Port "6379" +# Timeout 1000 +# +# + +# +# +# Host "localhost" +# Port 5555 +# Protocol TCP +# Batch true +# BatchMaxSize 8192 +# StoreRates true +# AlwaysAppendDS false +# TTLFactor 2.0 +# Notifications true +# CheckThresholds false +# EventServicePrefix "" +# +# Tag "foobar" +# Attribute "foo" "bar" +# + +# +# +# Host "localhost" +# Port 3030 +# StoreRates true +# AlwaysAppendDS false +# Notifications true +# Metrics true +# EventServicePrefix "" +# MetricHandler "influx" +# MetricHandler "default" +# NotificationHandler "flapjack" +# NotificationHandler "howling_monkey" +# +# Tag "foobar" +# Attribute "foo" "bar" +# + +# +# +# Host "localhost" +# Port "4242" +# HostTags "status=production" +# StoreRates false +# AlwaysAppendDS false +# +# + +# +# Host "localhost" +# Port "2181" +# + + + Filter "*.conf" + + diff --git a/roles/raspberry/templates/root.bashrc b/roles/raspberry/templates/root.bashrc new file mode 100644 index 0000000..91bb92a --- /dev/null +++ b/roles/raspberry/templates/root.bashrc @@ -0,0 +1,25 @@ +# ~/.bashrc: executed by bash(1) for non-login shells. + +# Note: PS1 and umask are already set in /etc/profile. You should not +# need this unless you want different defaults for root. +# PS1='${debian_chroot:+($debian_chroot)}\h:\w\$ ' +# umask 022 + +# You may uncomment the following lines if you want `ls' to be colorized: +# export LS_OPTIONS='--color=auto' +# eval "`dircolors`" +# alias ls='ls $LS_OPTIONS' +# alias ll='ls $LS_OPTIONS -l' +# alias l='ls $LS_OPTIONS -lA' +# +# Some more alias to avoid making mistakes: +# alias rm='rm -i' +# alias cp='cp -i' +# alias mv='mv -i' + +if [ -f ~/.bash_aliases ]; then + . ~/.bash_aliases +fi + +#PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' +PS1='\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '