Terraform like Mac setup
On today’s edition of “Things Joachim finds awesome”, I’m going to go over my recent switch to simple automated macOS re-installs. Essentially how to get your environment back to normal as quickly as possible, and how to test that setup without wiping your current environment out.
Several reasons you might want this
- You’ve installed a bunch of random crap that might or might not be causing system level issues and you really don’t know what. — Don’t tell me that’s never happened to you
- You get a loaner laptop while yours is getting repaired and you want everything back as quickly as possible. — YUCK
- Think someone has taken over the world and your laptop and you want to start from scratch
- Insert your own and many more reasons here :)
Possible options
- Don’t do it. — Would kinda make this blog pointless ;)
- Bunch of shell scripts. — Woohoo write once never understand again
- Ansible to the rescue. — Hum I wonder which one I’m choosing?
After looking at a bunch of projects, I never really wanted to use any of them. They all seemed bug prone and hard to understand what would happen after changes to the scripts. Plus automated installs of app store programs is really a must these days. That’s when I came across geerlingguy/mac-dev-playbook, you can look at my fork josmo/mac-dev-playbook for the changes that I’ve added.
What does it do?
- Uses yml configuration files to define what happens
- Has a more terraform like definition of what is being done vs shell scripts (Honestly it’s a bit in between Terraform and shell scripts but close enough for me)
- Symlink at the dotfiles, includes the possible use
- Installs app store programs
- Install brew and brew cask apps
Ok I want to get started, what should I do? (I want Joachim’s setup)
In your home folder run.
curl https://raw.githubusercontent.com/josmo/mac-dev-playbook/master/syncup.sh | shWTF? is that it?…. Yep that’s it lets looks at what it’s going to do and how you can customize
- It’s going to install homebrew (and with it some X-Code stuff you need ;))
- It’s going to clone my mac-dev-playbook
- install ansible
- install you’re ansible requirements
- runs the main playbook. (installs everything in default.config.yml)
The things I still wish for
So this setup is great and all, but the thing I personally still don’t like is that there’s no concept of removal state. If you remove something from the playbook it doesn’t uninstall it. This is something I personally love about terraform. It represents the current state of the infrastructure where this is more “what I want at the start”. Additionally, I’d love to have a simple command to add something to my configuration a la (again) terraform. Something like “mac-setup add docker” and it would automatically install docker and save the config. This is still way closer then what we’ve had before :)
Lastly- Testing this out
I use parallels for my virtualization needs to replace your preferred virtualization setup where ever I say parallels :)
Currently creating a sample vm with macOS Sierra is pretty simple. Start out by going to the app store, search for Sierra and hit the download button (When it’s done just exit the install, don’t continue). When it’s done insert a usb drive and run (Make sure to change Untitled to the name of the usb drive)
sudo /Applications/Install\ macOS\ Sierra.app/Contents/Resources/createinstallmedia — volume /Volumes/Untitled — applicationpath /Applications/Install\ macOS\ Sierra.appNow in parallels go to the create new Machine wizard, Select the “Install Windows or another OS from a DVD or image file”. From there is should just find your usb disk and start create you’re new VM. Now you can customize mac-dev-playbook and see if everything get’s to the place you want.
With the LIFFFT/Pelo.tech @pelotechnology crew, we’re on the next versions of dev concepts which allow for complete self-hosted apps, deployments which are based on high-availability, high-scalability, and simple blue/green style deployments. Hit me up if you’re interested in more info about it!
Joachim Hill-Grannec @lindyblues is a Partner at http://www.pelo.tech, a group that helps organizations improve their dev practices and culture. These days you’ll also find him traveling around the world dancing at West Coast Swing events.
