Ansible is handy, at least for me it has opened up a universe of easier ways to managing the configuration of the huge numbers of servers that are handled in Cloud environments. (That it is based on Python also helps a lot). Getting it to work to communicate with Windows hosts from a macOS host isn´t that straightforward, at least for me it wasn´t. macOS, en general, always makes me pay with a little effort and pain for any action that on another OS I consider trivial. This post is based on some work notes I made when I started having to configure Windows hosts for a series of tests.

Configuring Windows hosts to run Ansible from macOS: The Pain.

To run Ansible and be able to communicate with Windows hosts the most common way is to use WINRM for Python. While trivial on Linux, this can be a bit trickier to achieve on macOS due to the confusing executable paths. Even if you configure everything correctly you may run into the error: winrm or requests is not installed: No module named 'winrm'

no winrm found

It says that winrm is not installed. Well, lets run python3 -m pip install pywinrm to fix it, right? No! Because you’ve been diligent and it’s supposed to be ALREADY installed.

Stop, breathe. The error must make sense. It’s installed, but is it installed for the version of Python that Ansible actually uses? To test this, we can run head -n1 $(which ansible)

ansible´s python

Wait a moment, that’s not the same python that pywinrm is installed for, or is it?

system´s python

Maybe its a bit confusing, but we have already realized the error, as always on this field even if sometimes we find it hard to believe, the error makes sense and we only had to investigate a little to understand what was happening. No, the machine was not plotting against us. Now all that remains is to install the module with pip for the correct Python installation.

installing for the right exec

And finally we will have winrm working for ansible on macOS.

winrm finally working

Kudos as always to Stack Overflow, where I found the answer.