1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

[PR #6011/92544993 backport][stable-6] community.general.osx_defaults: Include stderr in error messages (#6080)

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

* Update osx_defaults documentation examples

* Include stderr in errors from osx_defaults

* Add Changelog Fragment

* Update changelogs/fragments/6011-osx-defaults-errors.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

* Change format of examples

* Update plugins/modules/osx_defaults.py

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 92544993c0)

Co-authored-by: Joseph Shanak <josephshanak@protonmail.com>
This commit is contained in:
patchback[bot] 2023-02-25 11:25:19 +01:00 committed by GitHub
parent b1a711633b
commit 94015c2096
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 14 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- "osx_defaults - include stderr in error messages (https://github.com/ansible-collections/community.general/pull/6011)."

View file

@ -78,49 +78,54 @@ notes:
''' '''
EXAMPLES = r''' EXAMPLES = r'''
# TODO: Describe what happens in each example - name: Set boolean valued key for application domain
community.general.osx_defaults:
- community.general.osx_defaults:
domain: com.apple.Safari domain: com.apple.Safari
key: IncludeInternalDebugMenu key: IncludeInternalDebugMenu
type: bool type: bool
value: true value: true
state: present state: present
- community.general.osx_defaults: - name: Set string valued key for global domain
community.general.osx_defaults:
domain: NSGlobalDomain domain: NSGlobalDomain
key: AppleMeasurementUnits key: AppleMeasurementUnits
type: string type: string
value: Centimeters value: Centimeters
state: present state: present
- community.general.osx_defaults: - name: Set int valued key for arbitrary plist
community.general.osx_defaults:
domain: /Library/Preferences/com.apple.SoftwareUpdate domain: /Library/Preferences/com.apple.SoftwareUpdate
key: AutomaticCheckEnabled key: AutomaticCheckEnabled
type: int type: int
value: 1 value: 1
become: true become: true
- community.general.osx_defaults: - name: Set int valued key only for the current host
community.general.osx_defaults:
domain: com.apple.screensaver domain: com.apple.screensaver
host: currentHost host: currentHost
key: showClock key: showClock
type: int type: int
value: 1 value: 1
- community.general.osx_defaults: - name: Defaults to global domain and setting value
community.general.osx_defaults:
key: AppleMeasurementUnits key: AppleMeasurementUnits
type: string type: string
value: Centimeters value: Centimeters
- community.general.osx_defaults: - name: Setting an array valued key
community.general.osx_defaults:
key: AppleLanguages key: AppleLanguages
type: array type: array
value: value:
- en - en
- nl - nl
- community.general.osx_defaults: - name: Removing a key
community.general.osx_defaults:
domain: com.geekchimp.macable domain: com.geekchimp.macable
key: ExampleKeyToRemove key: ExampleKeyToRemove
state: absent state: absent
@ -264,7 +269,7 @@ class OSXDefaults(object):
# If the RC is not 0, then terrible happened! Ooooh nooo! # If the RC is not 0, then terrible happened! Ooooh nooo!
if rc != 0: 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 # Ok, lets parse the type from output
data_type = out.strip().replace('Type is ', '') data_type = out.strip().replace('Type is ', '')
@ -275,9 +280,9 @@ class OSXDefaults(object):
# Strip output # Strip output
out = out.strip() 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: 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 # Convert string to list when type is array
if data_type == "array": if data_type == "array":
@ -315,13 +320,13 @@ class OSXDefaults(object):
expand_user_and_vars=False) expand_user_and_vars=False)
if rc != 0: 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): def delete(self):
""" Deletes defaults key from domain """ """ Deletes defaults key from domain """
rc, out, err = self.module.run_command(self._base_command() + ['delete', self.domain, self.key]) rc, out, err = self.module.run_command(self._base_command() + ['delete', self.domain, self.key])
if rc != 0: 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 ----------------------------------------------------------- }}} # /commands ----------------------------------------------------------- }}}