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.

9 thoughts on “How to automate your Mac OS X setup with Ansible

    1. Hi Fotis,

      I don’t use LaunchPad and Notification Centre. Can’t you control them with the ‘default’ utility?

      Btw. thanks for sharing your knowledge. Will take a look at it!


  1. I love this. Thank you for sharing.

    I have an improvement for the dockutil section that makes it possible to run the playbook over and over without having it change the dock.

    My working playbook is here:

    ansible-playbook will then report no changes when the changes have already been applied:

    localhost : ok=26 changed=0 unreachable=0 failed=0

  2. Although my fork has an outdated readme, it includes dockutil in a clean way.
    I thank you for your inspiration, so if you want to check mine out:

    Mine also includes the configuration of Sublime.
    This is something Jeff Geerling has stated he wants to do but hasn’t yet – my solution won’t work for everybody but it does work for me.

  3. I am new to Ansible and will be picking up some books but just wanted to ask a quick question. This all makes sense for an initial setup, but what about go-forward maintenance?
    If I wanted to tweak a terminal or dock setting, add a new application or package, or update Sublime from 2 to 3, do you update then simply re-run this playbook and it will only add/change what I changed? Will it re-run the brew calls and upgrade the apps?

  4. Great tutorial, thx! Small addition to Terminal configuration: I use the custom font Bitstream Vera Sans Mono. To install it, simply add the following to your homebrew vars:

    … well, this is more Cask related, but I was just happy this was supported and wanted to share.

Leave a Reply

Your email address will not be published. Required fields are marked *