Ansible + Alpine = "this is probably a bug"

I started moving away from several deploy scripts, git repositories and other crazy things to handle my few machines, I will follow this progress with a few blog posts on interesting things I encounter down the way.
Starting with something took me way more than expected.

Getting ansible to run on Alpine linux

Pretty simple, right? Think again.

The first setp is pretty simple 'tho, just add ansible and openssh-client to use ssh as connection method:

#apk add ansible openssh-client

At this point I was expecting to be able to just add the hosts file and to be able to run my first command, as I did in the past,as you might have figured by the title, this was not the case.
ERROR! Unexpected Exception, this is probably a bug: [Errno 2] No such file or directory

Yes, a very helpful message: ERROR! Unexpected Exception, this is probably a bug: [Errno 2] No such file or directory, and note that I did run the command with the highest level of verbosity so you get some extra info otherwise you only get that error. To be failr, in this case (-vvv) the message is followed by a long traceback, which I initially ignored (bad, BAD!).
At this point after some random attempts I started google-ing for answers with very little success. It is only when I finally looked back to the helpful traceback that i noticed something interesting: the process was interrupting at _multiprocessing.SemLock, a quick search and a lot of variegated issues, but all with a common point: /dev/shm!!

HA!! A quick check and.. Yes, that was the problem!

I'm not sure if that's an Alpine linux issue or a Scaleway configuration, but apparently the shared memory device was not mounted, so the solution was rather easy

# mkdir /dev/shm
# chmod 777 /dev/shm
# echo 'none /dev/shm tmpfs rw,nosuid,nodev,noexec 0 0' >> /etc/fstab
# mount /dev/shm

That's it.
Now ansible works like a chram!

Closing note

I have seen the following error messages to be solved correctly mounting the shm device:

  • OSError: [Errno 2] No such file or directory
  • OSError: [Errno 13] Permission denied
  • OSError: [Errno 23] Too many open files in system... Well, no that's a whole different story.
  • OSError: [Errno 28] No space left on device
  • OSError : [Errno 38] Function not implemented

Altough the errors appear with different message all those are related to the python semaphore handling and the  _multiprocessing.SemLock call, as this alwas seesm to be the least call in the traceback:

File "/usr/lib/python2.7/multiprocessing/", line 75, in __init__
    sl = self._semlock = _multiprocessing.SemLock(kind, value, maxvalue)