Skip to content

Commit

Permalink
Feature: macOS config (#7)
Browse files Browse the repository at this point in the history
Adding support for
* system config
* user config
* optionally download localhost.yml
  • Loading branch information
DrPsychick authored May 22, 2022
1 parent fe4f04e commit 3964522
Show file tree
Hide file tree
Showing 10 changed files with 451 additions and 29 deletions.
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@ I hate it when I need to setup a computer from scratch, but from time to time I

It is **not** meant to be used for linux or windows environments and **not** meant to support setting up a remote host. It's just a tiny helper to automate installing all the tools and software you expect on your local machine.

**compare with** https://github.com/geerlingguy/mac-dev-playbook as it may make this repo obsolete.
**Much simpler than** https://github.com/geerlingguy/mac-dev-playbook, but obviously not as sophisticated.

## features
* system configuration (`sudo defaults write XXX`) - hostname,
* user configuration (`defaults write XXX`) - dock behaviour, hot corners, finder defaults, ...
* setup the environment (.profile/.zshrc/aliases/...)
* install brew / pip3 packages
* download and install individual apps (zip or dmg)

## ideas/planned features
* [ ] support multiple environments for pip (virtualenv)
* [x] support adding brew casks
* [ ] (maybe) add a flag through which you can force install to update apps (most apps ask to update themselves though)
* [ ] maybe add some OSX setting stuff used here: https://github.com/roberth1988/osx-bootstrap
* optionally use a URL to download the `localhost.yml` configuration

# usage

Expand All @@ -40,13 +37,14 @@ cd macdev
```shell
cp host_vars/localhost-example.yml host_vars/localhost.yml
open -e host_vars/localhost.yml
# replace "YOUR_MACDEV_DIRECTORY" with the directory where the cloned repository resides
```

## run it
`ansible-playbook macdev.yml`

## maintain it
You want to install a new package? Edit your `host_vars/localhost.yml`, then simply run your alias `localdev` (see `host_vars/localhost-example.yml`) or the above command.
You want to install a new package? Edit your `host_vars/localhost.yml`, then simply run your alias `updatemac` (see `host_vars/localhost-example.yml`) or the above command.

## troubleshooting
* if you get this (after updating brew): `/usr/local/bin/ansible-playbook: bad interpreter: /usr/local/opt/python/bin/python3.7: no such file or directory`
Expand Down
45 changes: 44 additions & 1 deletion host_vars/localhost-M1example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,50 @@ role_pip: yes
role_brew: yes
role_app: no

# files and templates:
## system configuration (requires sudo)
system:
# # set ComputerName, HostName and NetBIOS Name
# hostname: example
# sudo systemsetup -help
systemsetup:
# - { key: "-setrestartfreeze", value: "on" }
# - { key: "-setdisplaysleep", value: "10" }
loginwindow:
# - { key: "AdminHostInfo", value: "HostName" }
# - { key: "GuestEnabled", value: "0" }
generic:
# - { domain: "/Library/Preferences/com.apple.loginwindow", key: "AdminHostInfo", string: "HostName" }
# - { domain: "/Library/Preferences/com.apple.loginwindow", key: "GuestEnabled", bool: false }

## user configuration (must be run per user)
config:
# domain = NSGlobalDomain
global:
# - { key: "InitialKeyRepeat", int: 15 }
# - { key: "KeyRepeat", int: 1 }
generic:
# - { domain: "com.apple.desktopservices", key: "DSDontWriteNetworkStores", bool: true }
# domain = com.apple.finder
finder:
# available views: `icnv`, `clmv`, `Flwv`, `Nlsv`
# - { key: "FXPreferredViewStyle", string: "Nlsv" }
# domain = com.apple.dock
dock:
# https://github.com/mathiasbynens/dotfiles/blob/c886e139233320e29fd882960ba3dd388d57afd7/.macos#L356
# - { key: "magnification", int: 1 }
# - { key: "tilesize", int: 32 }
# - { key: "largesize", int: 128 }
# - { key: "autohide", int: 1 }
# - { key: "wvous-tl-corner", int: 5 }
# - { key: "wvous-tl-modifier", int: 0 }
# - { key: "wvous-tr-corner", int: 11 }
# - { key: "wvous-tr-modifier", int: 0 }
# - { key: "wvous-bl-corner", int: 3 }
# - { key: "wvous-bl-modifier", int: 0 }
# - { key: "wvous-br-corner", int: 2 }
# - { key: "wvous-br-modifier", int: 0 }

## user files and templates:
# overwrite: replace file on target, if it exists
# shell: source file in .profile

Expand Down
162 changes: 162 additions & 0 deletions host_vars/localhost-drpsychick-jones.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
---

# roles
role_ssh: yes
role_sys: yes
role_cfg: yes
role_ansible: true
role_pip: yes
role_brew: yes
role_app: no

config_url: "https://raw.githubusercontent.com/DrPsychick/macdev/master/host_vars/localhost-drpsychick-jones.yml"

system:
hostname: jones
# sudo systemsetup -help
systemsetup:
- { key: "-setrestartfreeze", value: "on" }
- { key: "-setdisplaysleep", value: "10" }
# domain = /Library/Preferences/com.apple.loginwindow
loginwindow:
- { key: "AdminHostInfo", value: "HostName" }
- { key: "GuestEnabled", value: "0" }
generic:
- { domain: "/Library/Preferences/com.apple.loginwindow", key: "AdminHostInfo", string: "HostName" }
- { domain: "/Library/Preferences/com.apple.loginwindow", key: "GuestEnabled", bool: false }

config:
# domain = NSGlobalDomain
global:
- { key: "InitialKeyRepeat", int: 20 }
- { key: "KeyRepeat", int: 1 }
generic:
- { domain: "com.apple.desktopservices", key: "DSDontWriteNetworkStores", bool: true }
- { domain: "com.apple.Safari", key: "IncludeDevelopMenu", bool: true }
- { domain: "com.apple.Safari", key: "WebKitDeveloperExtrasEnabledPreferenceKey", bool: true }
- { domain: "com.apple.Safari", key: "com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled", bool: true }
- { domain: "com.apple.gamed", key: "Disabled", bool: true }
# domain = com.apple.finder
finder:
- { key: "FXPreferredViewStyle", string: "Nlsv" }
# domain = com.apple.dock
dock:
- { key: "magnification", bool: true }
- { key: "tilesize", int: 32 }
- { key: "largesize", int: 128 }
- { key: "autohide", bool: true }
- { key: "showhidden", bool: true }
- { key: "wvous-tl-corner", int: 5 }
- { key: "wvous-tl-modifier", int: 0 }
- { key: "wvous-tr-corner", int: 11 }
- { key: "wvous-tr-modifier", int: 0 }
- { key: "wvous-bl-corner", int: 3 }
- { key: "wvous-bl-modifier", int: 0 }
- { key: "wvous-br-corner", int: 2 }
- { key: "wvous-br-modifier", int: 0 }
- { key: "expose-animation-duration", float: 0.5 }

## user files and templates:
# overwrite: replace file on target, if it exists
# source: "interactive" or "login"

# files you want to copy to the target
files:
#- { name: "file-example", path: "$HOME/file-example", overwrite: true, shell: false }

# templates you want to copy to the target
templates:
- { name: "myfunctions.sh", path: "$HOME/bin/myfunctions.sh", overwrite: true, source: "interactive" }
- { name: "home-functions.sh", path: "$HOME/bin/home-functions.sh", overwrite: true }
- { name: "finicky.js", path: "$HOME/.finicky.js", overwrite: true }
- { name: "gitconfig", path: "$HOME/.gitconfig", overwrite: true }
- { name: "gitconfig-work", path: "$HOME/.gitconfig-work", overwrite: true }
- { name: "gitconfig-private", path: "$HOME/.gitconfig-private", overwrite: true }

# instead of copying a file or template, you can define aliases one by one
shell_aliases:
- { name: "updatemac", cmd: "(cd ~/work/git/macdev; {{ 'echo \"password for sudo:\"; sudo echo;' if role_sys }} ansible-playbook macdev.yml)" }
- { name: "rancherVM", cmd: 'LIMA_HOME="$HOME/Library/Application Support/rancher-desktop/lima" "/Applications/Rancher Desktop.app/Contents/Resources/resources/darwin/lima/bin/limactl" shell 0' }
- { name: "fixvpn", cmd: "sudo route delete -host 85.190.148.133 192.168.1.200; sudo route add -host 85.190.148.133 192.168.1.200" }

ansible_collections:
- { name: community.general }
# see https://docs.ansible.com/ansible/latest/user_guide/collections_using.html#install-multiple-collections-with-a-requirements-file
- { name: community.docker }
- { name: community.kubernetes } # , version: "", source: "" }

brew_packages:
- { name: gnupg, path: "{{brew_bin}}/gpg" }
- { name: jq, path: "{{brew_bin}}/jq" }
- { name: watch, path: "{{brew_bin}}/watch" }
- { name: gnupg, path: "{{brew_bin}}/gpg" }
#- { name: kubernetes-cli, path: "{{brew_bin}}/kubectl" } # conflicts with Rancher Desktop
#- { name: kubectx, path: "{{brew_bin}}/kubectx" }
#- { name: helm, path: "{{brew_bin}}/helm" } # conflicts with Rancher Desktop
- { name: pinentry-mac, path: "{{brew_bin}}/pinentry-mac" }
- { name: node, path: "{{brew_bin}}/node" }
- { name: telegraf, path: "{{brew_bin}}/telegraf" }
- { name: mtr, path: "{{brew_sbin}}/mtr" }
- { name: smartmontools, path: "{{brew_bin}}/smartctl" }
- { name: glances, path: "{{brew_bin}}/glances" }
- { name: hub, path: "{{brew_bin}}/hub" }
- { name: qemu, path: "{{brew_bin}}/qemu-img" }
- { name: k3d, path: "{{brew_bin}}/k3d" }
- { name: kustomize, path: "{{brew_bin}}/kustomize" }
- { name: kubeval, path: "{{brew_bin}}/kubeval" }
- { name: kubeseal, path: "{{brew_bin}}/kubeseal" }
- { name: pwgen, path: "{{brew_bin}}/pwgen" }
- { name: yamllint, path: "{{brew_bin}}/yamllint" }

brew_cask_packages:
#- { name: docker, path: /Applications/Docker.app }
- { name: iterm2, path: /Applications/iTerm.app }
- { name: google-chrome, path: /Applications/Google Chrome.app }
- { name: atom, path: /Applications/Atom.app }
- { name: slack, path: /Applications/Slack.app }
- { name: macpass, path: /Applications/MacPass.app }
- { name: zoomus, path: /Applications/zoom.us.app }
#- { name: openoffice, path: /Applications/OpenOffice.app }
#- { name: libreoffice, path: "/Applications/LibreOffice.app" }
#- { name: gimp, path: /Applications/Gimp-2.10.app }
#- { name: pycharm-ce, path: "/Applications/PyCharm CE.app" }
- { name: pycharm, path: "/Applications/PyCharm.app" }
- { name: goland, path: "/Applications/GoLand.app" }
- { name: tunnelblick, path: "/Applications/Tunnelblick.app" }
- { name: spectacle, path: "/Applications/Spectacle.app" }
- { name: drawio, path: "/Applications/draw.io.app" }
- { name: postman, path: "/Applications/Postman.app" }
- { name: moonlight, path: "/Applications/Moonlight.app" }
- { name: krita, path: "/Applications/krita.app" }
- { name: spotify, path: "/Applications/Spotify.app" }
- { name: sweet-home3d, path: "/Applications/Sweet Home 3D.app" }
- { name: monitorcontrol, path: "/Applications/MonitorControl.app" }
- { name: macs-fan-control, path: "/Applications/Macs Fan Control.app" }
- { name: qsync-client, path: "/Applications/QSync Client.app" }
- { name: discord, path: "/Applications/Discord.app" }
- { name: google-drive, path: "/Applications/Google Drive.app" }
- { name: vlc, path: "/Applications/VLC.app" }
#- { name: virtualbox, path: "/Applications/VirtualBox.app" }
#- { name: virtualbox-extension-pack, path: "{{ brew_prefix }}/Caskroom/virtualbox-extension-pack/6.1.28/Oracle_VM_VirtualBox_Extension_Pack-6.1.28.vbox-extpack" }
- { name: obsidian, path: "/Applications/Obsidian.app" }
- { name: mindforger, path: "/Applications/mindforger.app" }
- { name: moom, path: "/Applications/Moom.app" }
- { name: obs, path: "/Applications/OBS.app" }
- { name: obs-virtualcam, path: "{{ brew_prefix }}/Caskroom/obs-virtualcam" }
#- { name: qdslrdashboard, path: "/Applications/qDslrDashboard.app" }
- { name: finicky, path: "/Applications/finicky.app" }
- { name: microsoft-teams, path: "/Applications/Microsoft Teams.app" }
- { name: utm, path: "/Applications/UTM.app" }
- { name: minecraft, path: "/Applications/Minecraft.app" }
- { name: curseforge, path: "/Applications/CurseForge.app" }
- { name: rancher, path: "/Applications/Rancher Desktop.app" }
- { name: 1password, path: "/Applications/1Password 7.app" }

pip_packages:
- { name: yamale, path: "{{pip_bin}}/yamale" }
# - { name: kubernetes, path: "/lib/python3.9/site-packages/kubernetes" }
# - { name: ansible, path: /usr/local/bin/ansible }
# - { name: awscli, path: /usr/local/bin/aws }

# supports .zip and .dmg
app_packages:
75 changes: 61 additions & 14 deletions host_vars/localhost-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,82 @@

# roles
role_ssh: yes
# role_sys requires sudo
role_sys: no
role_cfg: no
role_ansible: yes
role_pip: yes
role_pip: no
role_brew: yes
role_app: no

# files and templates:
## system configuration (requires sudo)
system:
# # set ComputerName, HostName and NetBIOS Name
# hostname: example
# sudo systemsetup -help
systemsetup:
# - { key: "-setrestartfreeze", value: "on" }
# - { key: "-setdisplaysleep", value: "10" }
loginwindow:
# - { key: "AdminHostInfo", value: "HostName" } # shows host name and info on login screen
# - { key: "GuestEnabled", value: "0" }
generic:
# - { domain: "/Library/Preferences/com.apple.loginwindow", key: "AdminHostInfo", string: "HostName" }
# - { domain: "/Library/Preferences/com.apple.loginwindow", key: "GuestEnabled", bool: false }

## user configuration (must be run per user)
config:
# domain = NSGlobalDomain
global:
# - { key: "InitialKeyRepeat", int: 15 }
# - { key: "KeyRepeat", int: 1 }
generic:
# - { domain: "com.apple.desktopservices", key: "DSDontWriteNetworkStores", bool: true }
# domain = com.apple.finder
finder:
# available views: `icnv`, `clmv`, `Flwv`, `Nlsv`
- { key: "FXPreferredViewStyle", string: "Nlsv" }
# domain = com.apple.dock
dock:
# https://github.com/mathiasbynens/dotfiles/blob/c886e139233320e29fd882960ba3dd388d57afd7/.macos#L356
# - { key: "magnification", int: 1 }
# - { key: "tilesize", int: 32 }
# - { key: "largesize", int: 128 }
# - { key: "autohide", int: 1 }
# hot corners: tl = top-left, br = bottom-right
# - { key: "wvous-tl-corner", int: 5 }
# - { key: "wvous-tl-modifier", int: 0 }
# - { key: "wvous-tr-corner", int: 11 }
# - { key: "wvous-tr-modifier", int: 0 }
# - { key: "wvous-bl-corner", int: 3 }
# - { key: "wvous-bl-modifier", int: 0 }
# - { key: "wvous-br-corner", int: 2 }
# - { key: "wvous-br-modifier", int: 0 }

## user files and templates:
# overwrite: replace file on target, if it exists
# shell (OBSOLETE): source file in .bashrc/.zshrc
# source=(interactive|login): source file in "interactive" = .bashrc/.zshrc or "login" = .profile/.zprofile
# source=(interactive|login): source file for "interactive" session = .bashrc/.zshrc or "login" session = .profile/.zprofile

# files you want to copy to the target
files:
- { name: "gitconfig-example", path: "$HOME/.gitconfig-example", overwrite: true }
# - { name: "gitconfig-example", path: "$HOME/.gitconfig-example", overwrite: true }

# templates you want to copy to the target
templates:
- { name: "bashrc-example", path: "$HOME/.bashrc-example", overwrite: true }
- { name: "bash_aliases-example", path: "$HOME/.bash_aliases-example", overwrite: true, source: "interactive" }
# - { name: "bashrc-example", path: "$HOME/.bashrc-example", overwrite: true }
# - { name: "bash_aliases-example", path: "$HOME/.bash_aliases-example", overwrite: true, source: "interactive" }

# instead of copying a file or template, you can define aliases one by one
shell_aliases:
- { name: "localdev", cmd: "(cd ~/YOUR_MACDEV_DIRECTORY; ansible-playbook macdev.yml)" }
- { name: "updatemac", cmd: "(cd ~/YOUR_MACDEV_DIRECTORY; {{ 'echo \"password for sudo:\"; sudo echo;' if role_sys }} ansible-playbook macdev.yml)" }

ansible_collections:
- { name: community.general }
# see https://docs.ansible.com/ansible/latest/user_guide/collections_using.html#install-multiple-collections-with-a-requirements-file
#- { name: community.docker, version: "=1.9.0" }
#- { name: community.kubernetes, source: "" }

# TODO: at this time, only ONE user can control brew packages
brew_packages:
- { name: python, path: "{{ brew_bin }}/python3" }
- { name: pwgen, path: "{{ brew_bin }}/pwgen" }
Expand All @@ -54,10 +101,10 @@ brew_packages:
- { name: zsh-autosuggestions, path: /usr/local/share/zsh-autosuggestions }

brew_cask_packages:
- { name: docker, path: /Applications/Docker.app }
- { name: iterm2, path: /Applications/iTerm.app }
- { name: google-chrome, path: /Applications/Google Chrome.app }
- { name: atom, path: /Applications/Atom.app }
#- { name: docker, path: /Applications/Docker.app }
#- { name: atom, path: /Applications/Atom.app }
#- { name: postman, path: /Applications/Postman.app }
#- { name: slack, path: /Applications/Slack.app }
#- { name: macpass, path: /Applications/MacPass.app }
Expand All @@ -71,11 +118,11 @@ brew_cask_packages:
#- { name: moonlight, path: "/Applications/Moonlight.app" }
#- { name: zoom, path: "/Applications/zoom.us.app" }
#- { name: discord, path: "/Applications/Discord.app" }
#- { name: google-backup-and-sync, path: "/Applications/Backup and Sync.app" }
#- { name: google-drive, path: "/Applications/Google Drive.app" }

pip_packages:
- { name: ansible, path: "{{ pip_bin }}/ansible" }
- { name: awscli, path: "{{ pip_bin }}/aws" }
#pip_packages:
# - { name: ansible, path: "{{ pip_bin }}/ansible" }
# - { name: awscli, path: "{{ pip_bin }}/aws" }

# supports .zip and .dmg
app_packages:
Expand Down
Loading

0 comments on commit 3964522

Please sign in to comment.