From d07e57d664f424b94a8cdec1c8573669909d0129 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Sun, 4 Jan 2015 20:29:16 -0800 Subject: [PATCH] [meta] Update OS X Ansible role Add a bootstrap role to update `~/.dotfiles` and run `sudo` once (so that Homebrew's internal `sudo` calls work). Also allow for running Ansible from a remote computer onto the target Mac. --- README.md | 46 ++++++++++++++++++----- ansible/main.yml | 6 +-- ansible/roles/bootstrap/tasks/main.yml | 9 +++++ ansible/roles/dotfiles/tasks/dotfiles.yml | 6 --- ansible/roles/osx/tasks/bootstrap.yml | 10 +++++ ansible/roles/osx/tasks/casks.yml | 6 +-- ansible/roles/osx/tasks/defaults.yml | 5 ++- ansible/roles/osx/tasks/dock.yml | 4 +- ansible/roles/osx/tasks/fonts.yml | 2 + ansible/roles/osx/tasks/formulae.yml | 8 ++-- ansible/roles/osx/tasks/main.yml | 13 ++++--- ansible/roles/osx/vars/casks.yml | 2 +- ansible/roles/osx/vars/defaults.yml | 20 +++------- ansible/roles/osx/vars/formulae.yml | 28 +++++++------- 14 files changed, 102 insertions(+), 63 deletions(-) create mode 100644 ansible/roles/bootstrap/tasks/main.yml create mode 100644 ansible/roles/osx/tasks/bootstrap.yml diff --git a/README.md b/README.md index 875b50c..29718f2 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,34 @@ A new beginning for what used to be my appears to be the conventional name of these types of repos nowadays. This uses [Ansible](https://github.com/ansible/ansible) to provision new -machines and [stow](http://www.gnu.org/software/stow/) for managing conf -files that can be symlinked. +machines. # Usage +There are two ways to go about using this - either locally or remotely. The main +difference is that OS X application settings are only copied over when running +this on a remote machine. + +Either way, we start with installing Xcode: + +``` shell +xcode-select --install +open 'https://itunes.apple.com/us/app/xcode/id497799835?mt=12' +sudo xcodebuild -license +``` + +**After running Ansible**, the bootstrap `~/.dotfiles` directory can be removed +and replaced with a symlink to the canonical repo location on Dropbox and SSH +keys can be populated with the included script: + +``` shell +rm -rf ~/.dotfiles +ln -s ~/Dropbox/dotfiles ~/.dotfiles +ruby ~/.dotfiles/ansible/scripts/setup_ssh_keys.rb +``` + +## Local + ``` shell # Install Homebrew ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" @@ -18,20 +41,23 @@ brew install ansible # Clone dotfiles git clone --recursive https://github.com/kejadlen/dotfiles.git ~/.dotfiles -# Xcode -open 'https://itunes.apple.com/us/app/xcode/id497799835?mt=12' -sudo xcodebuild -license - # Run Ansible cd ~/.dotfiles/ansible && ansible-playbook main.yml --ask-sudo-pass rm -f ~/*.retry +``` -# Post-Dropbox syncing -rm -rf ~/.dotfiles -ln -s ~/Dropbox/dotfiles ~/.dotfiles -ruby ~/.dotfiles/ansible/scripts/setup_ssh_keys.rb +## Remote + +On the remote machine, SSH access must first be enabled (under System +Preferences -> Sharing) and the Xcode Command Line Tools need to be installed +(`xcode-select --install`). + +``` shell +cd ~/.dotfiles/ansible && ansible-playbook main.yml --ask-pass --ask-sudo-pass ``` +# Misc + To update submodules: ``` shell diff --git a/ansible/main.yml b/ansible/main.yml index fe8bef3..d5214b4 100644 --- a/ansible/main.yml +++ b/ansible/main.yml @@ -1,5 +1,5 @@ -- hosts: local - connection: local +- hosts: all roles: + - bootstrap - osx - - dotfiles + # - dotfiles diff --git a/ansible/roles/bootstrap/tasks/main.yml b/ansible/roles/bootstrap/tasks/main.yml new file mode 100644 index 0000000..b53acfe --- /dev/null +++ b/ansible/roles/bootstrap/tasks/main.yml @@ -0,0 +1,9 @@ +--- +- git: + repo: https://github.com/kejadlen/dotfiles.git + recursive: yes + dest: ~/.dotfiles + force: no +- name: no-op so that sudo works in Homebrew later + ping: + sudo: True diff --git a/ansible/roles/dotfiles/tasks/dotfiles.yml b/ansible/roles/dotfiles/tasks/dotfiles.yml index 1f252e5..e941199 100644 --- a/ansible/roles/dotfiles/tasks/dotfiles.yml +++ b/ansible/roles/dotfiles/tasks/dotfiles.yml @@ -7,12 +7,6 @@ - stow sudo: True when: ansible_os_family == "Debian" -- git: - repo: https://github.com/kejadlen/dotfiles.git - depth: 1 - dest: ~/.dotfiles - recursive: yes - force: no - command: > chdir={{ ansible_env.HOME }}/.dotfiles stow --stow --target={{ ansible_env.HOME }} {{ item }} diff --git a/ansible/roles/osx/tasks/bootstrap.yml b/ansible/roles/osx/tasks/bootstrap.yml new file mode 100644 index 0000000..a634b64 --- /dev/null +++ b/ansible/roles/osx/tasks/bootstrap.yml @@ -0,0 +1,10 @@ +--- +- name: ensure that Xcode is installed + command: command -v xcodebuild + +- stat: path=/usr/local/bin/brew + register: brew + ignore_errors: True +- name: install homebrew + shell: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + when: brew.stat.exists == False diff --git a/ansible/roles/osx/tasks/casks.yml b/ansible/roles/osx/tasks/casks.yml index 7859ae4..d63eb06 100644 --- a/ansible/roles/osx/tasks/casks.yml +++ b/ansible/roles/osx/tasks/casks.yml @@ -1,11 +1,11 @@ --- - include_vars: casks.yml + - file: path={{ ansible_env.HOME }}/Applications state=directory + # - homebrew: name=caskroom/cask/brew-cask state=upgraded - homebrew_tap: name=caskroom/cask state=present - homebrew: name=brew-cask state=present + - homebrew_cask: name={{ item }} state=installed with_items: casks -- command: defaults write {{ item }} - with_items: - - com.google.Chrome AppleEnableSwipeNavigateWithScrolls -bool false diff --git a/ansible/roles/osx/tasks/defaults.yml b/ansible/roles/osx/tasks/defaults.yml index 3006827..5e01175 100644 --- a/ansible/roles/osx/tasks/defaults.yml +++ b/ansible/roles/osx/tasks/defaults.yml @@ -1,9 +1,9 @@ --- - include_vars: defaults.yml -# - command: defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -int 1 -# sudo: True + - command: defaults write {{ item }} with_items: osx_defaults + - command: defaults -currentHost write NSGlobalDomain com.apple.mouse.tapBehavior -bool true # tap to click # - command: defaults write {{ item }} dontAutoLoad -array # /System/Library/CoreServices/Menu Extras/TimeMachine.menu @@ -15,6 +15,7 @@ # - Set :DesktopViewSettings:IconViewSettings:arrangeBy grid # - Set :FK_StandardViewSettings:IconViewSettings:arrangeBy grid # - Set :StandardViewSettings:IconViewSettings:arrangeBy grid + - command: killall {{ item }} with_items: - Finder diff --git a/ansible/roles/osx/tasks/dock.yml b/ansible/roles/osx/tasks/dock.yml index c545683..ce20fbd 100644 --- a/ansible/roles/osx/tasks/dock.yml +++ b/ansible/roles/osx/tasks/dock.yml @@ -1,7 +1,7 @@ --- - homebrew: name=dockutil state=present -- command: dockutil --remove all -- command: dockutil --add ~/Downloads --view list +- command: /usr/local/bin/dockutil --remove all +- command: /usr/local/bin/dockutil --add ~/Downloads --view list --display stack --sort datemodified - homebrew: name=dockutil state=absent diff --git a/ansible/roles/osx/tasks/fonts.yml b/ansible/roles/osx/tasks/fonts.yml index 9679213..ed3bc52 100644 --- a/ansible/roles/osx/tasks/fonts.yml +++ b/ansible/roles/osx/tasks/fonts.yml @@ -1,5 +1,7 @@ --- - include_vars: fonts.yml + - homebrew_tap: tap=caskroom/fonts state=present + - homebrew_cask: name={{ item }} state=installed with_items: fonts diff --git a/ansible/roles/osx/tasks/formulae.yml b/ansible/roles/osx/tasks/formulae.yml index a720ecc..397dbf1 100644 --- a/ansible/roles/osx/tasks/formulae.yml +++ b/ansible/roles/osx/tasks/formulae.yml @@ -1,6 +1,8 @@ --- - include_vars: formulae.yml -- homebrew: name={{ item }} state=present +- homebrew: + name: "{{ item.name }}" + install_options: "{{ item.install_options | default(omit) }}" + state: present with_items: formulae -- homebrew: name=macvim install_options=override-system-vim state=present -- command: brew linkapps +- command: /usr/local/bin/brew linkapps diff --git a/ansible/roles/osx/tasks/main.yml b/ansible/roles/osx/tasks/main.yml index 1825825..ba3b688 100644 --- a/ansible/roles/osx/tasks/main.yml +++ b/ansible/roles/osx/tasks/main.yml @@ -1,11 +1,14 @@ --- -- homebrew: update_homebrew=yes +- include: bootstrap.yml - include: formulae.yml - include: dock.yml - include: casks.yml - include: fonts.yml - include: defaults.yml -- file: path=~/Library/KeyBindings state=directory -- copy: src=.tmux.conf.local dest=~/.tmux.conf.local -- copy: src=DefaultKeyBinding.dict dest=~/Library/KeyBindings/DefaultKeyBinding.dict -- command: open ~/.dotfiles/Alpha.terminal + +# - copy: src=.tmux.conf.local dest=~/.tmux.conf.local + +# - file: path=~/Library/KeyBindings state=directory +# - copy: src=DefaultKeyBinding.dict dest=~/Library/KeyBindings/DefaultKeyBinding.dict + +# - command: open ~/.dotfiles/Alpha.terminal diff --git a/ansible/roles/osx/vars/casks.yml b/ansible/roles/osx/vars/casks.yml index da903e5..88b11f7 100644 --- a/ansible/roles/osx/vars/casks.yml +++ b/ansible/roles/osx/vars/casks.yml @@ -1,5 +1,6 @@ --- casks: + - 1password - adium - alfred - bittorrent-sync @@ -11,7 +12,6 @@ casks: - google-chrome - mailbox - moom - - onepassword - plug - qlmarkdown - qlstephen diff --git a/ansible/roles/osx/vars/defaults.yml b/ansible/roles/osx/vars/defaults.yml index f7e1fca..185e35e 100644 --- a/ansible/roles/osx/vars/defaults.yml +++ b/ansible/roles/osx/vars/defaults.yml @@ -1,5 +1,8 @@ --- -osx_defaults: # named osx_defaults since there's an Ansible conflict w/defaults +osx_defaults: + # This is named `osx_defaults` since there's an Ansible conflict when this key + # is named just `defaults`. + - -g NSDisableAutomaticTermination -bool true # Don't quit idle applications - NSGlobalDomain AppleFontSmoothing -int 2 # subpixel rendering on non-Apple LCDs @@ -19,9 +22,6 @@ osx_defaults: # named osx_defaults since there's an Ansible conflict w/defaults - com.apple.dock mineffect -string scale # minimize windows using the scale effect - com.apple.dock mru-spaces -bool false # don't rearrange spaces - com.apple.dock orientation -string left - # - com.apple.dock pinning -string start # don't center the dock - # - com.apple.dock showhidden -bool true # translucent icons for hidden apps - # - com.apple.dock workspaces-auto-swoosh -bool false # don't switch to a space w/open windows for the app - com.apple.dock wvous-bl-corner -int 10 # set the bottom left hot corner to sleep the display - com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool true - com.apple.driver.AppleBluetoothMultitouch.trackpad DragLock -int 1 @@ -30,17 +30,9 @@ osx_defaults: # named osx_defaults since there's an Ansible conflict w/defaults - com.apple.finder FXEnableExtensionChangeWarning -bool false # don't ask when changing file extension - com.apple.finder FXPreferredViewStyle -string Nlsv # default to list view - com.apple.finder QLEnableTextSelection -bool true # enable text selection in QuickLook - # - com.apple.finder ShowPathbar -bool true # show path bar - # - com.apple.finder ShowStatusBar -bool true # show status bar - com.apple.finder _FXShowPosixPathInTitle -bool true # show full path in Finder - # - com.apple.gamed Disabled -bool true - # - com.apple.iTunes NSUserKeyEquivalents -dict-add "Target Search Field" "@F" # remap cmd+f to find in iTunes - # - com.apple.iTunes invertStoreLinks -bool true - com.apple.screencapture disable-shadow -bool true # no window shadows when capturing windows - com.apple.screencapture location ~/Downloads - com.apple.screensaver askForPassword -int 1 - # - com.apple.systemuiserver menuExtras -array - # "/System/Library/CoreServices/Menu Extras/AirPort.menu" - # "/System/Library/CoreServices/Menu Extras/Volume.menu" - # "/System/Library/CoreServices/Menu Extras/Clock.menu" - # - com.apple.terminal StringEncodings -array 4 # UTF-8 in Terminal + + - com.google.Chrome AppleEnableSwipeNavigateWithScrolls -bool false diff --git a/ansible/roles/osx/vars/formulae.yml b/ansible/roles/osx/vars/formulae.yml index db632bf..1b49fa1 100644 --- a/ansible/roles/osx/vars/formulae.yml +++ b/ansible/roles/osx/vars/formulae.yml @@ -1,16 +1,16 @@ --- formulae: - - chruby - - ctags - - direnv - - fasd - - git - - hub - # - macvim # Needs install_options=override-system-vim - - ruby-install - - reattach-to-user-namespace - - the_silver_searcher - - tmux - - tree - - youtube-dl - - zsh + - name: chruby + - name: ctags + - name: direnv + - name: fasd + - name: git + - name: macvim + install_options: override-system-vim + - name: ruby-install + - name: reattach-to-user-namespace + - name: the_silver_searcher + - name: tmux + - name: tree + - name: youtube-dl + - name: zsh