Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Commit

Permalink
Issue #112: Split out LED control roles and add Blinkstick role.
Browse files Browse the repository at this point in the history
  • Loading branch information
geerlingguy committed Feb 18, 2019
1 parent 3156394 commit 665ef17
Show file tree
Hide file tree
Showing 21 changed files with 144 additions and 45 deletions.
4 changes: 4 additions & 0 deletions example.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ docker_registry_image: vsellier/docker-registry-arm:2.7.0
docker_registry_domain: registry.pidramble.test
docker_registry_ingress_host: 'kube3'
docker_registry_http_secret: fdb19409c851605cd6c46615888d4c0e37858121df7c

# LED Configuration.
led_enable_gpio: false
led_enable_blinkstick: false
13 changes: 9 additions & 4 deletions main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,22 @@
- role: geerlingguy.kubernetes
tags: ['kubernetes']

- role: leds
- role: leds-gpio
tags: ['leds']
when:
- led_enable_gpio
- deploy_target == 'pi'

- role: leds-blinkstick
tags: ['leds']
when:
- led_enable_blinkstick

tasks:
- include_tasks: tasks/nfs.yml
tags: ['nfs']
when: deploy_target != 'docker'

- import_tasks: tasks/led-monitor.yml
tags: ['leds']

- import_tasks: tasks/k8s-registry-setup.yml
tags: ['kubernetes']

Expand Down
33 changes: 33 additions & 0 deletions roles/leds-blinkstick/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
LEDs - Blinkstick
=================

Blinkstick LED role to install prerequisites and scripts for controlling Blinkstick-based RGB LEDs with the Raspberry Pi Dramble.

Requirements
------------

N/A

Role Variables
--------------

blinkstick_startup_color: red

The color the Blinkstick should be after system boot.

Dependencies
------------

N/A

Example Playbook
----------------

- hosts: pi
roles:
- role: leds-blinkstick

License
-------

MIT
2 changes: 2 additions & 0 deletions roles/leds-blinkstick/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
blinkstick_startup_color: red
15 changes: 15 additions & 0 deletions roles/leds-blinkstick/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
dependencies: []
galaxy_info:
author: Jeff Geerling
description: Blinkstick LED control setup for Rasbperry Pi.
company: Midwestern Mac, LLC
license: license (MIT)
min_ansible_version: 2.4
platforms:
- name: Debian
versions:
- stretch
galaxy_tags:
- monitoring
- system
32 changes: 32 additions & 0 deletions roles/leds-blinkstick/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
- name: Ensure Pip is installed.
apt: name=python-pip state=present

- name: Ensure blinkstick is installed.
pip: name=blinkstick state=present

- name: Ensure blinkstick-leds folder exists.
file:
path: /opt/blinkstick-leds
state: directory
mode: 0755

- name: Copy Blinkstick control scripts into place.
template:
src: "{{ item }}.j2"
dest: "/opt/blinkstick-leds/{{ item }}"
mode: 0755
with_items: "{{ blinkstick_scripts }}"

- name: Make Blinkstick control scripts available in the user's PATH.
file:
path: "/usr/bin/{{ item }}"
src: "/opt/gpio-leds/{{ item }}"
state: link
with_items: "{{ blinkstick_scripts }}"

- name: Set up cron jobs for Blinkstick control.
cron: 'name="{{ item.name }}" special_time=reboot job="{{ item.job }}"'
with_items:
- name: "Set up blinkstick on startup"
job: "blinkstick --set-mode 3 && blinkstick --set-color {{ blinkstick_startup_color }}"
9 changes: 9 additions & 0 deletions roles/leds-blinkstick/templates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Raspberry Pi Blinkstick control scripts

This folder contains Python scripts that can control Blinksticks (Blinkstick Nanos have been tested, but other models may also work).

## Using the scripts

Each of the scripts has a unique purpose:

- TODO
2 changes: 2 additions & 0 deletions roles/leds-blinkstick/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
blinkstick_scripts: []
35 changes: 35 additions & 0 deletions roles/leds-gpio/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
LEDs - GPIO
===========

GPIO LED role to install prerequisites and scripts for controlling custom GPIO-based RGB LEDs with the Raspberry Pi Dramble.

Requirements
------------

N/A

Role Variables
--------------

leds_pin_red: 17
leds_pin_green: 27
leds_pin_blue: 18

A mapping of GPIO pin numbers to color legs on the RGB LED.

Dependencies
------------

N/A

Example Playbook
----------------

- hosts: pi
roles:
- role: leds-gpio

License
-------

MIT
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
shell: "ps aux | grep led"
changed_when: false
register: led_monitor_check
when: deploy_target == 'pi'

- name: Start monitoring nginx requests via GPIO LED.
shell: "/usr/bin/led-log-monitor &"
async: 45
poll: 0
when: deploy_target == 'pi' and 'led-log-monitor' not in led_monitor_check.stdout
when: 'led-log-monitor' not in led_monitor_check.stdout

- name: Add a cron job to automatically start the log monitor after reboot.
cron:
name: "Monitor web requests with the RGB LED"
special_time: reboot
job: "/usr/bin/led-log-monitor &"
when: deploy_target == 'pi'
2 changes: 2 additions & 0 deletions roles/leds/tasks/main.yml → roles/leds-gpio/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@
with_items:
- { name: "Switch to green on RGB LED", job: "/usr/bin/rgb green" }
- { name: "Configure onboard Pi LEDs", job: "/usr/bin/onboard-led-setup" }

- import_tasks: led-monitor.yml
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
38 changes: 0 additions & 38 deletions roles/leds/README.md

This file was deleted.

0 comments on commit 665ef17

Please sign in to comment.