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

[PR #8711/132faeae backport][stable-9] gconftool2: minor refactor (#8717)

gconftool2: minor refactor (#8711)

* gconftool2: minor refactor

* add changelog frag

(cherry picked from commit 132faeae34)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2024-08-05 22:16:15 +02:00 committed by GitHub
parent 569bd30148
commit 63eca8e68c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 8 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- gconftool2 - make use of ``ModuleHelper`` features to simplify code (https://github.com/ansible-collections/community.general/pull/8711).

View file

@ -127,9 +127,8 @@ class GConftool(StateModuleHelper):
def __init_module__(self):
self.runner = gconftool2_runner(self.module, check_rc=True)
if self.vars.state != "get":
if not self.vars.direct and self.vars.config_source is not None:
self.module.fail_json(msg='If the "config_source" is specified then "direct" must be "true"')
if not self.vars.direct and self.vars.config_source is not None:
self.do_raise('If the "config_source" is specified then "direct" must be "true"')
self.vars.set('previous_value', self._get(), fact=True)
self.vars.set('value_type', self.vars.value_type)
@ -140,7 +139,7 @@ class GConftool(StateModuleHelper):
def _make_process(self, fail_on_err):
def process(rc, out, err):
if err and fail_on_err:
self.ansible.fail_json(msg='gconftool-2 failed with error: %s' % (str(err)))
self.do_raise('gconftool-2 failed with error:\n%s' % err.strip())
out = out.rstrip()
self.vars.value = None if out == "" else out
return self.vars.value
@ -152,16 +151,14 @@ class GConftool(StateModuleHelper):
def state_absent(self):
with self.runner("state key", output_process=self._make_process(False)) as ctx:
ctx.run()
if self.verbosity >= 4:
self.vars.run_info = ctx.run_info
self.vars.set('run_info', ctx.run_info, verbosity=4)
self.vars.set('new_value', None, fact=True)
self.vars._value = None
def state_present(self):
with self.runner("direct config_source value_type state key value", output_process=self._make_process(True)) as ctx:
ctx.run()
if self.verbosity >= 4:
self.vars.run_info = ctx.run_info
self.vars.set('run_info', ctx.run_info, verbosity=4)
self.vars.set('new_value', self._get(), fact=True)
self.vars._value = self.vars.new_value