Install Python 3.9 on Raspberry Pi OS or Debian 10 (for Ansible or other uses)

I've started getting a lot of bug reports on my repos to the effect of "Ansible won't install on my Raspberry Pi anymore". Accompanying it is a debug message like one of the following:

$ python3 -m pip install ansible
No matching distribution found for ansible-core<2.13,>=2.12.0 (from ansible)

# Alternatively:
ERROR: No matching distribution found for ansible-core<2.13,>=2.12.0

The problem is ansible-core 2.12 has a new hard requirement for Python 3.8 or newer. And ansible-core 2.12 is included in Ansible 5.0.0, which was recently released. Raspberry Pi OS, which was based on Debian 10 ("Buster") until recently, includes Python 3.7, which is too old to satisfy Ansible's installation requirements.

There was recently a fix that makes it so Ansible 5.x won't get installed on these older systems, but who wants to get stuck on old unsupported Ansible versions?

There are three options:

Face detection for my leaf blower

In the class of 'out there' projects, I recently added a little AI to my leaf blower:

Leaf blower with Raspberry Pi on top for AI ML Machine Vision blasting

The short of it: I have a face detection algorithm running which, when a certain individual enters the field of the Pi's vision, triggers a servo that powers on the blower, releasing a powerful air blast.

Red Shirt Jeff gets blasted by air cannon

I've been wanting to play around with face detection on the Pi for some time, but the Pi Zero I use in most of my camera projects is seriously underpowered for this kind of work.

CM4Ext Nano

So when Harlab (Hardware Laboratory) told me they'd like to send me a CM4Ext Nano board for testing, I thought it'd be the perfect opportunity to play with machine vision on the Pi.

The Raspberry Pi IoT Notification Bell

Harbinger of the Internet of Dings

Last year, I built the first version of what I call the "Raspberry Pi Bell Slapper." It was named that because it used a servo and a metal arm to slap the top of the bell in response to a stimuli—in this case, an email from a donation notification system for a local non-profit radio station.

This year, that same radio station had another one of their fund-raisers (a radiothon), and to celebrate, I thought I'd do the thing justice, with a better circuit (using a solenoid instead of a servo) and a 3D printed enclosure. And this is the result:

Clarence 2.0 - The Raspberry Pi Notification Bell

There is a Raspberry Pi Zero W with a custom solenoid control HAT on top inside the case to the left, and the solenoid right up against the bell, which is mounted on the right.

I also posted a video on YouTube exploring the project in detail: The Raspberry Pi IoT Notification Bell.

Fixing 'UNREACHABLE' SSH error when running Ansible playbooks against Ubuntu 18.04 or 16.04

Ubuntu 16.04 and 18.04 (and likely future versions) often don't have Python 2 installed by default. Sometimes Python 3 is installed, available at /usr/bin/python3, but for many minimal images I've used, there's no preinstalled Python at all.

Therefore, when you run Ansible playbooks against new VMs running Ubuntu, you might be greeted with the following error:

Changing a deeply-nested dict variable in an Ansible playbook

I recently had to build an Ansible playbook that takes in a massive inventory structure (read from a YAML file), modifies a specific key in that file, then dumps the file back to disk. There are some other ways that may be more efficient standalone (e.g. using a separate Python/PHP/Ruby/etc. script and a good YAML library), but since I had to do a number of other things in this Ansible playbook, I thought it would keep it simple if I could also modify the key inside the playbook.

I was scratching my head for a while, because while I knew that I could use the dict | combine() filter to merge two dicts together (this is a feature that was introduced in Ansible 2.0), I hadn't done so for a deeply-nested dict.

How to fix SSH errors when using Ansible with newer OSes like Ubuntu 16.04

Recently, as I've been building more and more servers running Ubuntu 16.04, I've hit the following errors:

PLAY [host] ************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************
fatal: []: UNREACHABLE! => {"changed": false, "msg": "SSH Error: data could not be sent to remote host "". Make sure this host can be reached over ssh", "unreachable": true}


/bin/sh: 1: /usr/bin/python: not found

The former error seems to happen when you're running a playbook on an Ubuntu 16.04 host (with gather_facts: yes), while the latter happens if you're using a minimal distribution that doesn't include Python at all. The problem, in both cases, is that Python 2.x is not installed on the server, and there are two different fixes: