Use Ansible to Configure your Workstation

Let me show you a simple and easy way to manage your MacOS workstation using Ansible. Ansible is awesome, and we should automate all the things.

I tinkered with doing this myself from scratch with some success, but I've discovered Jeff Geerling's incredible collection of Ansible roles and collections and didn't look back. They are simple, and ready to go.

Take a look at my workstation repository, also do check out Jeff's Ansible work.

First you need to install the dependencies. I am using a dotfiles Ansible role to manage my dotfiles, and a collection of mac roles:

ansible-galaxy collection install geerlingguy.mac
ansible-galaxy role install geerlingguy.dotfiles

The mac collection has roles for homebrew, mas, and dock, but I am only concerned with homebrew to install some of my favorite packages. Learn more at https://github.com/geerlingguy/ansible-collection-mac.

Create a playbook setup-macos-workstation.yml:

---
- hosts: localhost
  name: Setup Workstation
  user: roy
  connection: local

vars_files: - vars/main.yml

roles: - geerlingguy.dotfiles - geerlingguy.mac.homebrew

tasks: []

The next thing is to define the dotfiles you want and where to get them, and then also what you want to install via homebrew.

Create vars/main.yml

---
dotfiles_repo: "https://github.com/roylindauer/dotfiles.git"
dotfiles_repo_version: main
dotfiles_files:
  - .zshrc
  - .gitconfig
  - .railsrc
  - .aliases
  - .vimrc
  - rails-template.rb

homebrew_cask_accept_external_apps: true homebrew_installed_packages:

  • libyaml
  • curl
  • coreutils
  • git
  • git-crypt
  • terraform
  • wget
  • zsh
  • doctl
  • go
  • tflint
  • asdf
  • direnv homebrew_cask_appdir: /Applications homebrew_cask_apps:
  • iterm2
  • slack
  • visual-studio-code
  • docker
  • postman
  • spotify
  • notion
  • discord

Run the playbook to download your dotfiles and symlink them to your home directory, and then install all of the packages with brew.

ansible-playbook setup-macos-workstation.yml

This gets me like 80% of the way for setting up my workstation. Some things you have to configure and install manually. But it's nice to have my workstation expressed as code.