[PR #10601/25dc0907 backport][stable-11] pear: command args as list rather than string (#10634)

pear: command args as list rather than string (#10601)

* pear: command args as list rather than string

* add changelog frag

(cherry picked from commit 25dc09074e)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2025-08-10 13:50:36 +02:00 committed by GitHub
commit 0d96b65b4b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 25 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- pear - using safer mechanism to run external command (https://github.com/ansible-collections/community.general/pull/10601).

View file

@ -151,34 +151,33 @@ def get_repository_version(pear_output):
return None
def query_package(module, name, state="present"):
def query_package(module, name):
"""Query the package status in both the local system and the repository.
Returns a boolean to indicate if the package is installed,
and a second boolean to indicate if the package is up-to-date."""
if state == "present":
lcmd = "%s info %s" % (_get_pear_path(module), name)
lrc, lstdout, lstderr = module.run_command(lcmd, check_rc=False)
if lrc != 0:
# package is not installed locally
return False, False
rcmd = "%s remote-info %s" % (_get_pear_path(module), name)
rrc, rstdout, rstderr = module.run_command(rcmd, check_rc=False)
# get the version installed locally (if any)
lversion = get_local_version(rstdout)
# get the version in the repository
rversion = get_repository_version(rstdout)
if rrc == 0:
# Return True to indicate that the package is installed locally,
# and the result of the version number comparison
# to determine if the package is up-to-date.
return True, (lversion == rversion)
lcmd = [_get_pear_path(module), "info", name]
lrc, lstdout, lstderr = module.run_command(lcmd, check_rc=False)
if lrc != 0:
# package is not installed locally
return False, False
rcmd = [_get_pear_path(module), "remote-info", name]
rrc, rstdout, rstderr = module.run_command(rcmd, check_rc=False)
# get the version installed locally (if any)
lversion = get_local_version(rstdout)
# get the version in the repository
rversion = get_repository_version(rstdout)
if rrc == 0:
# Return True to indicate that the package is installed locally,
# and the result of the version number comparison
# to determine if the package is up-to-date.
return True, (lversion == rversion)
return False, False
def remove_packages(module, packages):
remove_c = 0
@ -189,7 +188,7 @@ def remove_packages(module, packages):
if not installed:
continue
cmd = "%s uninstall %s" % (_get_pear_path(module), package)
cmd = [_get_pear_path(module), "uninstall", package]
rc, stdout, stderr = module.run_command(cmd, check_rc=False)
if rc != 0:
@ -258,7 +257,7 @@ def install_packages(module, state, packages, prompts):
prompt_regex = None
data = default_stdin
cmd = "%s %s %s" % (_get_pear_path(module), command, package)
cmd = [_get_pear_path(module), command, package]
rc, stdout, stderr = module.run_command(cmd, check_rc=False, prompt_regex=prompt_regex, data=data, binary_data=True)
if rc != 0:
module.fail_json(msg="failed to install %s: %s" % (package, to_text(stdout + stderr)))