gconftool2: fix change output (#6270)

* gconftool2: fix change output

* add changelog frag

* gconftool2: improve visibility on the output

* fix obtaining updated value after `set`

* use issue URL in the changelog fragment

* fix further issues

* fix return value docs + changelog frag

* Update plugins/modules/gconftool2.py

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

* fix return value doc

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Alexei Znamensky 2023-05-04 08:45:35 +12:00 committed by GitHub
parent d254372d37
commit 3c20261264
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 134 additions and 15 deletions

View file

@ -35,12 +35,13 @@ options:
type: str
description:
- Preference keys typically have simple values such as strings,
integers, or lists of strings and integers. This is ignored if the state
is "get". See man gconftool-2(1).
integers, or lists of strings and integers.
This is ignored unless I(state=present). See man gconftool-2(1).
value_type:
type: str
description:
- The type of value being set. This is ignored if the state is "get".
- The type of value being set.
This is ignored unless I(state=present). See man gconftool-2(1).
choices: [ bool, float, int, string ]
state:
type: str
@ -56,8 +57,8 @@ options:
See man gconftool-2(1).
direct:
description:
- Access the config database directly, bypassing server. If direct is
specified then the config_source must be specified as well.
- Access the config database directly, bypassing server. If I(direct) is
specified then the I(config_source) must be specified as well.
See man gconftool-2(1).
type: bool
default: false
@ -73,17 +74,26 @@ EXAMPLES = """
RETURN = '''
key:
description: The key specified in the module parameters
description: The key specified in the module parameters.
returned: success
type: str
sample: /desktop/gnome/interface/font_name
value_type:
description: The type of the value that was changed
description: The type of the value that was changed.
returned: success
type: str
sample: string
value:
description: The value of the preference key after executing the module
description:
- The value of the preference key after executing the module or C(null) if key is removed.
- From community.general 7.0.0 onwards it returns C(null) for a non-existent I(key), and returns C("") before that.
returned: success
type: str
sample: "Serif 12"
previous_value:
description:
- The value of the preference key before executing the module.
- From community.general 7.0.0 onwards it returns C(null) for a non-existent I(key), and returns C("") before that.
returned: success
type: str
sample: "Serif 12"
@ -95,7 +105,6 @@ from ansible_collections.community.general.plugins.module_utils.gconftool2 impor
class GConftool(StateModuleHelper):
change_params = ('value', )
diff_params = ('value', )
output_params = ('key', 'value_type')
facts_params = ('key', 'value_type')
@ -111,7 +120,6 @@ class GConftool(StateModuleHelper):
),
required_if=[
('state', 'present', ['value', 'value_type']),
('state', 'absent', ['value']),
('direct', True, ['config_source']),
],
supports_check_mode=True,
@ -125,6 +133,7 @@ class GConftool(StateModuleHelper):
self.vars.set('previous_value', self._get(), fact=True)
self.vars.set('value_type', self.vars.value_type)
self.vars.set('_value', self.vars.previous_value, output=False, change=True)
self.vars.set_meta('value', initial_value=self.vars.previous_value)
self.vars.set('playbook_value', self.vars.value, fact=True)
@ -132,7 +141,8 @@ class GConftool(StateModuleHelper):
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.vars.value = out.rstrip()
out = out.rstrip()
self.vars.value = None if out == "" else out
return self.vars.value
return process
@ -148,11 +158,18 @@ 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('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:
self.vars.set('new_value', ctx.run(), fact=True)
ctx.run()
if self.verbosity >= 4:
self.vars.run_info = ctx.run_info
self.vars.set('new_value', self._get(), fact=True)
self.vars._value = self.vars.new_value
def main():