Last active
November 3, 2020 13:53
-
-
Save cyclingwithelephants/ebd5107196aac60e22fdcab3de41b447 to your computer and use it in GitHub Desktop.
A gist to bootstrap the ansible playbook used to provision my local dev machine. Taken from https://wilsonmar.github.io/ansible-mac-osx-setup/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# This script bootstraps a OSX laptop for development | |
# to a point where we can run Ansible on localhost. It: | |
# 1. Installs: | |
# - xcode | |
# - homebrew | |
# - ansible (via brew) | |
# - a few ansible galaxy playbooks (zsh, homebrew, cask etc) | |
# 2. Kicks off the ansible playbook: | |
# - main.yml | |
# | |
# It begins by asking for your sudo password: | |
ansible_playbook_repo_name=macos-config | |
ansible_playbook_dir=~/.config/ | |
fancy_echo() { | |
local fmt="$1"; shift | |
# shellcheck disable=SC2059 | |
printf "\n$fmt\n" "$@" | |
} | |
fancy_echo "Boostrapping ..." | |
trap 'ret=$?; test $ret -ne 0 && printf "failed\n\n" >&2; exit $ret' EXIT | |
set -e | |
# Here we go.. ask for the administrator password upfront and run a | |
# keep-alive to update existing `sudo` time stamp until script has finished | |
# sudo -v | |
# while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null & | |
# Ensure Apple's command line tools are installed | |
if ! command -v cc >/dev/null; then | |
fancy_echo "Installing xcode ..." | |
xcode-select --install | |
else | |
fancy_echo "Xcode already installed. Skipping." | |
fi | |
if ! command -v brew >/dev/null; then | |
fancy_echo "Installing Homebrew..." | |
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" </dev/null | |
else | |
fancy_echo "Homebrew already installed. Skipping." | |
fi | |
# [Install Ansible](http://docs.ansible.com/intro_installation.html). | |
if ! command -v ansible >/dev/null; then | |
fancy_echo "Installing Ansible ..." | |
brew install ansible | |
else | |
fancy_echo "Ansible already installed. Skipping." | |
fi | |
# ensure playbook directory exists | |
if [ ! -d "${ansible_playbook_dir}" ]; then | |
fancy_echo "creating repository directory ${ansible_playbook_dir}" | |
mkdir -p ${ansible_playbook_dir} | |
fi | |
# Clone the repository to your local drive. | |
if [ -d "${ansible_playbook_dir}${ansible_playbook_repo_name}" ]; then | |
fancy_echo "Laptop repo dir exists. Removing ..." | |
rm -rf "${ansible_playbook_dir}${ansible_playbook_repo_name}" | |
fi | |
fancy_echo "Cloning laptop repo ..." | |
cd ${ansible_playbook_dir} | |
git clone https://github.com/cyclingwithelephants/${ansible_playbook_repo_name}.git | |
fancy_echo "Changing to laptop repo dir ..." | |
cd ${ansible_playbook_repo_name} | |
fancy_echo "Running ansible playbook ..." | |
ansible-galaxy install -r requirements.yml | |
osascript -e 'tell application "Finder"' -e 'set _b to bounds of window of desktop' -e 'end tell' | |
ansible-playbook playbook.yml -i inventory -K |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment