summaryrefslogtreecommitdiff
path: root/lib/ansible/modules/packaging/os
diff options
context:
space:
mode:
authorIndrajit Raychaudhuri <irc@indrajit.com>2017-04-24 17:19:13 -0500
committerMichael Scherer <mscherer@users.noreply.github.com>2017-04-25 02:07:06 +0200
commit8c6a2a848cf6a6d6522c8f5be56decf8df1ed6ab (patch)
treed1b486719578383c6d8fbb1cd65faa4a91b798be /lib/ansible/modules/packaging/os
parent58666c0ca4209952252a5e20145d4e310ba4ccf7 (diff)
downloadansible-8c6a2a848cf6a6d6522c8f5be56decf8df1ed6ab.tar.gz
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
Diffstat (limited to 'lib/ansible/modules/packaging/os')
-rw-r--r--lib/ansible/modules/packaging/os/pacman.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/ansible/modules/packaging/os/pacman.py b/lib/ansible/modules/packaging/os/pacman.py
index 083ac7138d..bd5719671a 100644
--- a/lib/ansible/modules/packaging/os/pacman.py
+++ b/lib/ansible/modules/packaging/os/pacman.py
@@ -256,6 +256,9 @@ def remove_packages(module, pacman_path, packages):
cmd = "%s -%s %s --noconfirm --noprogressbar" % (pacman_path, args, package)
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:
d = stdout.split('\n')[2].split(' ')[2:]
for i, pkg in enumerate(d):
@@ -263,9 +266,6 @@ def remove_packages(module, pacman_path, packages):
diff['before'] += "%s\n" % pkg
data.append('\n'.join(d))
- if rc != 0:
- module.fail_json(msg="failed to remove %s" % (package))
-
remove_c += 1
if remove_c > 0:
@@ -303,6 +303,10 @@ def install_packages(module, pacman_path, state, packages, package_files):
if 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)
+
+ 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 = [ i for i in data if i != '' ]
for i, pkg in enumerate(data):
@@ -310,14 +314,15 @@ def install_packages(module, pacman_path, state, packages, package_files):
if module._diff:
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)
if 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)
+
+ 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 = [ i for i in data if i != '' ]
for i, pkg in enumerate(data):
@@ -325,9 +330,6 @@ def install_packages(module, pacman_path, state, packages, package_files):
if module._diff:
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)
if state == 'latest' and len(package_err) > 0: