Fixes #31824
(cherry picked from commit 2c8382eb87a8ae2f308daa3b71673063583ec0db)
... | ... |
@@ -196,30 +196,30 @@ def remove_plugin(module, plugin_bin, plugin_name): |
196 | 196 |
return True, cmd, out, err |
197 | 197 |
|
198 | 198 |
|
199 |
-def get_plugin_bin(module, plugin_bin): |
|
199 |
+def get_plugin_bin(module, plugin_bin=None): |
|
200 | 200 |
# Use the plugin_bin that was supplied first before trying other options |
201 |
- if plugin_bin: |
|
202 |
- if os.path.isfile(plugin_bin): |
|
203 |
- valid_plugin_bin = plugin_bin |
|
204 |
- |
|
205 |
- else: |
|
206 |
- # Add the plugin_bin passed into the module to the top of the list of paths to test, |
|
207 |
- # testing for that binary name first before falling back to the default paths. |
|
208 |
- bin_paths = list(PLUGIN_BIN_PATHS) |
|
209 |
- if plugin_bin and plugin_bin not in bin_paths: |
|
210 |
- bin_paths.insert(0, plugin_bin) |
|
211 |
- |
|
212 |
- # Get separate lists of dirs and binary names from the full paths to the |
|
213 |
- # plugin binaries. |
|
214 |
- plugin_dirs = list(set([os.path.dirname(x) for x in bin_paths])) |
|
215 |
- plugin_bins = list(set([os.path.basename(x) for x in bin_paths])) |
|
216 |
- |
|
217 |
- # Check for the binary names in the default system paths as well as the path |
|
218 |
- # specified in the module arguments. |
|
219 |
- for bin_file in plugin_bins: |
|
220 |
- valid_plugin_bin = module.get_bin_path(bin_file, opt_dirs=plugin_dirs) |
|
221 |
- if valid_plugin_bin: |
|
222 |
- break |
|
201 |
+ valid_plugin_bin = None |
|
202 |
+ if plugin_bin and os.path.isfile(plugin_bin): |
|
203 |
+ valid_plugin_bin = plugin_bin |
|
204 |
+ |
|
205 |
+ else: |
|
206 |
+ # Add the plugin_bin passed into the module to the top of the list of paths to test, |
|
207 |
+ # testing for that binary name first before falling back to the default paths. |
|
208 |
+ bin_paths = list(PLUGIN_BIN_PATHS) |
|
209 |
+ if plugin_bin and plugin_bin not in bin_paths: |
|
210 |
+ bin_paths.insert(0, plugin_bin) |
|
211 |
+ |
|
212 |
+ # Get separate lists of dirs and binary names from the full paths to the |
|
213 |
+ # plugin binaries. |
|
214 |
+ plugin_dirs = list(set([os.path.dirname(x) for x in bin_paths])) |
|
215 |
+ plugin_bins = list(set([os.path.basename(x) for x in bin_paths])) |
|
216 |
+ |
|
217 |
+ # Check for the binary names in the default system paths as well as the path |
|
218 |
+ # specified in the module arguments. |
|
219 |
+ for bin_file in plugin_bins: |
|
220 |
+ valid_plugin_bin = module.get_bin_path(bin_file, opt_dirs=plugin_dirs) |
|
221 |
+ if valid_plugin_bin: |
|
222 |
+ break |
|
223 | 223 |
|
224 | 224 |
if not valid_plugin_bin: |
225 | 225 |
module.fail_json(msg='%s does not exist and no other valid plugin installers were found. Make sure Elasticsearch is installed.' % plugin_bin) |