mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
[PR #9226/b429e8a2 backport][stable-10] xfconf/xfconf_info: add return value version (#9359)
xfconf/xfconf_info: add return value version (#9226)
* xfconf/xfconf_info: add return value version
* add changelog frag
* adapt test to helper improvements
* rollback copyright update
* replace tab with spaces in test yamls
(cherry picked from commit b429e8a2cf
)
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
parent
12f2d71950
commit
92e4bd184d
6 changed files with 121 additions and 21 deletions
|
@ -7,10 +7,10 @@ from __future__ import absolute_import, division, print_function
|
|||
__metaclass__ = type
|
||||
|
||||
from ansible.module_utils.parsing.convert_bool import boolean
|
||||
from ansible_collections.community.general.plugins.module_utils.cmd_runner import CmdRunner, cmd_runner_fmt as fmt
|
||||
from ansible_collections.community.general.plugins.module_utils.cmd_runner import CmdRunner, cmd_runner_fmt
|
||||
|
||||
|
||||
@fmt.unpack_args
|
||||
@cmd_runner_fmt.unpack_args
|
||||
def _values_fmt(values, value_types):
|
||||
result = []
|
||||
for value, value_type in zip(values, value_types):
|
||||
|
@ -25,14 +25,21 @@ def xfconf_runner(module, **kwargs):
|
|||
module,
|
||||
command='xfconf-query',
|
||||
arg_formats=dict(
|
||||
channel=fmt.as_opt_val("--channel"),
|
||||
property=fmt.as_opt_val("--property"),
|
||||
force_array=fmt.as_bool("--force-array"),
|
||||
reset=fmt.as_bool("--reset"),
|
||||
create=fmt.as_bool("--create"),
|
||||
list_arg=fmt.as_bool("--list"),
|
||||
values_and_types=fmt.as_func(_values_fmt),
|
||||
channel=cmd_runner_fmt.as_opt_val("--channel"),
|
||||
property=cmd_runner_fmt.as_opt_val("--property"),
|
||||
force_array=cmd_runner_fmt.as_bool("--force-array"),
|
||||
reset=cmd_runner_fmt.as_bool("--reset"),
|
||||
create=cmd_runner_fmt.as_bool("--create"),
|
||||
list_arg=cmd_runner_fmt.as_bool("--list"),
|
||||
values_and_types=_values_fmt,
|
||||
version=cmd_runner_fmt.as_fixed("--version"),
|
||||
),
|
||||
**kwargs
|
||||
)
|
||||
return runner
|
||||
|
||||
|
||||
def get_xfconf_version(runner):
|
||||
with runner("version") as ctx:
|
||||
rc, out, err = ctx.run()
|
||||
return out.splitlines()[0].split()[1]
|
||||
|
|
|
@ -153,10 +153,17 @@ cmd:
|
|||
- string
|
||||
- --set
|
||||
- Pacific/Auckland
|
||||
version:
|
||||
description:
|
||||
- The version of the C(xfconf-query) command.
|
||||
returned: success
|
||||
type: str
|
||||
sample: 4.18.1
|
||||
version_added: 10.2.0
|
||||
"""
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.module_helper import StateModuleHelper
|
||||
from ansible_collections.community.general.plugins.module_utils.xfconf import xfconf_runner
|
||||
from ansible_collections.community.general.plugins.module_utils.xfconf import xfconf_runner, get_xfconf_version
|
||||
|
||||
|
||||
class XFConfProperty(StateModuleHelper):
|
||||
|
@ -183,8 +190,8 @@ class XFConfProperty(StateModuleHelper):
|
|||
|
||||
def __init_module__(self):
|
||||
self.runner = xfconf_runner(self.module)
|
||||
self.does_not = 'Property "{0}" does not exist on channel "{1}".'.format(self.vars.property,
|
||||
self.vars.channel)
|
||||
self.vars.version = get_xfconf_version(self.runner)
|
||||
self.does_not = 'Property "{0}" does not exist on channel "{1}".'.format(self.vars.property, self.vars.channel)
|
||||
self.vars.set('previous_value', self._get())
|
||||
self.vars.set('type', self.vars.value_type)
|
||||
self.vars.set_meta('value', initial_value=self.vars.previous_value)
|
||||
|
@ -213,8 +220,7 @@ class XFConfProperty(StateModuleHelper):
|
|||
self.vars.stdout = ctx.results_out
|
||||
self.vars.stderr = ctx.results_err
|
||||
self.vars.cmd = ctx.cmd
|
||||
if self.verbosity >= 4:
|
||||
self.vars.run_info = ctx.run_info
|
||||
self.vars.set("run_info", ctx.run_info, verbosity=4)
|
||||
self.vars.value = None
|
||||
|
||||
def state_present(self):
|
||||
|
@ -244,8 +250,7 @@ class XFConfProperty(StateModuleHelper):
|
|||
self.vars.stdout = ctx.results_out
|
||||
self.vars.stderr = ctx.results_err
|
||||
self.vars.cmd = ctx.cmd
|
||||
if self.verbosity >= 4:
|
||||
self.vars.run_info = ctx.run_info
|
||||
self.vars.set("run_info", ctx.run_info, verbosity=4)
|
||||
|
||||
if not self.vars.is_array:
|
||||
self.vars.value = self.vars.value[0]
|
||||
|
|
|
@ -118,10 +118,17 @@ value_array:
|
|||
- Main
|
||||
- Work
|
||||
- Tmp
|
||||
version:
|
||||
description:
|
||||
- The version of the C(xfconf-query) command.
|
||||
returned: success
|
||||
type: str
|
||||
sample: 4.18.1
|
||||
version_added: 10.2.0
|
||||
"""
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.module_helper import ModuleHelper
|
||||
from ansible_collections.community.general.plugins.module_utils.xfconf import xfconf_runner
|
||||
from ansible_collections.community.general.plugins.module_utils.xfconf import xfconf_runner, get_xfconf_version
|
||||
|
||||
|
||||
class XFConfInfo(ModuleHelper):
|
||||
|
@ -139,6 +146,7 @@ class XFConfInfo(ModuleHelper):
|
|||
|
||||
def __init_module__(self):
|
||||
self.runner = xfconf_runner(self.module, check_rc=True)
|
||||
self.vars.version = get_xfconf_version(self.runner)
|
||||
self.vars.set("list_arg", False, output=False)
|
||||
self.vars.set("is_array", False)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue