How to Install Ansible on OS X El Capitan

You only need to install it on one machine (which could easily be a laptop) and it can manage an entire fleet of remote machines from that central point. When Ansible manages remote machines, it does not leave software installed or running on them, so there’s no real question about how to upgrade Ansible when moving to a new version.

Once Ansible is installed, it will not add a database, and there will be no daemons to start or keep running.

Ansible by default manages machines over the SSH protocol.

Install the Command Line Developer Tools for OS X El Capitan.

If Xcode is not currently installed, we can simply grab the Command Line Developer Tools for OS X El Capitan.

$ xcode-select --install
xcode-select: note: install requested for command line developer tools

Install 'pip'.

OS X El Capitan System Integrity Protection makes it difficult to alter system-level components, so we will be installing the Python components with the --user option.

$ easy_install --help | grep -A 3 -- --user
  --user                     install in user site-package
$ easy_install --user pip

Add the Python 2.7 user bin directory to our PATH variable.

For example, if using the default shell (Bash) with no existing configuration:

$ printf 'if [ -f ~/.bashrc ]; then\n  source ~/.bashrc\nfi\n' >> $HOME/.profile
$ printf 'export PATH=$PATH:$HOME/Library/Python/2.7/bin\n' >> $HOME/.bashrc
$ source $HOME/.profile

Verify the 'pip' command is now in our PATH.

$ pip --version

Install/Upgrade 'ansible' via 'pip'.

$ pip install --help | grep -A 2 -- --user
  --user                      Install to the Python user install directory for your
                              platform. Typically ~/.local/, or %APPDATA%\Python on
                              Windows. (See the Python documentation for site.USER_BASE
                              for full details.)
$ pip install --user --upgrade ansible

Verify the successful installation of the Ansible components.

$ type -a ansible
$ ansible --version

Create the system-wide Ansible directory.

$ sudo mkdir /etc/ansible

Copy the default Ansible configuration file to the system-wide Ansible directory.

$ sudo curl -L -o /etc/ansible/ansible.cfg


By default, we don't have an existing Ansible Inventory, but we can run ansible with localhost as the target.

$ ansible localhost -m ping
localhost | success >> {
    "changed": false,
    "ping": "pong"

$ ansible localhost -m setup -a 'filter=ansible_distribution'
localhost | success >> {
    "ansible_facts": {
        "ansible_distribution": "MacOSX"
    "changed": false

$ ansible localhost -a 'uname -a'
localhost | success | rc=0 >>
Darwin Mac-Pro.local 15.3.0 Darwin Kernel Version 15.3.0: Thu Dec 10 18:40:58 PST 2015; root:xnu-3248.30.4~1/RELEASE_X86_64 x86_64

Raise open file descriptors value for Ansible >= 2.x

As of version 2.0, Ansible uses a few more file handles to manage its forks. OS X has a very low default setting (256), so if we want to use 15 or more forks, we will need to raise the maximum number of open file descriptors value.

$ launchctl limit maxfiles
 maxfiles    256            unlimited
$ sudo launchctl limit maxfiles 1024 unlimited

To make the change persistent, we need to create a launchd property list file. Refer to How to persist ulimit settings in OSX Mavericks? for more information.

$ launchctl limit maxfiles
 maxfiles    524288            524288
$ ulimit -n

Create the Ansible Inventory and Playbooks.


List outdated packages installed in user-site.

$ pip list --user --outdated

Update outdated packages installed in user-site.

For example, if the setuptools and ansible packages were listed in the output of the previous command:

$ pip install --user --upgrade setuptools
$ pip install --user --upgrade ansible

No comments:

Powered by Blogger.