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:
parent
7e7b84348b
commit
ea8f109056
2 changed files with 12 additions and 17 deletions
2
changelogs/fragments/6336-dconf-refactor.yml
Normal file
2
changelogs/fragments/6336-dconf-refactor.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- dconf - minor refactoring improving parameters and dependencies validation (https://github.com/ansible-collections/community.general/pull/6336).
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue