Table of Contents
Go from Ansible beginner to Ansible pro with this full video course.
The two best methods for installing Ansible on Mac OS X are:
- Using Homebrew (best for beginners)
- Using Python
pip
(best for advanced users)
The official documentation states that their preferred method for installing Ansible on Mac OS X is using Python pip
. I also agree that this is the best way to install Ansible and this is how I do it on my machine, however I think installing it by using Homebrew is probably the best way for beginners.
The main difference between the two methods is that using pip
will give you more control over the Python version Ansible uses as well as any Python packages that Ansible depends on. This is especially useful if you’re using a version manager like asdf
, which I highly recommend.
How to install Ansible on Mac OS X using Homebrew
First, ensure that you have Homebrew installed. Homebrew is a package manager for Mac OS X that allows you to install many packages useful for web/software development.
Installing Ansible on Mac OS X with Homebrew is as simple as running brew install ansible
in Terminal (or your preferred terminal application):
$ brew install ansible
After the installation has finished, you can confirm that Ansible has installed correctly by running ansible --version
:
$ ansible --version
ansible 2.7.5
config file = None
configured module search path = ['/Users/percy/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/Cellar/ansible/2.7.5/libexec/lib/python3.7/site-packages/ansible
executable location = /usr/local/bin/ansible
python version = 3.7.2 (default, Dec 27 2018, 07:35:52) [Clang 10.0.0 (clang-1000.11.45.5)]
If ansible --version
runs successfully, congratulations! You now have Ansible’s power at your fingertips and you’re ready to start managing your servers.
How to install Ansible on Mac OS X using Python pip
Confirm that pip
is installed and upgrade it to the latest version
First, ensure that Python pip
is installed on your system. You can check if pip
is in your PATH
by running which pip
. If pip
is found, run pip --version
to confirm that everything is working as expected:
$ which pip
/Users/percy/.asdf/shims/pip
$ pip --version
pip 18.1 from /Users/percy/.asdf/installs/python/2.7.15/lib/python2.7/site-packages/pip (python 2.7)
I use asdf
to manage the Python versions on my system (and I suggest you do too). pip
is automatically installed along with asdf
Python installations.
If pip
isn’t on your system and you’re using the default Python version on your system, you can usually install pip
by running sudo easy_install pip
.
I suggest running pip install --upgrade pip
to update pip
to the latest version before installing Ansible:
$ pip install --upgrade pip
Requirement already up-to-date: pip in ./.asdf/installs/python/2.7.15/lib/python2.7/site-packages (18.1)
Install Ansible
Assuming pip
is installed and working, installing Ansible is as simple as running pip install ansible
:
$ pip install ansible
Collecting ansible
...
Successfully installed MarkupSafe-1.1.0 PyYAML-3.13 ansible-2.7.5 asn1crypto-0.24.0 bcrypt-3.1.5 cffi-1.11.5 cryptography-2.4.2 enum34-1.1.6 idna-2.8 ipaddress-1.0.22 jinja2-2.10 paramiko-2.4.2 pyasn1-0.4.5 pycparser-2.19 pynacl-1.3.0 six-1.12.0
Confirm that ansible
is in your path and that it runs as expected:
$ asdf reshim python
$ which ansible
/Users/percy/.asdf/shims/ansible
$ ansible --version
ansible 2.7.5
config file = None
configured module search path = [u'/Users/percy/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /Users/percy/.asdf/installs/python/2.7.15/lib/python2.7/site-packages/ansible
executable location = /Users/percy/.asdf/installs/python/2.7.15/bin/ansible
python version = 2.7.15 (default, Jan 9 2019, 17:43:11) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.38)]
If ansible --version
runs successfully, congratulations! You now have Ansible’s power at your fingertips and you’re ready to start managing your servers.