
Pros and cons
So, now that we have covered some of the different ways of installing Ansible on macOS, which is best? Well, there is no real answer to this as it comes down to personal preference. Both methods will install the latest versions of Ansible. However, Homebrew tends to be a week or two behind the current release.
If you have a lot of packages already installed using Homebrew, then you will already be used to running the following commands:
$ brew update
$ brew upgrade
Every once in a while, do update your installed packages to the latest. If you already do this, then it would make sense to use Homebrew to manage your Ansible installation.
If you are not a Homebrew user and want to make sure that you immediately have the latest version installed, then use the pip command to install Ansible. Upgrading to the latest version of Ansible is as simple as running the following command:
$ sudo -H pip install ansible --upgrade --ignore-installed setuptools
I have found that I need to use the --ignore-installed setuptools flag, as there are problems and conflicts with the version managed by macOS and the one which is part of Ansible updates. I have not known this to cause any problems.
Should you need to, then you can install older versions of Ansible using both Homebrew and pip. To do this using Homebrew, you just need to remove the current version by running the following command:
$ brew uninstall ansible
Then, you can install an earlier version of the package by running the following command:
$ brew install ansible@2.0
Or, for an even earlier version, you can use the command:
$ brew install ansible@1.9
For details on exactly which version of the package is going to be installed, you can run one of the following two commands:
$ brew info ansible@2.0
$ brew info ansible@1.9
While this will install an earlier version, you do not get much choice in which version is installed. If you really need an exact version, you can use the pip command to install it. For example, to install Ansible 2.3.1.0, you would need to run:
$ sudo -H pip install ansible==2.3.1.0 --ignore-installed setuptools
You should never need to do this. However, I have found that on some occasions, I have had to downgrade to help debug quirks in my playbooks introduced by upgrading to a later version.
As mentioned, I spend the bulk of my time in front of a macOS machine in some form or other, so which of the two methods do I use? Primarily, I use Homebrew, as I have several other tools installed using Homebrew. However, if I need to roll back to a previous version, I use pip and then return to Homebrew once the issue is resolved.