community.general.osx_defaults (8.5.0) — module

Manage macOS user defaults

Authors: Franck Nijhof (!UNKNOWN)

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

osx_defaults allows users to read, write, and delete macOS user defaults from Ansible scripts.

macOS applications and other programs use the defaults system to record user preferences and other information that must be maintained when the applications are not running (such as default font for new documents, or the position of an Info panel).

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Set boolean valued key for application domain
  community.general.osx_defaults:
    domain: com.apple.Safari
    key: IncludeInternalDebugMenu
    type: bool
    value: true
    state: present
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Set string valued key for global domain
  community.general.osx_defaults:
    domain: NSGlobalDomain
    key: AppleMeasurementUnits
    type: string
    value: Centimeters
    state: present
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Set int valued key for arbitrary plist
  community.general.osx_defaults:
    domain: /Library/Preferences/com.apple.SoftwareUpdate
    key: AutomaticCheckEnabled
    type: int
    value: 1
  become: true
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Set int valued key only for the current host
  community.general.osx_defaults:
    domain: com.apple.screensaver
    host: currentHost
    key: showClock
    type: int
    value: 1
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Defaults to global domain and setting value
  community.general.osx_defaults:
    key: AppleMeasurementUnits
    type: string
    value: Centimeters
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Setting an array valued key
  community.general.osx_defaults:
    key: AppleLanguages
    type: array
    value:
      - en
      - nl
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Removing a key
  community.general.osx_defaults:
    domain: com.geekchimp.macable
    key: ExampleKeyToRemove
    state: absent

Inputs

    
key:
    description:
    - The key of the user preference.
    type: str

host:
    description:
    - The host on which the preference should apply.
    - The special value V(currentHost) corresponds to the C(-currentHost) switch of the
      defaults commandline tool.
    type: str

path:
    default: /usr/bin:/usr/local/bin
    description:
    - The path in which to search for C(defaults).
    type: str

type:
    choices:
    - array
    - bool
    - boolean
    - date
    - float
    - int
    - integer
    - string
    default: string
    description:
    - The type of value to write.
    type: str

state:
    choices:
    - absent
    - list
    - present
    default: present
    description:
    - The state of the user defaults.
    - If set to V(list) will query the given parameter specified by O(key). Returns V(null)
      is nothing found or mis-spelled.
    type: str

value:
    description:
    - The value to write.
    - Only required when O(state=present).
    type: raw

domain:
    default: NSGlobalDomain
    description:
    - The domain is a domain name of the form C(com.companyname.appname).
    type: str

array_add:
    default: false
    description:
    - Add new elements to the array for a key which has an array as its value.
    type: bool