We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `packaging/os/apt_rpm.py`
Content:
```
1 #!/usr/bin/python -tt
2 # -*- coding: utf-8 -*-
3 
4 # (c) 2013, Evgenii Terechkov
5 # Written by Evgenii Terechkov <evg@altlinux.org> 
6 # Based on urpmi module written by Philippe Makowski <philippem@mageia.org> 
7 #
8 # This module is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This software is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this software.  If not, see <http://www.gnu.org/licenses/>.
20 
21 
22 DOCUMENTATION = '''
23 ---
24 module: apt_rpm
25 short_description: apt_rpm package manager
26 description:
27   - Manages packages with I(apt-rpm). Both low-level (I(rpm)) and high-level (I(apt-get)) package manager binaries required.
28 version_added: "1.5"
29 options:
30   pkg:
31     description:
32       - name of package to install, upgrade or remove.
33     required: true
34     default: null
35   state:
36     description:
37       - Indicates the desired package state
38     required: false
39     default: present
40     choices: [ "absent", "present" ]
41   update_cache:
42     description:
43       - update the package database first C(apt-get update).
44     required: false
45     default: no
46     choices: [ "yes", "no" ]
47 author: "Evgenii Terechkov (@evgkrsk)"
48 notes:  []
49 '''
50 
51 EXAMPLES = '''
52 # install package foo
53 - apt_rpm: pkg=foo state=present
54 # remove package foo
55 - apt_rpm: pkg=foo state=absent
56 # description: remove packages foo and bar 
57 - apt_rpm: pkg=foo,bar state=absent
58 # description: update the package database and install bar (bar will be the updated if a newer version exists) 
59 - apt_rpm: name=bar state=present update_cache=yes     
60 '''
61 
62 
63 try:
64     import json
65 except ImportError:
66     import simplejson as json
67 
68 import shlex
69 import os
70 import sys
71 
72 APT_PATH="/usr/bin/apt-get"
73 RPM_PATH="/usr/bin/rpm"
74 
75 def query_package(module, name):
76     # rpm -q returns 0 if the package is installed,
77     # 1 if it is not installed
78     rc = os.system("%s -q %s" % (RPM_PATH,name))
79     if rc == 0:
80         return True
81     else:
82         return False
83 
84 def query_package_provides(module, name):
85     # rpm -q returns 0 if the package is installed,
86     # 1 if it is not installed
87     rc = os.system("%s -q --provides %s >/dev/null" % (RPM_PATH,name))
88     return rc == 0
89 
90 def update_package_db(module):
91     rc = os.system("%s update" % APT_PATH)
92 
93     if rc != 0:
94         module.fail_json(msg="could not update package db")
95 
96 def remove_packages(module, packages):
97     
98     remove_c = 0
99     # Using a for loop incase of error, we can report the package that failed
100     for package in packages:
101         # Query the package first, to see if we even need to remove
102         if not query_package(module, package):
103             continue
104 
105         rc = os.system("%s -y remove %s > /dev/null" % (APT_PATH,package))
106 
107         if rc != 0:
108             module.fail_json(msg="failed to remove %s" % (package))
109     
110         remove_c += 1
111 
112     if remove_c > 0:
113         module.exit_json(changed=True, msg="removed %s package(s)" % remove_c)
114 
115     module.exit_json(changed=False, msg="package(s) already absent")
116 
117 
118 def install_packages(module, pkgspec):
119 
120     packages = ""
121     for package in pkgspec:
122         if not query_package_provides(module, package):
123             packages += "'%s' " % package
124 
125     if len(packages) != 0:
126 
127         cmd = ("%s -y install %s > /dev/null" % (APT_PATH, packages))
128 
129         rc, out, err = module.run_command(cmd)
130 
131         installed = True
132         for packages in pkgspec:
133             if not query_package_provides(module, package):
134                 installed = False
135 
136         # apt-rpm always have 0 for exit code if --force is used
137         if rc or not installed:
138             module.fail_json(msg="'apt-get -y install %s' failed: %s" % (packages, err))
139         else:
140             module.exit_json(changed=True, msg="%s present(s)" % packages)
141     else:
142         module.exit_json(changed=False)
143 
144 
145 def main():
146     module = AnsibleModule(
147             argument_spec    = dict(
148                 state        = dict(default='installed', choices=['installed', 'removed', 'absent', 'present']),
149                 update_cache = dict(default=False, aliases=['update-cache'], type='bool'),
150                 package      = dict(aliases=['pkg', 'name'], required=True)))
151                 
152 
153     if not os.path.exists(APT_PATH) or not os.path.exists(RPM_PATH):
154         module.fail_json(msg="cannot find /usr/bin/apt-get and/or /usr/bin/rpm")
155 
156     p = module.params
157 
158     if p['update_cache']:
159         update_package_db(module)
160 
161     packages = p['package'].split(',')
162 
163     if p['state'] in [ 'installed', 'present' ]:
164         install_packages(module, packages)
165 
166     elif p['state'] in [ 'removed', 'absent' ]:
167         remove_packages(module, packages)
168 
169 # this is magic, see lib/ansible/module_common.py
170 from ansible.module_utils.basic import *
171     
172 main()        
173
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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_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 @@
         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 @@
 
     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:

{"golden_diff": "diff --git a/packaging/os/apt_rpm.py b/packaging/os/apt_rpm.py\nold mode 100644\nnew mode 100755\n--- a/packaging/os/apt_rpm.py\n+++ b/packaging/os/apt_rpm.py\n@@ -75,7 +75,7 @@\n def query_package(module, name):\n     # rpm -q returns 0 if the package is installed,\n     # 1 if it is not installed\n-    rc = os.system(\"%s -q %s\" % (RPM_PATH,name))\n+    rc, out, err = module.run_command(\"%s -q %s\" % (RPM_PATH,name))\n     if rc == 0:\n         return True\n     else:\n@@ -84,14 +84,14 @@\n def query_package_provides(module, name):\n     # rpm -q returns 0 if the package is installed,\n     # 1 if it is not installed\n-    rc = os.system(\"%s -q --provides %s >/dev/null\" % (RPM_PATH,name))\n+    rc, out, err = module.run_command(\"%s -q --provides %s\" % (RPM_PATH,name))\n     return rc == 0\n \n def update_package_db(module):\n-    rc = os.system(\"%s update\" % APT_PATH)\n+    rc, out, err = module.run_command(\"%s update\" % APT_PATH)\n \n     if rc != 0:\n-        module.fail_json(msg=\"could not update package db\")\n+        module.fail_json(msg=\"could not update package db: %s\" % err)\n \n def remove_packages(module, packages):\n     \n@@ -102,10 +102,10 @@\n         if not query_package(module, package):\n             continue\n \n-        rc = os.system(\"%s -y remove %s > /dev/null\" % (APT_PATH,package))\n+        rc, out, err = module.run_command(\"%s -y remove %s\" % (APT_PATH,package))\n \n         if rc != 0:\n-            module.fail_json(msg=\"failed to remove %s\" % (package))\n+            module.fail_json(msg=\"failed to remove %s: %s\" % (package, err))\n     \n         remove_c += 1\n \n@@ -124,9 +124,7 @@\n \n     if len(packages) != 0:\n \n-        cmd = (\"%s -y install %s > /dev/null\" % (APT_PATH, packages))\n-\n-        rc, out, err = module.run_command(cmd)\n+        rc, out, err = module.run_command(\"%s -y install %s\" % (APT_PATH, packages))\n \n         installed = True\n         for packages in pkgspec:\n", "issue": "apt-rpm\n##### Issue Type:\n\nBug Report\n##### Component Name:\n\napt_rpm\n##### Ansible Version:\n\nN/A\n##### Summary:\n\nWhen I try to install a package using this command. It gives me a error.\nansible remote_hosts -m apt_rpm -s -a \"pkg=elinks state=present\"\n\n![image](https://cloud.githubusercontent.com/assets/16080783/12416617/7103fbee-bec8-11e5-9284-0ab4a5921b9b.png)\n\n![image](https://cloud.githubusercontent.com/assets/16080783/12416638/9467d0e2-bec8-11e5-9f9c-7c73275f5bb9.png)\n\nFYI, I tried installing through Apt-get command and it works.\n\napt-rpm\n##### Issue Type:\n\nBug Report\n##### Component Name:\n\napt_rpm\n##### Ansible Version:\n\nN/A\n##### Summary:\n\nWhen I try to install a package using this command. It gives me a error.\nansible remote_hosts -m apt_rpm -s -a \"pkg=elinks state=present\"\n\n![image](https://cloud.githubusercontent.com/assets/16080783/12416617/7103fbee-bec8-11e5-9284-0ab4a5921b9b.png)\n\n![image](https://cloud.githubusercontent.com/assets/16080783/12416638/9467d0e2-bec8-11e5-9f9c-7c73275f5bb9.png)\n\nFYI, I tried installing through Apt-get command and it works.\n\n", "before_files": [{"content": "#!/usr/bin/python -tt\n# -*- coding: utf-8 -*-\n\n# (c) 2013, Evgenii Terechkov\n# Written by Evgenii Terechkov <evg@altlinux.org> \n# Based on urpmi module written by Philippe Makowski <philippem@mageia.org> \n#\n# This module is free software: you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation, either version 3 of the License, or\n# (at your option) any later version.\n#\n# This software is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with this software.  If not, see <http://www.gnu.org/licenses/>.\n\n\nDOCUMENTATION = '''\n---\nmodule: apt_rpm\nshort_description: apt_rpm package manager\ndescription:\n  - Manages packages with I(apt-rpm). Both low-level (I(rpm)) and high-level (I(apt-get)) package manager binaries required.\nversion_added: \"1.5\"\noptions:\n  pkg:\n    description:\n      - name of package to install, upgrade or remove.\n    required: true\n    default: null\n  state:\n    description:\n      - Indicates the desired package state\n    required: false\n    default: present\n    choices: [ \"absent\", \"present\" ]\n  update_cache:\n    description:\n      - update the package database first C(apt-get update).\n    required: false\n    default: no\n    choices: [ \"yes\", \"no\" ]\nauthor: \"Evgenii Terechkov (@evgkrsk)\"\nnotes:  []\n'''\n\nEXAMPLES = '''\n# install package foo\n- apt_rpm: pkg=foo state=present\n# remove package foo\n- apt_rpm: pkg=foo state=absent\n# description: remove packages foo and bar \n- apt_rpm: pkg=foo,bar state=absent\n# description: update the package database and install bar (bar will be the updated if a newer version exists) \n- apt_rpm: name=bar state=present update_cache=yes     \n'''\n\n\ntry:\n    import json\nexcept ImportError:\n    import simplejson as json\n\nimport shlex\nimport os\nimport sys\n\nAPT_PATH=\"/usr/bin/apt-get\"\nRPM_PATH=\"/usr/bin/rpm\"\n\ndef query_package(module, name):\n    # rpm -q returns 0 if the package is installed,\n    # 1 if it is not installed\n    rc = os.system(\"%s -q %s\" % (RPM_PATH,name))\n    if rc == 0:\n        return True\n    else:\n        return False\n\ndef query_package_provides(module, name):\n    # rpm -q returns 0 if the package is installed,\n    # 1 if it is not installed\n    rc = os.system(\"%s -q --provides %s >/dev/null\" % (RPM_PATH,name))\n    return rc == 0\n\ndef update_package_db(module):\n    rc = os.system(\"%s update\" % APT_PATH)\n\n    if rc != 0:\n        module.fail_json(msg=\"could not update package db\")\n\ndef remove_packages(module, packages):\n    \n    remove_c = 0\n    # Using a for loop incase of error, we can report the package that failed\n    for package in packages:\n        # Query the package first, to see if we even need to remove\n        if not query_package(module, package):\n            continue\n\n        rc = os.system(\"%s -y remove %s > /dev/null\" % (APT_PATH,package))\n\n        if rc != 0:\n            module.fail_json(msg=\"failed to remove %s\" % (package))\n    \n        remove_c += 1\n\n    if remove_c > 0:\n        module.exit_json(changed=True, msg=\"removed %s package(s)\" % remove_c)\n\n    module.exit_json(changed=False, msg=\"package(s) already absent\")\n\n\ndef install_packages(module, pkgspec):\n\n    packages = \"\"\n    for package in pkgspec:\n        if not query_package_provides(module, package):\n            packages += \"'%s' \" % package\n\n    if len(packages) != 0:\n\n        cmd = (\"%s -y install %s > /dev/null\" % (APT_PATH, packages))\n\n        rc, out, err = module.run_command(cmd)\n\n        installed = True\n        for packages in pkgspec:\n            if not query_package_provides(module, package):\n                installed = False\n\n        # apt-rpm always have 0 for exit code if --force is used\n        if rc or not installed:\n            module.fail_json(msg=\"'apt-get -y install %s' failed: %s\" % (packages, err))\n        else:\n            module.exit_json(changed=True, msg=\"%s present(s)\" % packages)\n    else:\n        module.exit_json(changed=False)\n\n\ndef main():\n    module = AnsibleModule(\n            argument_spec    = dict(\n                state        = dict(default='installed', choices=['installed', 'removed', 'absent', 'present']),\n                update_cache = dict(default=False, aliases=['update-cache'], type='bool'),\n                package      = dict(aliases=['pkg', 'name'], required=True)))\n                \n\n    if not os.path.exists(APT_PATH) or not os.path.exists(RPM_PATH):\n        module.fail_json(msg=\"cannot find /usr/bin/apt-get and/or /usr/bin/rpm\")\n\n    p = module.params\n\n    if p['update_cache']:\n        update_package_db(module)\n\n    packages = p['package'].split(',')\n\n    if p['state'] in [ 'installed', 'present' ]:\n        install_packages(module, packages)\n\n    elif p['state'] in [ 'removed', 'absent' ]:\n        remove_packages(module, packages)\n\n# this is magic, see lib/ansible/module_common.py\nfrom ansible.module_utils.basic import *\n    \nmain()        \n", "path": "packaging/os/apt_rpm.py"}], "after_files": [{"content": "#!/usr/bin/python -tt\n# -*- coding: utf-8 -*-\n\n# (c) 2013, Evgenii Terechkov\n# Written by Evgenii Terechkov <evg@altlinux.org> \n# Based on urpmi module written by Philippe Makowski <philippem@mageia.org> \n#\n# This module is free software: you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation, either version 3 of the License, or\n# (at your option) any later version.\n#\n# This software is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with this software.  If not, see <http://www.gnu.org/licenses/>.\n\n\nDOCUMENTATION = '''\n---\nmodule: apt_rpm\nshort_description: apt_rpm package manager\ndescription:\n  - Manages packages with I(apt-rpm). Both low-level (I(rpm)) and high-level (I(apt-get)) package manager binaries required.\nversion_added: \"1.5\"\noptions:\n  pkg:\n    description:\n      - name of package to install, upgrade or remove.\n    required: true\n    default: null\n  state:\n    description:\n      - Indicates the desired package state\n    required: false\n    default: present\n    choices: [ \"absent\", \"present\" ]\n  update_cache:\n    description:\n      - update the package database first C(apt-get update).\n    required: false\n    default: no\n    choices: [ \"yes\", \"no\" ]\nauthor: \"Evgenii Terechkov (@evgkrsk)\"\nnotes:  []\n'''\n\nEXAMPLES = '''\n# install package foo\n- apt_rpm: pkg=foo state=present\n# remove package foo\n- apt_rpm: pkg=foo state=absent\n# description: remove packages foo and bar \n- apt_rpm: pkg=foo,bar state=absent\n# description: update the package database and install bar (bar will be the updated if a newer version exists) \n- apt_rpm: name=bar state=present update_cache=yes     \n'''\n\n\ntry:\n    import json\nexcept ImportError:\n    import simplejson as json\n\nimport shlex\nimport os\nimport sys\n\nAPT_PATH=\"/usr/bin/apt-get\"\nRPM_PATH=\"/usr/bin/rpm\"\n\ndef query_package(module, name):\n    # rpm -q returns 0 if the package is installed,\n    # 1 if it is not installed\n    rc, out, err = module.run_command(\"%s -q %s\" % (RPM_PATH,name))\n    if rc == 0:\n        return True\n    else:\n        return False\n\ndef query_package_provides(module, name):\n    # rpm -q returns 0 if the package is installed,\n    # 1 if it is not installed\n    rc, out, err = module.run_command(\"%s -q --provides %s\" % (RPM_PATH,name))\n    return rc == 0\n\ndef update_package_db(module):\n    rc, out, err = module.run_command(\"%s update\" % APT_PATH)\n\n    if rc != 0:\n        module.fail_json(msg=\"could not update package db: %s\" % err)\n\ndef remove_packages(module, packages):\n    \n    remove_c = 0\n    # Using a for loop incase of error, we can report the package that failed\n    for package in packages:\n        # Query the package first, to see if we even need to remove\n        if not query_package(module, package):\n            continue\n\n        rc, out, err = module.run_command(\"%s -y remove %s\" % (APT_PATH,package))\n\n        if rc != 0:\n            module.fail_json(msg=\"failed to remove %s: %s\" % (package, err))\n    \n        remove_c += 1\n\n    if remove_c > 0:\n        module.exit_json(changed=True, msg=\"removed %s package(s)\" % remove_c)\n\n    module.exit_json(changed=False, msg=\"package(s) already absent\")\n\n\ndef install_packages(module, pkgspec):\n\n    packages = \"\"\n    for package in pkgspec:\n        if not query_package_provides(module, package):\n            packages += \"'%s' \" % package\n\n    if len(packages) != 0:\n\n        rc, out, err = module.run_command(\"%s -y install %s\" % (APT_PATH, packages))\n\n        installed = True\n        for packages in pkgspec:\n            if not query_package_provides(module, package):\n                installed = False\n\n        # apt-rpm always have 0 for exit code if --force is used\n        if rc or not installed:\n            module.fail_json(msg=\"'apt-get -y install %s' failed: %s\" % (packages, err))\n        else:\n            module.exit_json(changed=True, msg=\"%s present(s)\" % packages)\n    else:\n        module.exit_json(changed=False)\n\n\ndef main():\n    module = AnsibleModule(\n            argument_spec    = dict(\n                state        = dict(default='installed', choices=['installed', 'removed', 'absent', 'present']),\n                update_cache = dict(default=False, aliases=['update-cache'], type='bool'),\n                package      = dict(aliases=['pkg', 'name'], required=True)))\n                \n\n    if not os.path.exists(APT_PATH) or not os.path.exists(RPM_PATH):\n        module.fail_json(msg=\"cannot find /usr/bin/apt-get and/or /usr/bin/rpm\")\n\n    p = module.params\n\n    if p['update_cache']:\n        update_package_db(module)\n\n    packages = p['package'].split(',')\n\n    if p['state'] in [ 'installed', 'present' ]:\n        install_packages(module, packages)\n\n    elif p['state'] in [ 'removed', 'absent' ]:\n        remove_packages(module, packages)\n\n# this is magic, see lib/ansible/module_common.py\nfrom ansible.module_utils.basic import *\n    \nmain()        \n", "path": "packaging/os/apt_rpm.py"}]}