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

[PR #6336/59cb5b2d backport][stable-6] dconf: minor refactor (#6353)

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>
(cherry picked from commit 59cb5b2d6f)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2023-04-17 04:05:24 +00:00 committed by GitHub
parent 7e7b84348b
commit ea8f109056
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 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:
from gi.repository.GLib import Variant, GError
@ -151,16 +154,8 @@ except ImportError:
Variant = None
GError = AttributeError
PSUTIL_IMP_ERR = None
try:
with deps.declare("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):
@ -414,7 +409,10 @@ def main():
# Converted to str below after special handling of bool.
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
@ -435,12 +433,7 @@ def main():
'using string comparison to check value equality. This fallback '
'will be deprecated in a future version of community.general.')
if not HAS_PSUTIL:
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.')
deps.validate(module)
# Create wrapper instance.
dconf = DconfPreference(module, module.check_mode)