2020-03-09 10:11:07 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
2022-08-05 22:12:10 +02:00
|
|
|
# Copyright (c) 2017, Joseph Benden <joe@benden.us>
|
2020-03-09 10:11:07 +01:00
|
|
|
#
|
2022-08-05 12:28:29 +02:00
|
|
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
__metaclass__ = type
|
|
|
|
|
|
|
|
DOCUMENTATION = '''
|
|
|
|
module: xfconf
|
|
|
|
author:
|
2022-04-20 08:24:51 +02:00
|
|
|
- "Joseph Benden (@jbenden)"
|
|
|
|
- "Alexei Znamensky (@russoz)"
|
2020-03-09 10:11:07 +01:00
|
|
|
short_description: Edit XFCE4 Configurations
|
|
|
|
description:
|
2021-07-23 08:17:14 +02:00
|
|
|
- This module allows for the manipulation of Xfce 4 Configuration with the help of
|
2022-11-08 14:03:07 +01:00
|
|
|
xfconf-query. Please see the xfconf-query(1) man page for more details.
|
2022-04-20 08:24:51 +02:00
|
|
|
seealso:
|
2022-11-08 14:03:07 +01:00
|
|
|
- name: xfconf-query(1) man page
|
2022-04-20 08:24:51 +02:00
|
|
|
description: Manual page of the C(xfconf-query) tool at the XFCE documentation site.
|
|
|
|
link: 'https://docs.xfce.org/xfce/xfconf/xfconf-query'
|
|
|
|
|
|
|
|
- name: xfconf - Configuration Storage System
|
|
|
|
description: XFCE documentation for the Xfconf configuration system.
|
|
|
|
link: 'https://docs.xfce.org/xfce/xfconf/start'
|
|
|
|
|
2023-02-20 17:28:47 +01:00
|
|
|
extends_documentation_fragment:
|
|
|
|
- community.general.attributes
|
|
|
|
|
|
|
|
attributes:
|
|
|
|
check_mode:
|
|
|
|
support: full
|
|
|
|
diff_mode:
|
|
|
|
support: full
|
|
|
|
|
2020-03-09 10:11:07 +01:00
|
|
|
options:
|
|
|
|
channel:
|
|
|
|
description:
|
2022-04-20 08:24:51 +02:00
|
|
|
- A Xfconf preference channel is a top-level tree key, inside of the
|
|
|
|
Xfconf repository that corresponds to the location for which all
|
2022-04-26 11:45:15 +02:00
|
|
|
application properties/keys are stored. See man xfconf-query(1).
|
2022-04-20 08:24:51 +02:00
|
|
|
required: true
|
2020-07-25 12:58:14 +02:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
property:
|
|
|
|
description:
|
2022-04-20 08:24:51 +02:00
|
|
|
- A Xfce preference key is an element in the Xfconf repository
|
2022-04-26 11:45:15 +02:00
|
|
|
that corresponds to an application preference. See man xfconf-query(1).
|
2022-04-20 08:24:51 +02:00
|
|
|
required: true
|
2020-07-25 12:58:14 +02:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
value:
|
|
|
|
description:
|
2022-04-20 08:24:51 +02:00
|
|
|
- Preference properties typically have simple values such as strings,
|
2022-04-26 11:45:15 +02:00
|
|
|
integers, or lists of strings and integers. See man xfconf-query(1).
|
2020-07-25 12:58:14 +02:00
|
|
|
type: list
|
|
|
|
elements: raw
|
2020-03-09 10:11:07 +01:00
|
|
|
value_type:
|
|
|
|
description:
|
2022-04-26 11:45:15 +02:00
|
|
|
- The type of value being set.
|
2023-06-18 19:48:01 +02:00
|
|
|
- When providing more than one O(value_type), the length of the list must
|
|
|
|
be equal to the length of O(value).
|
|
|
|
- If only one O(value_type) is provided, but O(value) contains more than
|
|
|
|
on element, that O(value_type) will be applied to all elements of O(value).
|
|
|
|
- If the O(property) being set is an array and it can possibly have ony one
|
|
|
|
element in the array, then O(force_array=true) must be used to ensure
|
2022-04-20 08:24:51 +02:00
|
|
|
that C(xfconf-query) will interpret the value as an array rather than a
|
|
|
|
scalar.
|
2023-06-18 19:48:01 +02:00
|
|
|
- Support for V(uchar), V(char), V(uint64), and V(int64) has been added in community.general 4.8.0.
|
2020-07-25 12:58:14 +02:00
|
|
|
type: list
|
|
|
|
elements: str
|
2022-04-20 20:58:40 +02:00
|
|
|
choices: [ string, int, double, bool, uint, uchar, char, uint64, int64, float ]
|
2020-03-09 10:11:07 +01:00
|
|
|
state:
|
2020-11-04 09:02:50 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
2022-04-20 08:24:51 +02:00
|
|
|
- The action to take upon the property/value.
|
2023-06-18 19:48:01 +02:00
|
|
|
- The state V(get) has been removed in community.general 5.0.0. Please use the module M(community.general.xfconf_info) instead.
|
2022-04-26 11:45:15 +02:00
|
|
|
choices: [ present, absent ]
|
2020-03-09 10:11:07 +01:00
|
|
|
default: "present"
|
2020-07-25 12:58:14 +02:00
|
|
|
force_array:
|
|
|
|
description:
|
2022-11-08 14:03:07 +01:00
|
|
|
- Force array even if only one element.
|
2020-07-25 12:58:14 +02:00
|
|
|
type: bool
|
2022-08-24 19:59:01 +02:00
|
|
|
default: false
|
2020-07-25 12:58:14 +02:00
|
|
|
aliases: ['array']
|
|
|
|
version_added: 1.0.0
|
2021-02-10 19:42:40 +01:00
|
|
|
disable_facts:
|
|
|
|
description:
|
2023-06-18 19:48:01 +02:00
|
|
|
- The value V(false) is no longer allowed since community.general 4.0.0.
|
2022-05-17 19:26:06 +02:00
|
|
|
- This option is deprecated, and will be removed in community.general 8.0.0.
|
2021-02-10 19:42:40 +01:00
|
|
|
type: bool
|
2021-10-12 13:56:15 +02:00
|
|
|
default: true
|
2021-02-10 19:42:40 +01:00
|
|
|
version_added: 2.1.0
|
2020-03-09 10:11:07 +01:00
|
|
|
'''
|
|
|
|
|
|
|
|
EXAMPLES = """
|
|
|
|
- name: Change the DPI to "192"
|
2020-07-25 12:58:14 +02:00
|
|
|
xfconf:
|
2020-03-09 10:11:07 +01:00
|
|
|
channel: "xsettings"
|
|
|
|
property: "/Xft/DPI"
|
|
|
|
value_type: "int"
|
|
|
|
value: "192"
|
|
|
|
|
2020-07-25 12:58:14 +02:00
|
|
|
- name: Set workspace names (4)
|
|
|
|
xfconf:
|
|
|
|
channel: xfwm4
|
|
|
|
property: /general/workspace_names
|
|
|
|
value_type: string
|
|
|
|
value: ['Main', 'Work1', 'Work2', 'Tmp']
|
|
|
|
|
|
|
|
- name: Set workspace names (1)
|
|
|
|
xfconf:
|
|
|
|
channel: xfwm4
|
|
|
|
property: /general/workspace_names
|
|
|
|
value_type: string
|
|
|
|
value: ['Main']
|
2022-04-20 08:24:51 +02:00
|
|
|
force_array: true
|
2020-03-09 10:11:07 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
RETURN = '''
|
|
|
|
channel:
|
|
|
|
description: The channel specified in the module parameters
|
|
|
|
returned: success
|
|
|
|
type: str
|
|
|
|
sample: "xsettings"
|
|
|
|
property:
|
|
|
|
description: The property specified in the module parameters
|
|
|
|
returned: success
|
|
|
|
type: str
|
|
|
|
sample: "/Xft/DPI"
|
|
|
|
value_type:
|
2020-12-12 09:07:30 +01:00
|
|
|
description:
|
2023-06-18 19:48:01 +02:00
|
|
|
- The type of the value that was changed (V(none) for O(state=reset)).
|
|
|
|
Either a single string value or a list of strings for array types.
|
2022-04-20 08:24:51 +02:00
|
|
|
- This is a string or a list of strings.
|
2020-03-09 10:11:07 +01:00
|
|
|
returned: success
|
2022-02-02 21:58:27 +01:00
|
|
|
type: any
|
2020-12-12 09:07:30 +01:00
|
|
|
sample: '"int" or ["str", "str", "str"]'
|
2020-03-09 10:11:07 +01:00
|
|
|
value:
|
2020-12-12 09:07:30 +01:00
|
|
|
description:
|
2022-04-20 08:24:51 +02:00
|
|
|
- The value of the preference key after executing the module. Either a
|
|
|
|
single string value or a list of strings for array types.
|
|
|
|
- This is a string or a list of strings.
|
2020-03-09 10:11:07 +01:00
|
|
|
returned: success
|
2022-02-02 21:58:27 +01:00
|
|
|
type: any
|
2020-12-12 09:07:30 +01:00
|
|
|
sample: '"192" or ["orange", "yellow", "violet"]'
|
2020-07-25 12:58:14 +02:00
|
|
|
previous_value:
|
2020-12-12 09:07:30 +01:00
|
|
|
description:
|
2022-04-26 11:45:15 +02:00
|
|
|
- The value of the preference key before executing the module.
|
|
|
|
Either a single string value or a list of strings for array types.
|
2022-04-20 08:24:51 +02:00
|
|
|
- This is a string or a list of strings.
|
2020-07-25 12:58:14 +02:00
|
|
|
returned: success
|
2022-02-02 21:58:27 +01:00
|
|
|
type: any
|
2020-12-12 09:07:30 +01:00
|
|
|
sample: '"96" or ["red", "blue", "green"]'
|
2022-08-01 11:21:06 +02:00
|
|
|
cmd:
|
|
|
|
description:
|
|
|
|
- A list with the resulting C(xfconf-query) command executed by the module.
|
|
|
|
returned: success
|
|
|
|
type: list
|
|
|
|
elements: str
|
|
|
|
version_added: 5.4.0
|
|
|
|
sample:
|
|
|
|
- /usr/bin/xfconf-query
|
|
|
|
- --channel
|
|
|
|
- xfce4-panel
|
|
|
|
- --property
|
|
|
|
- /plugins/plugin-19/timezone
|
|
|
|
- --create
|
|
|
|
- --type
|
|
|
|
- string
|
|
|
|
- --set
|
|
|
|
- Pacific/Auckland
|
2020-03-09 10:11:07 +01:00
|
|
|
'''
|
|
|
|
|
2022-06-06 10:38:46 +02:00
|
|
|
from ansible_collections.community.general.plugins.module_utils.module_helper import StateModuleHelper
|
|
|
|
from ansible_collections.community.general.plugins.module_utils.xfconf import xfconf_runner
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
|
2022-06-06 10:38:46 +02:00
|
|
|
class XFConfProperty(StateModuleHelper):
|
2023-02-04 17:05:08 +01:00
|
|
|
change_params = ('value', )
|
|
|
|
diff_params = ('value', )
|
2021-04-06 21:21:05 +02:00
|
|
|
output_params = ('property', 'channel', 'value')
|
2020-11-20 11:27:53 +01:00
|
|
|
module = dict(
|
|
|
|
argument_spec=dict(
|
2022-04-26 11:45:15 +02:00
|
|
|
state=dict(type='str', choices=("present", "absent"), default="present"),
|
2022-04-20 20:58:40 +02:00
|
|
|
channel=dict(type='str', required=True),
|
|
|
|
property=dict(type='str', required=True),
|
|
|
|
value_type=dict(type='list', elements='str',
|
|
|
|
choices=('string', 'int', 'double', 'bool', 'uint', 'uchar', 'char', 'uint64', 'int64', 'float')),
|
|
|
|
value=dict(type='list', elements='raw'),
|
|
|
|
force_array=dict(type='bool', default=False, aliases=['array']),
|
2022-05-17 19:26:06 +02:00
|
|
|
disable_facts=dict(
|
|
|
|
type='bool', default=True,
|
|
|
|
removed_in_version='8.0.0',
|
|
|
|
removed_from_collection='community.general'
|
|
|
|
),
|
2020-11-20 11:27:53 +01:00
|
|
|
),
|
|
|
|
required_if=[('state', 'present', ['value', 'value_type'])],
|
|
|
|
required_together=[('value', 'value_type')],
|
|
|
|
supports_check_mode=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
default_state = 'present'
|
|
|
|
|
|
|
|
def __init_module__(self):
|
2022-06-06 10:38:46 +02:00
|
|
|
self.runner = xfconf_runner(self.module)
|
|
|
|
self.does_not = 'Property "{0}" does not exist on channel "{1}".'.format(self.vars.property,
|
|
|
|
self.vars.channel)
|
2022-11-10 21:18:52 +01:00
|
|
|
self.vars.set('previous_value', self._get())
|
|
|
|
self.vars.set('type', self.vars.value_type)
|
2021-04-06 21:21:05 +02:00
|
|
|
self.vars.meta('value').set(initial_value=self.vars.previous_value)
|
|
|
|
|
2022-06-06 10:38:46 +02:00
|
|
|
if self.vars.disable_facts is False:
|
2022-05-23 07:19:24 +02:00
|
|
|
self.do_raise('Returning results as facts has been removed. Stop using disable_facts=false.')
|
2020-11-20 11:27:53 +01:00
|
|
|
|
|
|
|
def process_command_output(self, rc, out, err):
|
|
|
|
if err.rstrip() == self.does_not:
|
|
|
|
return None
|
|
|
|
if rc or len(err):
|
2022-07-24 12:09:24 +02:00
|
|
|
self.do_raise('xfconf-query failed with error (rc={0}): {1}'.format(rc, err))
|
2020-11-20 11:27:53 +01:00
|
|
|
|
|
|
|
result = out.rstrip()
|
|
|
|
if "Value is an array with" in result:
|
|
|
|
result = result.split("\n")
|
|
|
|
result.pop(0)
|
|
|
|
result.pop(0)
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
def _get(self):
|
2022-06-15 08:06:26 +02:00
|
|
|
with self.runner('channel property', output_process=self.process_command_output) as ctx:
|
2022-06-06 10:38:46 +02:00
|
|
|
return ctx.run()
|
2020-07-25 12:58:14 +02:00
|
|
|
|
2020-11-20 11:27:53 +01:00
|
|
|
def state_absent(self):
|
2022-06-15 08:06:26 +02:00
|
|
|
with self.runner('channel property reset', check_mode_skip=True) as ctx:
|
2022-06-06 10:38:46 +02:00
|
|
|
ctx.run(reset=True)
|
2022-08-01 11:21:06 +02:00
|
|
|
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
|
2020-11-20 11:27:53 +01:00
|
|
|
self.vars.value = None
|
2020-07-25 12:58:14 +02:00
|
|
|
|
2020-11-20 11:27:53 +01:00
|
|
|
def state_present(self):
|
2020-07-25 12:58:14 +02:00
|
|
|
# stringify all values - in the CLI they will all be happy strings anyway
|
|
|
|
# and by doing this here the rest of the code can be agnostic to it
|
2021-04-06 21:21:05 +02:00
|
|
|
self.vars.value = [str(v) for v in self.vars.value]
|
|
|
|
value_type = self.vars.value_type
|
2020-07-25 12:58:14 +02:00
|
|
|
|
2020-11-20 11:27:53 +01:00
|
|
|
values_len = len(self.vars.value)
|
|
|
|
types_len = len(value_type)
|
2020-07-25 12:58:14 +02:00
|
|
|
|
|
|
|
if types_len == 1:
|
|
|
|
# use one single type for the entire list
|
2020-11-20 11:27:53 +01:00
|
|
|
value_type = value_type * values_len
|
2020-07-25 12:58:14 +02:00
|
|
|
elif types_len != values_len:
|
|
|
|
# or complain if lists' lengths are different
|
2022-07-24 12:09:24 +02:00
|
|
|
self.do_raise('Number of elements in "value" and "value_type" must be the same')
|
2020-07-25 12:58:14 +02:00
|
|
|
|
|
|
|
# calculates if it is an array
|
2020-11-20 11:27:53 +01:00
|
|
|
self.vars.is_array = \
|
2021-04-06 21:21:05 +02:00
|
|
|
bool(self.vars.force_array) or \
|
2020-11-20 11:27:53 +01:00
|
|
|
isinstance(self.vars.previous_value, list) or \
|
|
|
|
values_len > 1
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2022-06-15 08:06:26 +02:00
|
|
|
with self.runner('channel property create force_array values_and_types', check_mode_skip=True) as ctx:
|
2022-06-06 10:38:46 +02:00
|
|
|
ctx.run(create=True, force_array=self.vars.is_array, values_and_types=(self.vars.value, value_type))
|
2022-08-01 11:21:06 +02:00
|
|
|
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
|
2020-07-25 12:58:14 +02:00
|
|
|
|
2020-11-20 11:27:53 +01:00
|
|
|
if not self.vars.is_array:
|
|
|
|
self.vars.value = self.vars.value[0]
|
2021-04-06 21:21:05 +02:00
|
|
|
self.vars.type = value_type[0]
|
|
|
|
else:
|
|
|
|
self.vars.type = value_type
|
2020-07-25 12:58:14 +02:00
|
|
|
|
2020-11-20 11:27:53 +01:00
|
|
|
|
|
|
|
def main():
|
2021-08-17 10:43:18 +02:00
|
|
|
XFConfProperty.execute()
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|