How to automate your Mac OS X setup with Ansible

Last month I updated my development machine to the shiny new El Capitan. Unfortunately as a zsh and tmux user I ran into a very annoying bug and so I was forced to re-install my MBP with Yosemite. Because I belong to the power users which tend to customise their installations a lot and because I like automation I decided I was going to automate this cumbersome job for once and for all. Of course, with my favourite configuration management tool: Ansible.

It appears I’m not the only one and found Jeff Geerling’s excellent mac-dev-playbook repository. The contains a lot of useful information and the repository is an excellent starting point. I’ve also used it as starting point for my own repository. In this post I’ll explain the most important details of my setup.

Installation of Applications and packages

I like Homebrew to install packages on my Mac so that’s also what I use in my Ansible setup. There is a ready to use Ansible role available – also created by Jeff Geerling – which I recommend. To use it:

To configure the role to suit your needs you have to edit vars/main.yml. My current version as an example:

The Dock

There is a neat utility available called dockutil which allows you to take full control over your dock. You can install it via Homebrew, so just register it under homebrew_installed_packages.

I use the following tasks and vars to fix my dock:



I spend a significant amount of the day in the terminal, so I’ve tweaked the default Terminal settings a lot. The cool thing is these settings can be exported via Shell > Export settings. The Ansible task to import such a file:

Mac OS X tweaks

A lot of people don’t know you can configure a lot of settings via the command line interface to the user defaults. You can read and write these settings. For some inspiration take a look at my defaults.