1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

pacman: Fail fast when 'rc != 0'

We fail-fast and display 'stderr' in case 'pacman' returns with 'rc != 0'.
There is no point computing 'module._diff' in such case anyway.

Fixes #23910

(cherry picked from commit 8c6a2a848cf6a6d6522c8f5be56decf8df1ed6ab)
This commit is contained in:
Indrajit Raychaudhuri 2017-04-24 17:19:13 -05:00 committed by Brian Coca
parent 72a4e1cf0d
commit 45252b79be

View file

@ -258,6 +258,9 @@ def remove_packages(module, pacman_path, packages):
cmd = "%s -%s %s --noconfirm --noprogressbar" % (pacman_path, args, package) cmd = "%s -%s %s --noconfirm --noprogressbar" % (pacman_path, args, package)
rc, stdout, stderr = module.run_command(cmd, check_rc=False) rc, stdout, stderr = module.run_command(cmd, check_rc=False)
if rc != 0:
module.fail_json(msg="failed to remove %s" % (package))
if module._diff: if module._diff:
d = stdout.split('\n')[2].split(' ')[2:] d = stdout.split('\n')[2].split(' ')[2:]
for i, pkg in enumerate(d): for i, pkg in enumerate(d):
@ -265,9 +268,6 @@ def remove_packages(module, pacman_path, packages):
diff['before'] += "%s\n" % pkg diff['before'] += "%s\n" % pkg
data.append('\n'.join(d)) data.append('\n'.join(d))
if rc != 0:
module.fail_json(msg="failed to remove %s" % (package))
remove_c += 1 remove_c += 1
if remove_c > 0: if remove_c > 0:
@ -305,6 +305,10 @@ def install_packages(module, pacman_path, state, packages, package_files):
if to_install_repos: if to_install_repos:
cmd = "%s -S %s --noconfirm --noprogressbar --needed" % (pacman_path, " ".join(to_install_repos)) cmd = "%s -S %s --noconfirm --noprogressbar --needed" % (pacman_path, " ".join(to_install_repos))
rc, stdout, stderr = module.run_command(cmd, check_rc=False) rc, stdout, stderr = module.run_command(cmd, check_rc=False)
if rc != 0:
module.fail_json(msg="failed to install %s: %s" % (" ".join(to_install_repos), stderr))
data = stdout.split('\n')[3].split(' ')[2:] data = stdout.split('\n')[3].split(' ')[2:]
data = [ i for i in data if i != '' ] data = [ i for i in data if i != '' ]
for i, pkg in enumerate(data): for i, pkg in enumerate(data):
@ -312,14 +316,15 @@ def install_packages(module, pacman_path, state, packages, package_files):
if module._diff: if module._diff:
diff['after'] += "%s\n" % pkg diff['after'] += "%s\n" % pkg
if rc != 0:
module.fail_json(msg="failed to install %s: %s" % (" ".join(to_install_repos), stderr))
install_c += len(to_install_repos) install_c += len(to_install_repos)
if to_install_files: if to_install_files:
cmd = "%s -U %s --noconfirm --noprogressbar --needed" % (pacman_path, " ".join(to_install_files)) cmd = "%s -U %s --noconfirm --noprogressbar --needed" % (pacman_path, " ".join(to_install_files))
rc, stdout, stderr = module.run_command(cmd, check_rc=False) rc, stdout, stderr = module.run_command(cmd, check_rc=False)
if rc != 0:
module.fail_json(msg="failed to install %s: %s" % (" ".join(to_install_files), stderr))
data = stdout.split('\n')[3].split(' ')[2:] data = stdout.split('\n')[3].split(' ')[2:]
data = [ i for i in data if i != '' ] data = [ i for i in data if i != '' ]
for i, pkg in enumerate(data): for i, pkg in enumerate(data):
@ -327,9 +332,6 @@ def install_packages(module, pacman_path, state, packages, package_files):
if module._diff: if module._diff:
diff['after'] += "%s\n" % pkg diff['after'] += "%s\n" % pkg
if rc != 0:
module.fail_json(msg="failed to install %s: %s" % (" ".join(to_install_files), stderr))
install_c += len(to_install_files) install_c += len(to_install_files)
if state == 'latest' and len(package_err) > 0: if state == 'latest' and len(package_err) > 0: