diff --git a/lib/ansible/modules/packaging/os/pacman.py b/lib/ansible/modules/packaging/os/pacman.py index 787781bb37..8a0af877a7 100644 --- a/lib/ansible/modules/packaging/os/pacman.py +++ b/lib/ansible/modules/packaging/os/pacman.py @@ -258,6 +258,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): @@ -265,9 +268,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: @@ -305,6 +305,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): @@ -312,14 +316,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): @@ -327,9 +332,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: