Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

elasticsearch_plugin fails when plugin_bin is None #31824

Closed
andriilahuta opened this issue Oct 17, 2017 · 1 comment · Fixed by #31845
Closed

elasticsearch_plugin fails when plugin_bin is None #31824

andriilahuta opened this issue Oct 17, 2017 · 1 comment · Fixed by #31845
Assignees
Labels
affects_2.5 This issue/PR affects Ansible v2.5 bug This issue/PR relates to a bug. module This issue/PR relates to a module. python3 support:community This issue/PR relates to code supported by the Ansible community.

Comments

@andriilahuta
Copy link
Contributor

ISSUE TYPE
  • Bug Report
COMPONENT NAME

elasticsearch_plugin module

ANSIBLE VERSION
Latest ansible devel:
ansible 2.5.0
  config file = 
  configured module search path = 
  ansible python module location = /usr/local/lib/python3.5/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.5.2 (default, Sep 14 2017, 22:51:06) [GCC 5.4.0 20160609]
CONFIGURATION

None

OS / ENVIRONMENT

Ubuntu, Elasticsearch 6.x beta

SUMMARY

elasticsearch_plugin raises UnboundLocalError: local variable 'valid_plugin_bin' referenced before assignment when called with default plugin_bin arg (which is None).

The problem lies in the get_plugin_bin function: it does nothing when plugin_bin is None, but still tries to check valid_plugin_bin at the end.

Applying the following patch seems to resolve the issue.

@@ -198,28 +198,27 @@ def remove_plugin(module, plugin_bin, plugin_name):
 
 def get_plugin_bin(module, plugin_bin):
     # Use the plugin_bin that was supplied first before trying other options
-    if plugin_bin:
-        if os.path.isfile(plugin_bin):
-            valid_plugin_bin = plugin_bin
-
-        else:
-            # Add the plugin_bin passed into the module to the top of the list of paths to test,
-            # testing for that binary name first before falling back to the default paths.
-            bin_paths = list(PLUGIN_BIN_PATHS)
-            if plugin_bin and plugin_bin not in bin_paths:
-                bin_paths.insert(0, plugin_bin)
-
-            # Get separate lists of dirs and binary names from the full paths to the
-            # plugin binaries.
-            plugin_dirs = list(set([os.path.dirname(x) for x in bin_paths]))
-            plugin_bins = list(set([os.path.basename(x) for x in bin_paths]))
-
-            # Check for the binary names in the default system paths as well as the path
-            # specified in the module arguments.
-            for bin_file in plugin_bins:
-                valid_plugin_bin = module.get_bin_path(bin_file, opt_dirs=plugin_dirs)
-                if valid_plugin_bin:
-                    break
+    if plugin_bin and os.path.isfile(plugin_bin):
+        valid_plugin_bin = plugin_bin
+
+    else:
+        # Add the plugin_bin passed into the module to the top of the list of paths to test,
+        # testing for that binary name first before falling back to the default paths.
+        bin_paths = list(PLUGIN_BIN_PATHS)
+        if plugin_bin and plugin_bin not in bin_paths:
+            bin_paths.insert(0, plugin_bin)
+
+        # Get separate lists of dirs and binary names from the full paths to the
+        # plugin binaries.
+        plugin_dirs = list(set([os.path.dirname(x) for x in bin_paths]))
+        plugin_bins = list(set([os.path.basename(x) for x in bin_paths]))
+
+        # Check for the binary names in the default system paths as well as the path
+        # specified in the module arguments.
+        for bin_file in plugin_bins:
+            valid_plugin_bin = module.get_bin_path(bin_file, opt_dirs=plugin_dirs)
+            if valid_plugin_bin:
+                break
 
     if not valid_plugin_bin:
         module.fail_json(msg='%s does not exist and no other valid plugin installers were found. Make sure Elasticsearch is installed.' % plugin_bin)
STEPS TO REPRODUCE
- name: Install Elasticsearch plugins
  elasticsearch_plugin:
    name: '{{ item }}'
    state: present
  with_items: '{{ elasticsearch_plugins }}'
  notify: restart elasticsearch
EXPECTED RESULTS

It would install plugins from {{ elasticsearch_plugins }}

ACTUAL RESULTS
{"changed": false, "failed": true, "item": "ingest-user-agent", "module_stderr": "Shared connection to ... closed.\r\n", "module_stdout": "\r\n\r\nTraceback (most recent call last):\r\n  File \"/tmp/ansible_6cufn7rd/ansible_module_elasticsearch_plugin.py\", line 276, in <module>\r\n    main()\r\n  File \"/tmp/ansible_6cufn7rd/ansible_module_elasticsearch_plugin.py\", line 258, in main\r\n    plugin_bin = get_plugin_bin(module, plugin_bin)\r\n  File \"/tmp/ansible_6cufn7rd/ansible_module_elasticsearch_plugin.py\", line 225, in get_plugin_bin\r\n    if not valid_plugin_bin:\r\nUnboundLocalError: local variable 'valid_plugin_bin' referenced before assignment\r\n1------- None\r\n", "msg": "MODULE FAILURE", "rc": 0}
@ansibot
Copy link
Contributor

ansibot commented Oct 17, 2017

@ansibot ansibot added affects_2.5 This issue/PR affects Ansible v2.5 bug_report module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. python3 support:community This issue/PR relates to code supported by the Ansible community. labels Oct 17, 2017
@samdoran samdoran self-assigned this Oct 17, 2017
@samdoran samdoran removed the needs_triage Needs a first human triage before being processed. label Oct 17, 2017
@samdoran samdoran added this to Nominated in 2.4.x Blocker List Oct 17, 2017
samdoran added a commit to samdoran/ansible that referenced this issue Oct 17, 2017
@abadger abadger removed this from Nominated in 2.4.x Blocker List Oct 17, 2017
abadger pushed a commit that referenced this issue Oct 18, 2017
Fixes #31824

(cherry picked from commit 2c8382e)
abadger pushed a commit that referenced this issue Oct 18, 2017
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.5 This issue/PR affects Ansible v2.5 bug This issue/PR relates to a bug. module This issue/PR relates to a module. python3 support:community This issue/PR relates to code supported by the Ansible community.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants