infra/roles/sensors/tasks/sensors.yml

352 lines
10 KiB
YAML

---
# probably: libyaml-dev
- name: add {{ myusername }} to groups for sensors
user:
name: "{{ myusername }}"
groups:
- gpio
- dialout
- sensors
append: true
- name: wifi
template:
src: wpa_supplicant.conf.j2
dest: /etc/wpa_supplicant/wpa_supplicant.conf
owner: root
group: root
mode: 0600
when: wifi_enabled|bool|default(False)
tags:
- wifi
- name: enable w1 in bootloader config
lineinfile:
path: /boot/config.txt
line: "dtoverlay=w1-gpio"
create: false
when: "'ds18b20' in sensors.temp|map(attribute='kind')"
register: bootconfig
# molly-guard is usually installed, but it symlinks the real binaries
# through /lib/molly-guard
- name: reboot if needed
reboot:
connect_timeout: 2
search_paths:
- "/lib/molly-guard"
- "/usr/sbin"
- "/sbin"
when:
- bootconfig.changed
- "'ds18b20' in sensors.temp|map(attribute='kind')"
- name: install build dedendencies for dht.c
apt:
name:
- wiringpi
- ruby
- ruby-dev
- rubygems1.8
# - build-essential # already isntallde
state: present
when: dht_builder|default(False)
tags: dht
# https://bluedot.readthedocs.io/en/latest/pairpipi.html#using-the-command-line
#
# $ sudo bluetoothctl
# [bluetooth]# discoverable on
# Changing discoverable on succeeded
# [bluetooth]# pairable on
# Changing pairable on succeeded
# [bluetooth]# agent on
# Agent is already registered
# [bluetooth]# default-agent
# Default agent request successful
# [bluetooth]# scan on
# [bluetooth]# pair EA:26:7D:4A:ED:E4
# 0a-11e5-a837-0800200c9a66
# Vendor specific
# [NEW] Descriptor
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service0009/char000d/desc000f
# 00002901-0000-1000-8000-00805f9b34fb
# Characteristic User Description
# [NEW] Descriptor
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service0009/char000d/desc0010
# 00002902-0000-1000-8000-00805f9b34fb
# Client Characteristic Configuration
# [NEW] Characteristic
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service0009/char0011
# e6807d23-b90a-11e5-a837-0800200c9a66
# Vendor specific
# [NEW] Descriptor
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service0009/char0011/desc0013
# 00002901-0000-1000-8000-00805f9b34fb
# Characteristic User Description
# [NEW] Characteristic
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service0009/char0014
# e6807d24-b90a-11e5-a837-0800200c9a66
# Vendor specific
# [NEW] Descriptor
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service0009/char0014/desc0016
# 00002901-0000-1000-8000-00805f9b34fb
# Characteristic User Description
# [NEW] Descriptor
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service0009/char0014/desc0017
# 00002902-0000-1000-8000-00805f9b34fb
# Client Characteristic Configuration
# [NEW] Characteristic
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service0009/char0018
# e6807d25-b90a-11e5-a837-0800200c9a66
# Vendor specific
# [NEW] Descriptor
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service0009/char0018/desc001a
# 00002901-0000-1000-8000-00805f9b34fb
# Characteristic User Description
# [NEW] Characteristic
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service0009/char001b
# e6807d26-b90a-11e5-a837-0800200c9a66
# Vendor specific
# [NEW] Descriptor
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service0009/char001b/desc001d
# 00002901-0000-1000-8000-00805f9b34fb
# Characteristic User Description
# [NEW] Characteristic
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service0009/char001e
# e6807d27-b90a-11e5-a837-0800200c9a66
# Vendor specific
# [NEW] Descriptor
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service0009/char001e/desc0020
# 00002901-0000-1000-8000-00805f9b34fb
# Characteristic User Description
# [NEW] Characteristic
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service0009/char0021
# e6807e20-b90a-11e5-a837-0800200c9a66
# Vendor specific
# [NEW] Descriptor
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service0009/char0021/desc0023
# 00002901-0000-1000-8000-00805f9b34fb
# Characteristic User Description
# [NEW] Descriptor
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service0009/char0021/desc0024
# 00002902-0000-1000-8000-00805f9b34fb
# Client Characteristic Configuration
# [NEW] Characteristic
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service0009/char0025
# e6807e21-b90a-11e5-a837-0800200c9a66
# Vendor specific
# [NEW] Descriptor
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service0009/char0025/desc0027
# 00002901-0000-1000-8000-00805f9b34fb
# Characteristic User Description
# [NEW] Characteristic
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service0009/char0028
# e6807e24-b90a-11e5-a837-0800200c9a66
# Vendor specific
# [NEW] Descriptor
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service0009/char0028/desc002a
# 00002901-0000-1000-8000-00805f9b34fb
# Characteristic User Description
# [NEW] Descriptor
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service0009/char0028/desc002b
# 00002902-0000-1000-8000-00805f9b34fb
# Client Characteristic Configuration
# [NEW] Characteristic
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service0009/char002c
# e6807e25-b90a-11e5-a837-0800200c9a66
# Vendor specific
# [NEW] Descriptor
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service0009/char002c/desc002e
# 00002901-0000-1000-8000-00805f9b34fb
# Characteristic User Description
# [NEW] Primary Service
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service002f
# 0000181a-0000-1000-8000-00805f9b34fb
# Environmental Sensing
# [NEW] Characteristic
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service002f/char0030
# 00002a6e-0000-1000-8000-00805f9b34fb
# Temperature
# [NEW] Descriptor
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service002f/char0030/desc0032
# 00002901-0000-1000-8000-00805f9b34fb
# Characteristic User Description
# [NEW] Descriptor
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service002f/char0030/desc0033
# 00002902-0000-1000-8000-00805f9b34fb
# Client Characteristic Configuration
# [NEW] Characteristic
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service002f/char0034
# 00002a6f-0000-1000-8000-00805f9b34fb
# Humidity
# [NEW] Descriptor
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service002f/char0034/desc0036
# 00002901-0000-1000-8000-00805f9b34fb
# Characteristic User Description
# [NEW] Descriptor
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service002f/char0034/desc0037
# 00002902-0000-1000-8000-00805f9b34fb
# Client Characteristic Configuration
# [NEW] Primary Service
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service0038
# 0000180a-0000-1000-8000-00805f9b34fb
# Device Information
# [NEW] Characteristic
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service0038/char0039
# 00002a29-0000-1000-8000-00805f9b34fb
# Manufacturer Name String
# [NEW] Characteristic
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service0038/char003b
# 00002a24-0000-1000-8000-00805f9b34fb
# Model Number String
# [NEW] Characteristic
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service0038/char003d
# 00002a25-0000-1000-8000-00805f9b34fb
# Serial Number String
# [NEW] Characteristic
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service0038/char003f
# 00002a27-0000-1000-8000-00805f9b34fb
# Hardware Revision String
# [NEW] Characteristic
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service0038/char0041
# 00002a26-0000-1000-8000-00805f9b34fb
# Firmware Revision String
# [NEW] Characteristic
# /org/bluez/hci0/dev_EA_26_7D_4A_ED_E4/service0038/char0043
# 00002a28-0000-1000-8000-00805f9b34fb
# Software Revision String
# [CHG] Device EA:26:7D:4A:ED:E4 UUIDs: 00001800-0000-1000-8000-00805f9b34fb
# [CHG] Device EA:26:7D:4A:ED:E4 UUIDs: 00001801-0000-1000-8000-00805f9b34fb
# [CHG] Device EA:26:7D:4A:ED:E4 UUIDs: 0000180a-0000-1000-8000-00805f9b34fb
# [CHG] Device EA:26:7D:4A:ED:E4 UUIDs: 0000181a-0000-1000-8000-00805f9b34fb
# [CHG] Device EA:26:7D:4A:ED:E4 UUIDs: e6807d20-b90a-11e5-a837-0800200c9a66
# [CHG] Device EA:26:7D:4A:ED:E4 ServicesResolved: yes
# [CHG] Device EA:26:7D:4A:ED:E4 Appearance: 0x03c0
# [CHG] Device EA:26:7D:4A:ED:E4 Paired: yes
# Pairing successful
# [Beddit 2564]# quit
- name: set up bluetooth
apt:
name:
- pi-bluetooth
- bluez
- libgirepository1.0-dev
# for monitor.sh
- bc
- bluez-hcidump
# - bluez-utils
# - bluetooth
# - blueman
when: bluetooth_enabled | default(false)
tags: bluetooth
- name: install fpm with gem
gem:
name: fpm
include_doc: false
state: latest
when: dht_builder|default(False)
tags: dht, fpm
- name: install sudoisdht
apt:
name: sudoisdht
state: latest
update_cache: true
when:
- "'temp' in sensors"
- "'dht' in sensors.temp|map(attribute='kind')"
tags:
- dht
- package
notify:
- restart sudoisbot temp_pub
- name: find /dev/hidraw* files
find:
paths: /dev
patterns: 'hidraw*'
recurse: false
file_type: any
when:
- "'temp' in sensors"
- "'temper' in sensors.temp|map(attribute='kind')"
register: hidraw
tags:
- hidraw
- name: set /dev/hidraw permissions
file:
path: "{{ item.path }}"
group: sensors
mode: 0660
notify: restart sudoisbot temp_pub
when:
- "'temp' in sensors"
- "'temper' in sensors.temp|map(attribute='kind')"
with_items: "{{ hidraw.files }}"
loop_control:
label: "{{ item.path }}"
tags:
- hidraw
- name: template sudoisbot config to standard location
template:
src: sudoisbot.yml.j2
dest: /usr/local/etc/sudoisbot.yml
owner: root
group: root
mode: 0644
tags:
- sensors-config
- sensors-sudoisbot
- deploy
notify:
- restart sudoisbot temp_pub
- restart sudoisbot rain_pub
- name: sudoisbot as pip package
pip:
name: sudoisbot
state: latest
executable: pip3
tags:
- sensors-sudoisbot
- deploy
notify:
- restart sudoisbot temp_pub
- restart sudoisbot rain_pub
- name: install systemd config for sudoisbot
template:
src: sudoisbot.service.j2
dest: "/etc/systemd/system/sudoisbot@.service"
tags:
- sensors-config
- sensors-systemd
- deploy
notify:
- restart sudoisbot temp_pub
- restart sudoisbot rain_pub
- systemctl daemon reload
- name: enable sudoisbot
systemd:
state: started
enabled: true
daemon_reload: true
name: "sudoisbot@{{ item.key }}_pub"
loop_control:
label: "sudoisbot@{{ item.key }}_pub"
with_dict:
- "{{ sensors }}"
tags:
- sensors-config
- sensors-systemd
- sensors-started
- deploy