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 README.md
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:
1 |
$ ansible-galaxy install geerlingguy.homebrew |
To configure the role to suit your needs you have to edit vars/main.yml
. My current version as an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
--- homebrew_install_path: /usr/local/homebrew homebrew_installed_packages: - ansible - docker - git - ssh-copy-id - openssl - wget - brew-cask - dockutil - zsh - tmux - mercurial - phpmd - php-code-sniffer - php-cs-fixer - phpunit - php70 - php70-intl - php70-xdebug - php70-imagick - php70-mcrypt homebrew_taps: - caskroom/cask - caskroom/versions - homebrew/php homebrew_cask_appdir: /Applications homebrew_cask_apps: - google-chrome - dropbox - firefox - limechat - vagrant - virtualbox - phpstorm - slack - istat-menus - atom - android-file-transfer - limechat - spotify - dockertoolbox |
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
--- - name: Remove all crap from Dock shell: dockutil --remove '{{ item }}' ignore_errors: true with_items: dockitems_to_remove - name: Check if items in dock exist shell: dockutil --find '{{ item.name }}' || dockutil --add '{{ item.path }}' with_items: dockitems_to_persist - name: Fix order shell: dockutil --move '{{ item.name }}' --position {{ item.pos }} with_items: dockitems_to_persist |
Vars:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
dockitems_to_remove: - Launchpad - Mail - Safari - Contacts - Notes - Reminders - Maps - Photos - Messages - FaceTime - iTunes - iBooks - App Store - System Preferences - Calendar dockitems_to_persist: - name: Google Chrome path: "/Applications/Google Chrome.app" pos: 1 - name: Firefox path: "/Applications/Firefox.app" pos: 2 - name: PhpStorm path: /Applications/PhpStorm.app pos: 3 - name: Slack path: /Applications/Slack.app pos: 4 - name: VirtualBox path: /Applications/VirtualBox.app pos: 5 - name: Terminal path: /Applications/Utilities/Terminal.app pos: 6 - name: Spotify path: /Applications/Spotify.app pos: 7 |
Terminal
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
- name: Get current Terminal profile. shell: defaults read com.apple.Terminal 'Default Window Settings' register: terminal_theme changed_when: false - name: Ensure custom Terminal profile is added. shell: open files/Solarized-Dark.terminal changed_when: false when: "'Solarized-Dark' not in terminal_theme.stdout" - name: Ensure custom Terminal profile is set as default. shell: "{{ item }}" with_items: - defaults write com.apple.Terminal 'Default Window Settings' -string 'Solarized-Dark' - defaults write com.apple.Terminal 'Startup Window Settings' -string 'Solarized-Dark' changed_when: false when: "'Solarized Dark ansi' not in terminal_theme.stdout" |
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.