make ansible use python3 on osx

When installing Ansible on OSX I ran into the problem of it not using an (existing) python v3.8 but rather the system python (v2.7).

This is often a problem as python is used by the system and must not be touched unless one wants to have problems with their Mac.

So I needed to tell Ansible to use 3.8 instead.

According to this: https://docs.ansible.com/ansible/latest/reference_appendices/python_3_support.html
It’s supposedly enough to install Ansible using pip3 and everything’s fine:

$ pip3 install ansible
$ ansible --version | grep "python version"
  python version = 3.6.2 (default, Sep 22 2017, 08:28:09) [GCC 7.2.1 20170915 (Red Hat 7.2.1-2)]

Which did not work for me:

$ pip3 install ansible
$ ansible --version | grep "python version"
   python version = 2.7.16 ...

Ultimately I found the answer on accident:

$ which ansible
 ansible: aliased to /Users/worp/Library/Python/2.7/bin/ansible

$ ll /Users/worp/Library/Python/2.7/bin/ansible /Users/worp/Library/Python/2.7/bin/ansible

$ ll /Users/worp/Library/Python/3.8/bin/ansible
/Users/worp/Library/Python/3.8/bin/ansible

So the what fixed it for me was simply adding an alias in my zshrc to the ansible in the python version’s folder I wanted to use:

$ cat ~/.zshrc | grep -i alias
...
alias ansible='/Users/worp/Library/Python/3.8/bin/ansible'
...
# Et voila!
$ ansible --version | grep "python version"
  python version = 3.8.9 (default, Oct 26 2021, 07:25:54) [Clang 13.0.0 (clang-1300.0.29.30)]