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

dconf: minor refactor (#6336)

* dconf: minor refactor

* add changelog frag

* Update plugins/modules/dconf.py

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

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Alexei Znamensky 2023-04-17 08:19:26 +12:00 committed by GitHub
parent ee11847c7e
commit 59cb5b2d6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 17 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- dconf - minor refactoring improving parameters and dependencies validation (https://github.com/ansible-collections/community.general/pull/6336).

View file

@ -143,7 +143,10 @@ EXAMPLES = r"""
import os import os
import traceback
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
from ansible_collections.community.general.plugins.module_utils import deps
try: try:
from gi.repository.GLib import Variant, GError from gi.repository.GLib import Variant, GError
@ -151,16 +154,8 @@ except ImportError:
Variant = None Variant = None
GError = AttributeError GError = AttributeError
PSUTIL_IMP_ERR = None with deps.declare("psutil"):
try:
import psutil import psutil
HAS_PSUTIL = True
except ImportError:
PSUTIL_IMP_ERR = traceback.format_exc()
HAS_PSUTIL = False
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
from ansible.module_utils.common.text.converters import to_native
class DBusWrapper(object): class DBusWrapper(object):
@ -414,7 +409,10 @@ def main():
# Converted to str below after special handling of bool. # Converted to str below after special handling of bool.
value=dict(required=False, default=None, type='raw'), value=dict(required=False, default=None, type='raw'),
), ),
supports_check_mode=True supports_check_mode=True,
required_if=[
('state', 'present', ['value']),
],
) )
# Try to be forgiving about the user specifying a boolean as the value, or # Try to be forgiving about the user specifying a boolean as the value, or
@ -435,12 +433,7 @@ def main():
'using string comparison to check value equality. This fallback ' 'using string comparison to check value equality. This fallback '
'will be deprecated in a future version of community.general.') 'will be deprecated in a future version of community.general.')
if not HAS_PSUTIL: deps.validate(module)
module.fail_json(msg=missing_required_lib("psutil"), exception=PSUTIL_IMP_ERR)
# If present state was specified, value must be provided.
if module.params['state'] == 'present' and module.params['value'] is None:
module.fail_json(msg='State "present" requires "value" to be set.')
# Create wrapper instance. # Create wrapper instance.
dconf = DconfPreference(module, module.check_mode) dconf = DconfPreference(module, module.check_mode)