mac-dev-playbook
mac-dev-playbook copied to clipboard
Use osx_defaults module for part of .osx provisioning
I found it very weird that many people who provision their Macs using Ansible still use a bash script (the .osx
dotfile) to set some settings.
That's why I started looking into converting all of that into Ansible tasks, because replacing all bash scripts with Ansible seems to be a good thing to do.
At the moment this change allows to move all defaults
commands from the .osx
script to the config.yml
for this playbook. Other parts of the .osx
script will be harder to implement, because I did not find readily usable roles or modules for those yet.
This Task is configured by the variable osx_defaults
and activated by setting osx_use_defaults
to true
. I have also added osx_use_dotfile
to determine if the .osx
script should be run. The default behaviour of the playbook should not have changed. So if you merge this and don't touch your custom config, everything should be the same as before.
The osx_defaults
variable is a list of defaults that can be directly transcribed from the defaults
command used in many .osx
scripts, for example:
defaults write NSGlobalDomain AppleInterfaceStyle -string "Dark"
becomes
osx_defaults:
- { domain: NSGlobalDomain, key: AppleInterfaceStyle, type: string, value: Dark }
Feel free to propose changes do this, including ideas about how to implement the commands pmset
, launchctl
and tmutil
via Ansible.
This pull request has been marked 'stale' due to lack of recent activity. If there is no further activity, the PR will be closed in another 30 days. Thank you for your contribution!
Please read this blog post to see the reasons why I mark pull requests as stale.
This pull request is no longer marked for closure.
Thanks! This is much cleaner than the .osx-style defaults settings.
The biggest limitation I see with using the osx_defaults module is that it does not support the dict
, even less so nested dict of dicts
(ansible/ansible/issues/24028) which are required in some cases. The defaults
command doesn't either: apps access these settings through the native *Kit frameworks, and for shell access the only way I have been able to discover is the OS-bundled PlistBuddy
.
Here's how I set default window size for the builtin Pro
terminal theme:
- name: 'Enable Opt-(left, right, backspace) as Meta-key and other Terminal.app defaults'
command: '/usr/libexec/PlistBuddy -c "{{ item }}" $HOME/Library/Preferences/com.apple.Terminal.plist'
loop:
- "set 'Startup Window Settings' Pro"
- "set 'Default Window Settings' Pro"
- 'set :Window\ Settings:Pro:useOptionAsMetaKey true'
- 'set :Window\ Settings:Pro:columnCount 120'
- 'set :Window\ Settings:Pro:rowCount 30'