From 665ef17127e337e523d7700d0c96f03a616d9a50 Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Mon, 18 Feb 2019 15:27:06 -0600 Subject: [PATCH] Issue #112: Split out LED control roles and add Blinkstick role. --- example.config.yml | 4 ++ main.yml | 13 +++++-- roles/leds-blinkstick/README.md | 33 ++++++++++++++++ roles/leds-blinkstick/defaults/main.yml | 2 + roles/leds-blinkstick/meta/main.yml | 15 ++++++++ roles/leds-blinkstick/tasks/main.yml | 32 ++++++++++++++++ roles/leds-blinkstick/templates/README.md | 9 +++++ roles/leds-blinkstick/vars/main.yml | 2 + roles/leds-gpio/README.md | 35 +++++++++++++++++ roles/{leds => leds-gpio}/defaults/main.yml | 0 roles/{leds => leds-gpio}/meta/main.yml | 0 .../leds-gpio/tasks}/led-monitor.yml | 4 +- roles/{leds => leds-gpio}/tasks/main.yml | 2 + roles/{leds => leds-gpio}/templates/README.md | 0 roles/{leds => leds-gpio}/templates/colors.j2 | 0 roles/{leds => leds-gpio}/templates/fade.j2 | 0 .../templates/led-log-monitor.j2 | 0 .../templates/onboard-led-setup.j2 | 0 roles/{leds => leds-gpio}/templates/rgb.j2 | 0 roles/{leds => leds-gpio}/vars/main.yml | 0 roles/leds/README.md | 38 ------------------- 21 files changed, 144 insertions(+), 45 deletions(-) create mode 100644 roles/leds-blinkstick/README.md create mode 100644 roles/leds-blinkstick/defaults/main.yml create mode 100644 roles/leds-blinkstick/meta/main.yml create mode 100644 roles/leds-blinkstick/tasks/main.yml create mode 100644 roles/leds-blinkstick/templates/README.md create mode 100644 roles/leds-blinkstick/vars/main.yml create mode 100644 roles/leds-gpio/README.md rename roles/{leds => leds-gpio}/defaults/main.yml (100%) rename roles/{leds => leds-gpio}/meta/main.yml (100%) rename {tasks => roles/leds-gpio/tasks}/led-monitor.yml (76%) rename roles/{leds => leds-gpio}/tasks/main.yml (96%) rename roles/{leds => leds-gpio}/templates/README.md (100%) rename roles/{leds => leds-gpio}/templates/colors.j2 (100%) rename roles/{leds => leds-gpio}/templates/fade.j2 (100%) rename roles/{leds => leds-gpio}/templates/led-log-monitor.j2 (100%) rename roles/{leds => leds-gpio}/templates/onboard-led-setup.j2 (100%) rename roles/{leds => leds-gpio}/templates/rgb.j2 (100%) rename roles/{leds => leds-gpio}/vars/main.yml (100%) delete mode 100644 roles/leds/README.md diff --git a/example.config.yml b/example.config.yml index db13ab3..0f84ef5 100644 --- a/example.config.yml +++ b/example.config.yml @@ -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 diff --git a/main.yml b/main.yml index 9653144..45ffa67 100644 --- a/main.yml +++ b/main.yml @@ -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'] diff --git a/roles/leds-blinkstick/README.md b/roles/leds-blinkstick/README.md new file mode 100644 index 0000000..8d252da --- /dev/null +++ b/roles/leds-blinkstick/README.md @@ -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 diff --git a/roles/leds-blinkstick/defaults/main.yml b/roles/leds-blinkstick/defaults/main.yml new file mode 100644 index 0000000..05efa24 --- /dev/null +++ b/roles/leds-blinkstick/defaults/main.yml @@ -0,0 +1,2 @@ +--- +blinkstick_startup_color: red diff --git a/roles/leds-blinkstick/meta/main.yml b/roles/leds-blinkstick/meta/main.yml new file mode 100644 index 0000000..4335004 --- /dev/null +++ b/roles/leds-blinkstick/meta/main.yml @@ -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 diff --git a/roles/leds-blinkstick/tasks/main.yml b/roles/leds-blinkstick/tasks/main.yml new file mode 100644 index 0000000..c0558ab --- /dev/null +++ b/roles/leds-blinkstick/tasks/main.yml @@ -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 }}" diff --git a/roles/leds-blinkstick/templates/README.md b/roles/leds-blinkstick/templates/README.md new file mode 100644 index 0000000..6b39af9 --- /dev/null +++ b/roles/leds-blinkstick/templates/README.md @@ -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 diff --git a/roles/leds-blinkstick/vars/main.yml b/roles/leds-blinkstick/vars/main.yml new file mode 100644 index 0000000..ea707b2 --- /dev/null +++ b/roles/leds-blinkstick/vars/main.yml @@ -0,0 +1,2 @@ +--- +blinkstick_scripts: [] diff --git a/roles/leds-gpio/README.md b/roles/leds-gpio/README.md new file mode 100644 index 0000000..44351db --- /dev/null +++ b/roles/leds-gpio/README.md @@ -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 diff --git a/roles/leds/defaults/main.yml b/roles/leds-gpio/defaults/main.yml similarity index 100% rename from roles/leds/defaults/main.yml rename to roles/leds-gpio/defaults/main.yml diff --git a/roles/leds/meta/main.yml b/roles/leds-gpio/meta/main.yml similarity index 100% rename from roles/leds/meta/main.yml rename to roles/leds-gpio/meta/main.yml diff --git a/tasks/led-monitor.yml b/roles/leds-gpio/tasks/led-monitor.yml similarity index 76% rename from tasks/led-monitor.yml rename to roles/leds-gpio/tasks/led-monitor.yml index 2d98c49..8badb03 100644 --- a/tasks/led-monitor.yml +++ b/roles/leds-gpio/tasks/led-monitor.yml @@ -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' \ No newline at end of file diff --git a/roles/leds/tasks/main.yml b/roles/leds-gpio/tasks/main.yml similarity index 96% rename from roles/leds/tasks/main.yml rename to roles/leds-gpio/tasks/main.yml index 807f879..60fc1eb 100644 --- a/roles/leds/tasks/main.yml +++ b/roles/leds-gpio/tasks/main.yml @@ -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 diff --git a/roles/leds/templates/README.md b/roles/leds-gpio/templates/README.md similarity index 100% rename from roles/leds/templates/README.md rename to roles/leds-gpio/templates/README.md diff --git a/roles/leds/templates/colors.j2 b/roles/leds-gpio/templates/colors.j2 similarity index 100% rename from roles/leds/templates/colors.j2 rename to roles/leds-gpio/templates/colors.j2 diff --git a/roles/leds/templates/fade.j2 b/roles/leds-gpio/templates/fade.j2 similarity index 100% rename from roles/leds/templates/fade.j2 rename to roles/leds-gpio/templates/fade.j2 diff --git a/roles/leds/templates/led-log-monitor.j2 b/roles/leds-gpio/templates/led-log-monitor.j2 similarity index 100% rename from roles/leds/templates/led-log-monitor.j2 rename to roles/leds-gpio/templates/led-log-monitor.j2 diff --git a/roles/leds/templates/onboard-led-setup.j2 b/roles/leds-gpio/templates/onboard-led-setup.j2 similarity index 100% rename from roles/leds/templates/onboard-led-setup.j2 rename to roles/leds-gpio/templates/onboard-led-setup.j2 diff --git a/roles/leds/templates/rgb.j2 b/roles/leds-gpio/templates/rgb.j2 similarity index 100% rename from roles/leds/templates/rgb.j2 rename to roles/leds-gpio/templates/rgb.j2 diff --git a/roles/leds/vars/main.yml b/roles/leds-gpio/vars/main.yml similarity index 100% rename from roles/leds/vars/main.yml rename to roles/leds-gpio/vars/main.yml diff --git a/roles/leds/README.md b/roles/leds/README.md deleted file mode 100644 index 225dd44..0000000 --- a/roles/leds/README.md +++ /dev/null @@ -1,38 +0,0 @@ -Role Name -========= - -A brief description of the role goes here. - -Requirements ------------- - -Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. - -Role Variables --------------- - -A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. - -Dependencies ------------- - -A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. - -Example Playbook ----------------- - -Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: - - - hosts: servers - roles: - - { role: username.rolename, x: 42 } - -License -------- - -BSD - -Author Information ------------------- - -An optional section for the role authors to include contact information, or a website (HTML is not allowed).