mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
* gconftool2: improvements
* added changelog fragment
* typo
* Update changelogs/fragments/4647-gconftool2-command-arg.yaml
Per recommendation from Felix. Danke!
(cherry picked from commit fbff98c5f2
)
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
parent
4ed3fa9a73
commit
3ad920c872
2 changed files with 16 additions and 18 deletions
2
changelogs/fragments/4647-gconftool2-command-arg.yaml
Normal file
2
changelogs/fragments/4647-gconftool2-command-arg.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- gconftool2 - properly escape values when passing them to ``gconftool-2`` (https://github.com/ansible-collections/community.general/pull/4647).
|
|
@ -99,43 +99,39 @@ class GConf2Preference(object):
|
|||
|
||||
def call(self, call_type, fail_onerr=True):
|
||||
""" Helper function to perform gconftool-2 operations """
|
||||
config_source = ''
|
||||
direct = ''
|
||||
config_source = []
|
||||
direct = []
|
||||
changed = False
|
||||
out = ''
|
||||
|
||||
# If the configuration source is different from the default, create
|
||||
# the argument
|
||||
if self.config_source is not None and len(self.config_source) > 0:
|
||||
config_source = "--config-source " + self.config_source
|
||||
config_source = ["--config-source", self.config_source]
|
||||
|
||||
# If direct is true, create the argument
|
||||
if self.direct:
|
||||
direct = "--direct"
|
||||
direct = ["--direct"]
|
||||
|
||||
# Execute the call
|
||||
cmd = "gconftool-2 "
|
||||
cmd = ["gconftool-2"]
|
||||
try:
|
||||
# If the call is "get", then we don't need as many parameters and
|
||||
# we can ignore some
|
||||
if call_type == 'get':
|
||||
cmd += "--get {0}".format(self.key)
|
||||
cmd.extend(["--get", self.key])
|
||||
# Otherwise, we will use all relevant parameters
|
||||
elif call_type == 'set':
|
||||
cmd += "{0} {1} --type {2} --{3} {4} \"{5}\"".format(direct,
|
||||
config_source,
|
||||
self.value_type,
|
||||
call_type,
|
||||
self.key,
|
||||
self.value)
|
||||
cmd.extend(direct)
|
||||
cmd.extend(config_source)
|
||||
cmd.extend(["--type", self.value_type, "--{3}".format(call_type), self.key, self.value])
|
||||
elif call_type == 'unset':
|
||||
cmd += "--unset {0}".format(self.key)
|
||||
cmd.extend(["--unset", self.key])
|
||||
|
||||
# Start external command
|
||||
rc, out, err = self.ansible.run_command(cmd, use_unsafe_shell=True)
|
||||
rc, out, err = self.ansible.run_command(cmd)
|
||||
|
||||
if len(err) > 0:
|
||||
if fail_onerr:
|
||||
if err and fail_onerr:
|
||||
self.ansible.fail_json(msg='gconftool-2 failed with '
|
||||
'error: %s' % (str(err)))
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue