From 9468a65bed2ec4acf9bf6c8bd26abe96a0804153 Mon Sep 17 00:00:00 2001 From: Schlueter Date: Wed, 20 May 2015 13:27:04 -0400 Subject: [PATCH 1/6] Add state to easy_install --- packaging/language/easy_install.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packaging/language/easy_install.py b/packaging/language/easy_install.py index 889a81f025a..b95cb1bb08e 100644 --- a/packaging/language/easy_install.py +++ b/packaging/language/easy_install.py @@ -89,8 +89,9 @@ EXAMPLES = ''' - easy_install: name=bottle virtualenv=/webapps/myapp/venv ''' -def _is_package_installed(module, name, easy_install): - cmd = '%s --dry-run %s' % (easy_install, name) +def _is_package_installed(module, name, easy_install, executable_arguments): + executable_arguments.append('--dry-run') + cmd = '%s %s %s' % (easy_install, ' '.join(executable_arguments), name) rc, status_stdout, status_stderr = module.run_command(cmd) return not ('Reading' in status_stdout or 'Downloading' in status_stdout) @@ -124,6 +125,10 @@ def _get_easy_install(module, env=None, executable=None): def main(): arg_spec = dict( name=dict(required=True), + state=dict(required=False, + default='present', + choices=['present','latest'], + type='str'), virtualenv=dict(default=None, required=False), virtualenv_site_packages=dict(default='no', type='bool'), virtualenv_command=dict(default='virtualenv', required=False), @@ -137,6 +142,8 @@ def main(): executable = module.params['executable'] site_packages = module.params['virtualenv_site_packages'] virtualenv_command = module.params['virtualenv_command'] + executable_arguments = [] + module.params['state'] is 'latest' and executable_arguments.append('--upgrade') rc = 0 err = '' @@ -167,7 +174,7 @@ def main(): if not installed: if module.check_mode: module.exit_json(changed=True) - cmd = '%s %s' % (easy_install, name) + cmd = '%s %s %s' % (easy_install, ' '.join(executable_arguments), name) rc_easy_inst, out_easy_inst, err_easy_inst = module.run_command(cmd) rc += rc_easy_inst From 9b6a7416155e26e939c7681cb2d61de900792ff3 Mon Sep 17 00:00:00 2001 From: Schlueter Date: Thu, 21 May 2015 12:04:13 -0400 Subject: [PATCH 2/6] Correct pass by object reference issue --- packaging/language/easy_install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/language/easy_install.py b/packaging/language/easy_install.py index b95cb1bb08e..6ae42b65967 100644 --- a/packaging/language/easy_install.py +++ b/packaging/language/easy_install.py @@ -90,7 +90,7 @@ EXAMPLES = ''' ''' def _is_package_installed(module, name, easy_install, executable_arguments): - executable_arguments.append('--dry-run') + executable_arguments = executable_arguments + ['--dry-run'] cmd = '%s %s %s' % (easy_install, ' '.join(executable_arguments), name) rc, status_stdout, status_stderr = module.run_command(cmd) return not ('Reading' in status_stdout or 'Downloading' in status_stdout) From 3bae8bda10854ebaea7daed53d07dfddbce30900 Mon Sep 17 00:00:00 2001 From: Schlueter Date: Thu, 21 May 2015 12:16:26 -0400 Subject: [PATCH 3/6] Use standard if statement to check state in easy_install resource --- packaging/language/easy_install.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packaging/language/easy_install.py b/packaging/language/easy_install.py index 6ae42b65967..635f1b64f3f 100644 --- a/packaging/language/easy_install.py +++ b/packaging/language/easy_install.py @@ -143,7 +143,8 @@ def main(): site_packages = module.params['virtualenv_site_packages'] virtualenv_command = module.params['virtualenv_command'] executable_arguments = [] - module.params['state'] is 'latest' and executable_arguments.append('--upgrade') + if module.params['state'] == 'latest': + executable_arguments.append('--upgrade') rc = 0 err = '' From 02cd8489c17556128b344c22b59eb4799ac84ebe Mon Sep 17 00:00:00 2001 From: Schlueter Date: Thu, 21 May 2015 12:23:05 -0400 Subject: [PATCH 4/6] Add Documentation --- packaging/language/easy_install.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packaging/language/easy_install.py b/packaging/language/easy_install.py index 635f1b64f3f..eaf16e6de92 100644 --- a/packaging/language/easy_install.py +++ b/packaging/language/easy_install.py @@ -70,6 +70,12 @@ options: version_added: "1.3" required: false default: null + state: + description: + - The desired state of the gem. C(latest) ensures that the latest version is installed. + required: false + choices: [present, latest] + default: present notes: - Please note that the M(easy_install) module can only install Python libraries. Thus this module is not able to remove libraries. It is @@ -83,7 +89,7 @@ author: Matt Wright EXAMPLES = ''' # Examples from Ansible Playbooks -- easy_install: name=pip +- easy_install: name=pip state=latest # Install Bottle into the specified virtualenv. - easy_install: name=bottle virtualenv=/webapps/myapp/venv From 17544062ec6fa4035538a11d030632cce3ad8d78 Mon Sep 17 00:00:00 2001 From: Schlueter Date: Thu, 21 May 2015 12:49:43 -0400 Subject: [PATCH 5/6] Correct reference to gem in easy_install resource --- packaging/language/easy_install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/language/easy_install.py b/packaging/language/easy_install.py index eaf16e6de92..e1924d0c160 100644 --- a/packaging/language/easy_install.py +++ b/packaging/language/easy_install.py @@ -72,7 +72,7 @@ options: default: null state: description: - - The desired state of the gem. C(latest) ensures that the latest version is installed. + - The desired state of the library. C(latest) ensures that the latest version is installed. required: false choices: [present, latest] default: present From 1030cb48a793fe685f55c283933f82f4afb014e3 Mon Sep 17 00:00:00 2001 From: Schlueter Date: Thu, 21 May 2015 12:54:48 -0400 Subject: [PATCH 6/6] Add 'version_added' to state documentation for easy_install resource --- packaging/language/easy_install.py | 1 + 1 file changed, 1 insertion(+) diff --git a/packaging/language/easy_install.py b/packaging/language/easy_install.py index e1924d0c160..77efeae797f 100644 --- a/packaging/language/easy_install.py +++ b/packaging/language/easy_install.py @@ -71,6 +71,7 @@ options: required: false default: null state: + version_added: "2.0" description: - The desired state of the library. C(latest) ensures that the latest version is installed. required: false