Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use osx_defaults module for part of .osx provisioning #79

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

CherryKitten
Copy link

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.

CherryKitten added 5 commits November 22, 2019 14:49
@stale
Copy link

stale bot commented Mar 6, 2020

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.

@stale stale bot added the stale label Mar 6, 2020
@stale
Copy link

stale bot commented Mar 28, 2020

This pull request is no longer marked for closure.

@stale stale bot removed the stale label Mar 28, 2020
@geerlingguy
Copy link
Owner

Thanks! This is much cleaner than the .osx-style defaults settings.

StephenBrown2 added a commit to StephenBrown2/mac-dev-playbook that referenced this pull request Apr 22, 2021
Include dockutil: geerlingguy#106
Include bootstrap from geerlingguy#96 (comment)
Use osx_defaults module: geerlingguy#79
@cbrunnkvist
Copy link

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants