2020-03-09 10:11:07 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2022-08-05 12:28:29 +02:00
|
|
|
# Copyright (c) 2016, Kenneth D. Evensen <kevensen@redhat.com>
|
|
|
|
# Copyright (c) 2017, Abhijeet Kasurde <akasurde@redhat.com>
|
|
|
|
# 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: gconftool2
|
|
|
|
author:
|
2023-02-20 17:28:47 +01:00
|
|
|
- Kenneth D. Evensen (@kevensen)
|
2020-03-09 10:11:07 +01:00
|
|
|
short_description: Edit GNOME Configurations
|
|
|
|
description:
|
|
|
|
- This module allows for the manipulation of GNOME 2 Configuration via
|
|
|
|
gconftool-2. Please see the gconftool-2(1) man pages for more details.
|
2023-02-20 17:28:47 +01:00
|
|
|
extends_documentation_fragment:
|
|
|
|
- community.general.attributes
|
|
|
|
attributes:
|
|
|
|
check_mode:
|
|
|
|
support: full
|
|
|
|
diff_mode:
|
|
|
|
support: none
|
2020-03-09 10:11:07 +01:00
|
|
|
options:
|
|
|
|
key:
|
2020-11-04 09:02:50 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- A GConf preference key is an element in the GConf repository
|
2022-07-29 11:38:37 +02:00
|
|
|
that corresponds to an application preference. See man gconftool-2(1).
|
2022-08-24 19:59:01 +02:00
|
|
|
required: true
|
2020-03-09 10:11:07 +01:00
|
|
|
value:
|
2020-11-04 09:02:50 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- Preference keys typically have simple values such as strings,
|
2023-05-03 22:45:35 +02:00
|
|
|
integers, or lists of strings and integers.
|
2023-06-15 15:46:44 +02:00
|
|
|
This is ignored unless O(state=present). See man gconftool-2(1).
|
2020-03-09 10:11:07 +01:00
|
|
|
value_type:
|
2020-11-04 09:02:50 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
2023-05-03 22:45:35 +02:00
|
|
|
- The type of value being set.
|
2023-06-15 15:46:44 +02:00
|
|
|
This is ignored unless O(state=present). See man gconftool-2(1).
|
2020-03-09 10:11:07 +01:00
|
|
|
choices: [ bool, float, int, string ]
|
|
|
|
state:
|
2020-11-04 09:02:50 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- The action to take upon the key/value.
|
2022-08-24 19:59:01 +02:00
|
|
|
required: true
|
2023-10-09 13:31:27 +02:00
|
|
|
choices: [ absent, present ]
|
2020-03-09 10:11:07 +01:00
|
|
|
config_source:
|
2020-11-04 09:02:50 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- Specify a configuration source to use rather than the default path.
|
2022-07-29 11:38:37 +02:00
|
|
|
See man gconftool-2(1).
|
2020-03-09 10:11:07 +01:00
|
|
|
direct:
|
|
|
|
description:
|
2023-06-15 15:46:44 +02:00
|
|
|
- Access the config database directly, bypassing server. If O(direct) is
|
|
|
|
specified then the O(config_source) must be specified as well.
|
2022-07-29 11:38:37 +02:00
|
|
|
See man gconftool-2(1).
|
2020-03-09 10:11:07 +01:00
|
|
|
type: bool
|
2022-08-24 19:59:01 +02:00
|
|
|
default: false
|
2020-03-09 10:11:07 +01:00
|
|
|
'''
|
|
|
|
|
|
|
|
EXAMPLES = """
|
|
|
|
- name: Change the widget font to "Serif 12"
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.gconftool2:
|
2020-03-09 10:11:07 +01:00
|
|
|
key: "/desktop/gnome/interface/font_name"
|
|
|
|
value_type: "string"
|
|
|
|
value: "Serif 12"
|
|
|
|
"""
|
|
|
|
|
|
|
|
RETURN = '''
|
|
|
|
key:
|
2023-05-03 22:45:35 +02:00
|
|
|
description: The key specified in the module parameters.
|
2020-03-09 10:11:07 +01:00
|
|
|
returned: success
|
|
|
|
type: str
|
|
|
|
sample: /desktop/gnome/interface/font_name
|
|
|
|
value_type:
|
2023-05-03 22:45:35 +02:00
|
|
|
description: The type of the value that was changed.
|
2020-03-09 10:11:07 +01:00
|
|
|
returned: success
|
|
|
|
type: str
|
|
|
|
sample: string
|
|
|
|
value:
|
2023-05-03 22:45:35 +02:00
|
|
|
description:
|
2023-06-15 15:46:44 +02:00
|
|
|
- The value of the preference key after executing the module or V(null) if key is removed.
|
|
|
|
- From community.general 7.0.0 onwards it returns V(null) for a non-existent O(key), and returned V("") before that.
|
2023-05-03 22:45:35 +02:00
|
|
|
returned: success
|
|
|
|
type: str
|
|
|
|
sample: "Serif 12"
|
|
|
|
previous_value:
|
|
|
|
description:
|
|
|
|
- The value of the preference key before executing the module.
|
2023-06-15 15:46:44 +02:00
|
|
|
- From community.general 7.0.0 onwards it returns V(null) for a non-existent O(key), and returned V("") before that.
|
2020-03-09 10:11:07 +01:00
|
|
|
returned: success
|
|
|
|
type: str
|
|
|
|
sample: "Serif 12"
|
|
|
|
...
|
|
|
|
'''
|
|
|
|
|
2022-11-15 21:02:45 +01:00
|
|
|
from ansible_collections.community.general.plugins.module_utils.module_helper import StateModuleHelper
|
|
|
|
from ansible_collections.community.general.plugins.module_utils.gconftool2 import gconftool2_runner
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
|
2022-11-15 21:02:45 +01:00
|
|
|
class GConftool(StateModuleHelper):
|
2023-02-04 17:05:08 +01:00
|
|
|
diff_params = ('value', )
|
2022-11-15 21:02:45 +01:00
|
|
|
output_params = ('key', 'value_type')
|
|
|
|
facts_params = ('key', 'value_type')
|
|
|
|
facts_name = 'gconftool2'
|
|
|
|
module = dict(
|
2020-03-09 10:11:07 +01:00
|
|
|
argument_spec=dict(
|
2021-03-12 08:51:47 +01:00
|
|
|
key=dict(type='str', required=True, no_log=False),
|
2020-03-09 10:11:07 +01:00
|
|
|
value_type=dict(type='str', choices=['bool', 'float', 'int', 'string']),
|
|
|
|
value=dict(type='str'),
|
2023-10-09 13:31:27 +02:00
|
|
|
state=dict(type='str', required=True, choices=['absent', 'present']),
|
2020-03-09 10:11:07 +01:00
|
|
|
direct=dict(type='bool', default=False),
|
|
|
|
config_source=dict(type='str'),
|
|
|
|
),
|
2022-11-15 21:02:45 +01:00
|
|
|
required_if=[
|
|
|
|
('state', 'present', ['value', 'value_type']),
|
|
|
|
('direct', True, ['config_source']),
|
|
|
|
],
|
|
|
|
supports_check_mode=True,
|
2020-03-09 10:11:07 +01:00
|
|
|
)
|
2024-04-23 22:07:29 +02:00
|
|
|
use_old_vardict = False
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2022-11-15 21:02:45 +01:00
|
|
|
def __init_module__(self):
|
|
|
|
self.runner = gconftool2_runner(self.module, check_rc=True)
|
2024-08-05 21:06:11 +02:00
|
|
|
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"')
|
2022-11-15 21:02:45 +01:00
|
|
|
|
|
|
|
self.vars.set('previous_value', self._get(), fact=True)
|
|
|
|
self.vars.set('value_type', self.vars.value_type)
|
2023-05-03 22:45:35 +02:00
|
|
|
self.vars.set('_value', self.vars.previous_value, output=False, change=True)
|
2022-11-15 21:02:45 +01:00
|
|
|
self.vars.set_meta('value', initial_value=self.vars.previous_value)
|
|
|
|
self.vars.set('playbook_value', self.vars.value, fact=True)
|
|
|
|
|
|
|
|
def _make_process(self, fail_on_err):
|
|
|
|
def process(rc, out, err):
|
|
|
|
if err and fail_on_err:
|
2024-08-05 21:06:11 +02:00
|
|
|
self.do_raise('gconftool-2 failed with error:\n%s' % err.strip())
|
2023-05-03 22:45:35 +02:00
|
|
|
out = out.rstrip()
|
|
|
|
self.vars.value = None if out == "" else out
|
2022-11-15 21:02:45 +01:00
|
|
|
return self.vars.value
|
|
|
|
return process
|
|
|
|
|
|
|
|
def _get(self):
|
|
|
|
return self.runner("state key", output_process=self._make_process(False)).run(state="get")
|
|
|
|
|
|
|
|
def state_absent(self):
|
|
|
|
with self.runner("state key", output_process=self._make_process(False)) as ctx:
|
|
|
|
ctx.run()
|
2024-08-05 21:06:11 +02:00
|
|
|
self.vars.set('run_info', ctx.run_info, verbosity=4)
|
2022-11-15 21:02:45 +01:00
|
|
|
self.vars.set('new_value', None, fact=True)
|
2023-05-03 22:45:35 +02:00
|
|
|
self.vars._value = None
|
2022-11-15 21:02:45 +01:00
|
|
|
|
|
|
|
def state_present(self):
|
|
|
|
with self.runner("direct config_source value_type state key value", output_process=self._make_process(True)) as ctx:
|
2023-05-03 22:45:35 +02:00
|
|
|
ctx.run()
|
2024-08-05 21:06:11 +02:00
|
|
|
self.vars.set('run_info', ctx.run_info, verbosity=4)
|
2023-05-03 22:45:35 +02:00
|
|
|
self.vars.set('new_value', self._get(), fact=True)
|
|
|
|
self.vars._value = self.vars.new_value
|
2022-11-15 21:02:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
GConftool.execute()
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|