* PEP8 fix
* Rectified string check in package install command stdout
* Add abadger's code review changes
Fixes #22245
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
(cherry picked from commit b5eca624d0029bc492a99525ac1ef0c2e469533e)
... | ... |
@@ -94,17 +94,23 @@ EXAMPLES = ''' |
94 | 94 |
import os |
95 | 95 |
import os.path |
96 | 96 |
import tempfile |
97 |
- |
|
98 | 97 |
from ansible.module_utils.basic import AnsibleModule |
99 | 98 |
|
100 | 99 |
|
101 |
-def _is_package_installed(module, name, easy_install, executable_arguments): |
|
102 |
- executable_arguments = executable_arguments + ['--dry-run'] |
|
100 |
+def install_package(module, name, easy_install, executable_arguments): |
|
103 | 101 |
cmd = '%s %s %s' % (easy_install, ' '.join(executable_arguments), name) |
104 |
- rc, status_stdout, status_stderr = module.run_command(cmd) |
|
102 |
+ rc, out, err = module.run_command(cmd) |
|
103 |
+ return rc, out, err |
|
104 |
+ |
|
105 |
+ |
|
106 |
+def _is_package_installed(module, name, easy_install, executable_arguments): |
|
107 |
+ # Copy and add to the arguments |
|
108 |
+ executable_arguments = executable_arguments[:] |
|
109 |
+ executable_arguments.append('--dry-run') |
|
110 |
+ rc, out, err = install_package(module, name, easy_install, executable_arguments) |
|
105 | 111 |
if rc: |
106 |
- module.fail_json(msg=status_stderr) |
|
107 |
- return not ('Reading' in status_stdout or 'Downloading' in status_stdout) |
|
112 |
+ module.fail_json(msg=err) |
|
113 |
+ return 'Downloading' not in out |
|
108 | 114 |
|
109 | 115 |
|
110 | 116 |
def _get_easy_install(module, env=None, executable=None): |
... | ... |
@@ -138,7 +144,7 @@ def main(): |
138 | 138 |
name=dict(required=True), |
139 | 139 |
state=dict(required=False, |
140 | 140 |
default='present', |
141 |
- choices=['present','latest'], |
|
141 |
+ choices=['present', 'latest'], |
|
142 | 142 |
type='str'), |
143 | 143 |
virtualenv=dict(default=None, required=False), |
144 | 144 |
virtualenv_site_packages=dict(default='no', type='bool'), |
... | ... |
@@ -186,8 +192,7 @@ def main(): |
186 | 186 |
if not installed: |
187 | 187 |
if module.check_mode: |
188 | 188 |
module.exit_json(changed=True) |
189 |
- cmd = '%s %s %s' % (easy_install, ' '.join(executable_arguments), name) |
|
190 |
- rc_easy_inst, out_easy_inst, err_easy_inst = module.run_command(cmd) |
|
189 |
+ rc_easy_inst, out_easy_inst, err_easy_inst = install_package(module, name, easy_install, executable_arguments) |
|
191 | 190 |
|
192 | 191 |
rc += rc_easy_inst |
193 | 192 |
out += out_easy_inst |
... | ... |
@@ -364,7 +364,6 @@ lib/ansible/modules/notification/slack.py |
364 | 364 |
lib/ansible/modules/notification/twilio.py |
365 | 365 |
lib/ansible/modules/packaging/language/bundler.py |
366 | 366 |
lib/ansible/modules/packaging/language/cpanm.py |
367 |
-lib/ansible/modules/packaging/language/easy_install.py |
|
368 | 367 |
lib/ansible/modules/packaging/language/gem.py |
369 | 368 |
lib/ansible/modules/packaging/language/maven_artifact.py |
370 | 369 |
lib/ansible/modules/packaging/language/pear.py |