Repository: ansible/ansible-modules-core

Issue:
apt-rpm
##### Issue Type:

Bug Report
##### Component Name:

apt_rpm
##### Ansible Version:

N/A
##### Summary:

When I try to install a package using this command. It gives me a error.
ansible remote_hosts -m apt_rpm -s -a "pkg=elinks state=present"

![image](https://cloud.githubusercontent.com/assets/16080783/12416617/7103fbee-bec8-11e5-9284-0ab4a5921b9b.png)

![image](https://cloud.githubusercontent.com/assets/16080783/12416638/9467d0e2-bec8-11e5-9f9c-7c73275f5bb9.png)

FYI, I tried installing through Apt-get command and it works.

apt-rpm
##### Issue Type:

Bug Report
##### Component Name:

apt_rpm
##### Ansible Version:

N/A
##### Summary:

When I try to install a package using this command. It gives me a error.
ansible remote_hosts -m apt_rpm -s -a "pkg=elinks state=present"

![image](https://cloud.githubusercontent.com/assets/16080783/12416617/7103fbee-bec8-11e5-9284-0ab4a5921b9b.png)

![image](https://cloud.githubusercontent.com/assets/16080783/12416638/9467d0e2-bec8-11e5-9f9c-7c73275f5bb9.png)

FYI, I tried installing through Apt-get command and it works.



Discussion:
Could you paste the error message text into your initial report instead of using images please? That will help the issue get indexed and hopefully show up in search engines if anyone else has the same problem. :-)

also will help me read it from w3m ... in any case you say that installing through 'apt-get' works? not sure then why you are using apt-rpm?

@evgkrsk, ping. This issue is waiting on your response.
[click here for bot help](https://github.com/jctanner/ansibullbot/blob/ISSUE_TRIAGE_CLASS/ISSUE_HELP.md)

<!--- boilerplate: issue_notify_maintainer --->

Could you paste the error message text into your initial report instead of using images please? That will help the issue get indexed and hopefully show up in search engines if anyone else has the same problem. :-)

also will help me read it from w3m ... in any case you say that installing through 'apt-get' works? not sure then why you are using apt-rpm?

@evgkrsk, ping. This issue is waiting on your response.
[click here for bot help](https://github.com/jctanner/ansibullbot/blob/ISSUE_TRIAGE_CLASS/ISSUE_HELP.md)

<!--- boilerplate: issue_notify_maintainer --->


Resolving patch:
diff --git a/packaging/os/apt_rpm.py b/packaging/os/apt_rpm.py
old mode 100644
new mode 100755
--- a/packaging/os/apt_rpm.py
+++ b/packaging/os/apt_rpm.py
@@ -75,7 +75,7 @@
 def query_package(module, name):
     # rpm -q returns 0 if the package is installed,
     # 1 if it is not installed
-    rc = os.system("%s -q %s" % (RPM_PATH,name))
+    rc, out, err = module.run_command("%s -q %s" % (RPM_PATH,name))
     if rc == 0:
         return True
     else:
@@ -84,14 +84,14 @@ def query_package(module, name):
 def query_package_provides(module, name):
     # rpm -q returns 0 if the package is installed,
     # 1 if it is not installed
-    rc = os.system("%s -q --provides %s >/dev/null" % (RPM_PATH,name))
+    rc, out, err = module.run_command("%s -q --provides %s" % (RPM_PATH,name))
     return rc == 0
 
 def update_package_db(module):
-    rc = os.system("%s update" % APT_PATH)
+    rc, out, err = module.run_command("%s update" % APT_PATH)
 
     if rc != 0:
-        module.fail_json(msg="could not update package db")
+        module.fail_json(msg="could not update package db: %s" % err)
 
 def remove_packages(module, packages):
     
@@ -102,10 +102,10 @@ def remove_packages(module, packages):
         if not query_package(module, package):
             continue
 
-        rc = os.system("%s -y remove %s > /dev/null" % (APT_PATH,package))
+        rc, out, err = module.run_command("%s -y remove %s" % (APT_PATH,package))
 
         if rc != 0:
-            module.fail_json(msg="failed to remove %s" % (package))
+            module.fail_json(msg="failed to remove %s: %s" % (package, err))
     
         remove_c += 1
 
@@ -124,9 +124,7 @@ def install_packages(module, pkgspec):
 
     if len(packages) != 0:
 
-        cmd = ("%s -y install %s > /dev/null" % (APT_PATH, packages))
-
-        rc, out, err = module.run_command(cmd)
+        rc, out, err = module.run_command("%s -y install %s" % (APT_PATH, packages))
 
         installed = True
         for packages in pkgspec:


Test patch: