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:
parent
569bd30148
commit
63eca8e68c
2 changed files with 7 additions and 8 deletions
2
changelogs/fragments/8711-gconftool2-refactor.yml
Normal file
2
changelogs/fragments/8711-gconftool2-refactor.yml
Normal 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).
|
|
@ -127,9 +127,8 @@ class GConftool(StateModuleHelper):
|
||||||
|
|
||||||
def __init_module__(self):
|
def __init_module__(self):
|
||||||
self.runner = gconftool2_runner(self.module, check_rc=True)
|
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:
|
||||||
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.module.fail_json(msg='If the "config_source" is specified then "direct" must be "true"')
|
|
||||||
|
|
||||||
self.vars.set('previous_value', self._get(), fact=True)
|
self.vars.set('previous_value', self._get(), fact=True)
|
||||||
self.vars.set('value_type', self.vars.value_type)
|
self.vars.set('value_type', self.vars.value_type)
|
||||||
|
@ -140,7 +139,7 @@ class GConftool(StateModuleHelper):
|
||||||
def _make_process(self, fail_on_err):
|
def _make_process(self, fail_on_err):
|
||||||
def process(rc, out, err):
|
def process(rc, out, err):
|
||||||
if err and fail_on_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()
|
out = out.rstrip()
|
||||||
self.vars.value = None if out == "" else out
|
self.vars.value = None if out == "" else out
|
||||||
return self.vars.value
|
return self.vars.value
|
||||||
|
@ -152,16 +151,14 @@ class GConftool(StateModuleHelper):
|
||||||
def state_absent(self):
|
def state_absent(self):
|
||||||
with self.runner("state key", output_process=self._make_process(False)) as ctx:
|
with self.runner("state key", output_process=self._make_process(False)) as ctx:
|
||||||
ctx.run()
|
ctx.run()
|
||||||
if self.verbosity >= 4:
|
self.vars.set('run_info', ctx.run_info, verbosity=4)
|
||||||
self.vars.run_info = ctx.run_info
|
|
||||||
self.vars.set('new_value', None, fact=True)
|
self.vars.set('new_value', None, fact=True)
|
||||||
self.vars._value = None
|
self.vars._value = None
|
||||||
|
|
||||||
def state_present(self):
|
def state_present(self):
|
||||||
with self.runner("direct config_source value_type state key value", output_process=self._make_process(True)) as ctx:
|
with self.runner("direct config_source value_type state key value", output_process=self._make_process(True)) as ctx:
|
||||||
ctx.run()
|
ctx.run()
|
||||||
if self.verbosity >= 4:
|
self.vars.set('run_info', ctx.run_info, verbosity=4)
|
||||||
self.vars.run_info = ctx.run_info
|
|
||||||
self.vars.set('new_value', self._get(), fact=True)
|
self.vars.set('new_value', self._get(), fact=True)
|
||||||
self.vars._value = self.vars.new_value
|
self.vars._value = self.vars.new_value
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue