Recently built a small Raspberry Pi cluster that I’m using as a lab for some Ansible automation testing. After seeing the work that Jeff Geerling had done with his “Dramble” cluster it inspired me to also want to leverage a USB light as an indicator on the hosts as tasks were being performed with Ansible.
I have to admit though, I’m fairly lazy and didn’t want to build a USB light so I set out searching for some hopefully cheap alternatives. Luckily I found one for about $12.
This one is called the “fit-statUSB“. Very compact but very nice and bright little light.
Getting it to work was really quite simple. Once you plug it in to a USB port on the Pi you have to configure it.
sudo stty -F /dev/ttyACM0 9600 raw -echo -echoe -echok -echoctl -echoke
Once it is configured you can simply issue the following commands to change the color.
Change light to red:
echo -n -e “#FF0000\r” > /dev/ttyACM0
Change light to green:
echo -n -e “#00FF00\r” > /dev/ttyACM0
As you can see it’s fairly simple. Just change the HEX color value and enjoy a different color.
Now it was a matter of creating a simple playbook to issue the shell command. One thing I found was that you have to use /bin/echo as just using echo would cause it to ignore the -e switch with the echo command.
Playbook Example: --- - name: Turn Light Blue hosts: LAB1 user: root tasks: - name: Command for Blue Light shell: /bin/echo -n -e "#0000FF\r" > /dev/ttyACM0 - name: Turn Light Red hosts: LAB1 user: root tasks: - name: Command for Red Light shell: /bin/echo -n -e "#FF0000\r" > /dev/ttyACM0 - name: Turn Light Green hosts: LAB1 user: root tasks: - name: Command for Green Light shell: /bin/echo -n -e "#00FF00\r" > /dev/ttyACM0
That’s it folk, that simple and works great. You can use it to get a visual representation of what host Ansible is currently configuring, what task is currently running and so on. Use your imagination. Especially useful for a stack of Pi’s and learning.
Make sure you configure the USB light first as mentioned earlier. If you don’t configure it, you will find it works once and will change the color when using the playbook but all subsequent commands will fail and you will have to reset the USB light manually.