infra/roles/sensors/tasks/sensors.yml

165 lines
3.3 KiB
YAML

---
# probably: libyaml-dev
- name: add {{ myusername }} to groups for sensors
user:
name: "{{ myusername }}"
groups:
- gpio
- dialout
- sensors
append: yes
- 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: no
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
- name: install fpm with gem
gem:
name: fpm
include_doc: no
state: latest
when: dht_builder|default(False)
tags: dht, fpm
- name: install sudoisdht
apt:
name: sudoisdht
state: latest
update_cache: yes
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: no
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: remove 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: yes
daemon_reload: yes
name: "sudoisbot@{{ item.key }}_pub"
loop_control:
label: "sudoisbot@{{ item.key }}_pub"
with_dict:
- "{{ sensors }}"
tags:
- sensors-config
- sensors-systemd
- sensors-started
- deploy