Commit 8ceb4a72 authored by Levin Zimmermann's avatar Levin Zimmermann

playbook: Add Wendelin Olimex preperation playbooks

Initial commit for adding automatic preperation of Olimex boards as an IoT Gateway
and for a Sensor to send data to Wendelin (see
https://wendelin.nexedi.com/wendelin-Learning.Track/wendelin-Tutorial.Setup.Sensor.IOTGateway/WebPage_viewAsWeb
).
parent 868e7359
- set_fact:
request_fluentd_python_script_path={{ role_path }}/files/request-fluentd.py
- name: Solve template to request Fluentd
template:
src: request-fluentd.j2
dest: "{{ request_fluentd_python_script_path }}"
- name: Request Fluentd from SlapOS Master
shell: slapos console "{{ request_fluentd_python_script_path }}"
# Constants
fluentd_software_release_uri = product.fluentd
computer_name = "{{computer_name}}"
fluentd_software_name = "{{fluentd_software_name}}"
fluentd_config = """{{fluentd_config}}"""
# Supplying and requesting
supply(fluentd_software_release_uri, computer_name)
request(
fluentd_software_release_uri,
fluentd_software_name,
filter_kw={"computer_guid": computer_name},
partition_parameter_kw={"conf_text": fluentd_config},
)
- name: Install Python
apt:
name: python
state: present
- name: Install pip
apt:
name: python-pip
state: present
- name: Install i2c-tools
apt:
name: i2c-tools
state: present
- name: Install Python package bme280
pip:
name: bme280
- name: Install python-smbus
apt:
name: python-smbus
state: present
- name: Solve python template to read sensor
template:
src: read_bme280.j2
dest: /usr/local/bin/read_bme280.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
from bme280 import bme280
from bme280 import bme280_i2c
from bme280.bme280 import read_all
bme280_i2c.set_default_i2c_address(int("0x77", 0)) # address of sensor 0x77
bme280_i2c.set_default_bus(int({{ i2c_bus_number }})) # i2c bus number 3 (i2c-3)
bme280.setup()
data = bme280.read_all()
print("{}\t{}\t{}".format(data.pressure,data.humidity,data.temperature))
# Simply import both playbooks so that all variables can be set by the user
- import_playbook: re6stnet.yml
- import_playbook: slapos.yml
- name: a play that runs entirely on the ansible host
hosts: 127.0.0.1
connection: local
vars_prompt:
- name: "fluentd_software_name"
prompt: "What is the name of your Fluentd Software relase?"
private: no
default: "Fluentd software release"
# Playbook to prepare Olimex board to act as a IoT Gateway
# which sends data to a Wendelin instance
- import_playbook: wendelin-olimex-base.yml
- name: a play that runs entirely on the ansible host
hosts: 127.0.0.1
connection: local
vars_prompt:
- name: "streamtool_uri"
prompt: "What is the URL of your Wendelin instance? (e.g. https://softinstXXXX.host.vifib.net)"
private: no
- name: "tag_name"
prompt: "What is your tag name?\nYour tag name must consist of 2 part separated by .(dot). First part is the name of the sensor and must be the same as the reference of the Data Supply. The second part is the type of data (Data Product)."
private: no
default: "sensor_1.sample-environment-raw-data"
- name: "user_name"
prompt: "What is the user name for your Wendelin instance?"
private: no
default: "zope"
- name: "user_password"
prompt: "What is the password for the user of your Wendelin instance?"
private: yes
vars:
fluentd_config: |
<source>
@type forward
port 24224
bind ::0
</source>
<match {{ tag_name }}>
@type wendelin
streamtool_uri {{ streamtool_uri }}/erp5/portal_ingestion_policies/default
user {{ user_name }}
password {{ user_password }}
<buffer>
flush_mode interval
@type file
path fluentd-buffer-file/
flush_interval 1m
</buffer>
roles:
- role: fluentd
# Playbook to prepare Olimex board to run a MOD-ENV sensor and
# parse the tracked data to Fluentd
- import_playbook: wendelin-olimex-base.yml
- name: a play that runs entirely on the ansible host
hosts: 127.0.0.1
connection: local
vars_prompt:
- name: "ipv6_address_iot_gateway"
prompt: "What is the IPv6 address of the host where the data will be send to (IoT Gateway)?"
private: no
- name: "tag_name"
prompt: "What is your tag name?\nYour tag name must consist of 2 part separated by .(dot). First part is the name of the sensor and must be the same as the reference of the Data Supply. The second part is the type of data (Data Product)."
private: no
default: "sensor_1.sample-environment-raw-data"
vars:
fluentd_config: |
<source>
@type exec
tag {{ tag_name }}
command python /usr/local/bin/custom_read_bme280.py
run_interval 1m
<parse>
keys pressure, humidity, temperature
</parse>
</source>
<match {{ tag_name }}>
@type forward
<server>
name myserver1
host {{ ipv6_address_iot_gateway }}
</server>
</match>
roles:
- role: olimex-sensor
- role: fluentd
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment