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

community.general.osx_defaults: Include stderr in error messages #6011

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/6011-osx-defaults-errors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
josephshanak marked this conversation as resolved.
Show resolved Hide resolved
- "osx_defaults - include stderr in error messages (https://github.com/ansible-collections/community.general/pull/6011)."
19 changes: 12 additions & 7 deletions plugins/modules/osx_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,48 +71,53 @@
'''

EXAMPLES = r'''
# TODO: Describe what happens in each example

# Set Boolean Valued Key for Application Domain
- community.general.osx_defaults:
josephshanak marked this conversation as resolved.
Show resolved Hide resolved
domain: com.apple.Safari
key: IncludeInternalDebugMenu
type: bool
value: true
state: present

# Set String Valued Key for Global Domain
- community.general.osx_defaults:
domain: NSGlobalDomain
key: AppleMeasurementUnits
type: string
value: Centimeters
state: present

# 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

# 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

# Defaults to Global Domain and Setting value
- community.general.osx_defaults:
key: AppleMeasurementUnits
type: string
value: Centimeters

# Setting an Array valued key
- community.general.osx_defaults:
key: AppleLanguages
type: array
value:
- en
- nl

# Removing a key
- community.general.osx_defaults:
josephshanak marked this conversation as resolved.
Show resolved Hide resolved
domain: com.geekchimp.macable
key: ExampleKeyToRemove
Expand Down Expand Up @@ -257,7 +262,7 @@ def read(self):

# If the RC is not 0, then terrible happened! Ooooh nooo!
if rc != 0:
raise OSXDefaultsException("An error occurred while reading key type from defaults: %s" % out)
raise OSXDefaultsException("An error occurred while reading key type from defaults: %s" % err)

# Ok, lets parse the type from output
data_type = out.strip().replace('Type is ', '')
Expand All @@ -268,9 +273,9 @@ def read(self):
# Strip output
out = out.strip()

# An non zero RC at this point is kinda strange...
# A non zero RC at this point is kinda strange...
if rc != 0:
raise OSXDefaultsException("An error occurred while reading key value from defaults: %s" % out)
raise OSXDefaultsException("An error occurred while reading key value from defaults: %s" % err)

# Convert string to list when type is array
if data_type == "array":
Expand Down Expand Up @@ -308,13 +313,13 @@ def write(self):
expand_user_and_vars=False)

if rc != 0:
raise OSXDefaultsException('An error occurred while writing value to defaults: %s' % out)
raise OSXDefaultsException('An error occurred while writing value to defaults: %s' % err)

def delete(self):
""" Deletes defaults key from domain """
rc, out, err = self.module.run_command(self._base_command() + ['delete', self.domain, self.key])
if rc != 0:
raise OSXDefaultsException("An error occurred while deleting key from defaults: %s" % out)
raise OSXDefaultsException("An error occurred while deleting key from defaults: %s" % err)

# /commands ----------------------------------------------------------- }}}

Expand Down