Ansible for old Macs

2 minute read

I have been playing around with Ansible lately and one of the use cases I have found is for a Mac rebuild.

I have tested with MacOS Monterey on a MacBook 12-inch, Early 2016. I will rebuild my 2017 Intel Macbook Pro running Ventura shortly.

Initially, I wouldn’t really have distinguished between old/new Mac but I just dove into using Homebrew and it was taking hours. Had I done a little research prior I would have noticed it isn’t even supported anymore on Monterey. So I modified my approach to use MacPorts and it runs great. No issues! It isn’t as hip as HomeBrew, I guess, but works on older macs easily.

It essentially sets up my Mac how I like it. Installs various stuff and configures the terminal to look and function better. Feel free to use and modify to your own preferences. Ansible is fun!

You can clone or fork the repository from here

Instructions

Basically, fork or clone this repository then modify and run.

Below is my rebuild process.

  1. Refresh installation of Mac using Command R during boot. Takes a couple of hours.
  2. Update OS. Another 45 minutes with reboot.
  3. [optional] Change hostname
  4. [optional] Update DNS to the internal DNS server for local name resolution
  5. [optional] Add the new hostname to the local DNS server
  6. [optional] Set a static IP via reserved DHCP.
  7. Install x-tools. Another 20 minutes.
xcode-select --install
  1. Download then install MacPorts. You can download from here. Click on your version of OSX
  2. Download and install Python for mac. You can get here
  3. Install Python which also installs pip. Make sure to click on the Install Certificates.command when the installation completes.
  4. Upgrade pip
pip3 install --upgrade pip
  1. Install Ansible on the Macbook
pip3 install ansible
  1. Clone or fork this repo.
  2. Modify the hosts file to the hostname of your Mac. You can check by running the hostname command.
  3. Modify the group_vars/all.yml to your username. NOTE: It is expected the username is already created on the Mac as this is required during installation/rebuild.
  4. Run playbook from Macbook. It is meant to be run using ansible-pull from your git repo. It needs to be run using sudo. Takes about an hour to complete on my MacBook.
# If a public repo then run the following from the Mac. Replace with your values.
sudo ansible-pull -U https://github.com/<Your Account>/your_git.git
# If a private repo then run the following from the Mac. Replace with your values.
export OAUTH_TOKEN="Insert your github oauth token here"
ansible-pull -U https://oauth2:$OAUTH_TOKEN@github.com/ProServicesStorage/ansible_configs.git