mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-11 08:34:21 -07:00
pear: command args as list rather than string (#10601)
* pear: command args as list rather than string * add changelog frag
This commit is contained in:
parent
1bd7aac07e
commit
25dc09074e
2 changed files with 26 additions and 25 deletions
2
changelogs/fragments/10601-pear-cmd-list.yml
Normal file
2
changelogs/fragments/10601-pear-cmd-list.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- pear - using safer mechanism to run external command (https://github.com/ansible-collections/community.general/pull/10601).
|
|
@ -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)))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue