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

custom lookup plugin found with ansible-doc but not found in playbook #66464

Closed
philbert opened this issue Jan 14, 2020 · 4 comments · Fixed by #66521
Closed

custom lookup plugin found with ansible-doc but not found in playbook #66464

philbert opened this issue Jan 14, 2020 · 4 comments · Fixed by #66521
Labels
affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. python3 support:community This issue/PR relates to code supported by the Ansible community.

Comments

@philbert
Copy link

SUMMARY

Custom lookup plugin appears correctly configured using ansible-doc -t lookup listFolders however always results in FAILED! => {"msg": "lookup plugin (listFolders) not found"} when used in playbook.

ISSUE TYPE
  • Bug Report
COMPONENT NAME
  • Custom lookup plugin
ANSIBLE VERSION
ansible 2.9.2
  config file = /Users/xxxx/.ansible.cfg
  configured module search path = ['/Users/xxxx/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/2.9.2_1/libexec/lib/python3.8/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.8.1 (default, Dec 27 2019, 18:05:45) [Clang 11.0.0 (clang-1100.0.33.16)]
CONFIGURATION
defaults only
OS / ENVIRONMENT
  • macOS Mojave 10.14.6
  • zsh 5.3 (x86_64-apple-darwin18.0)
STEPS TO REPRODUCE

Here is a trivial custom lookup plugin that just contains documentation to test my configuration.
It is placed in /Users/xxxx/.ansible/plugins/lookup/listFolders.py

DOCUMENTATION = """
    lookup: listFolders
    short_description: returns list from yaml descriptor
    description:
        - This lookup returns a list from the yaml descriptor
"""

This command correctly pics up the lookup plugin:
ansible-doc -t lookup listFolders

And shows the output:

> LISTFOLDERS    (/Users/xxxx/.ansible/plugins/lookup/listFolders.py)

        This lookup returns a list from the yaml descriptor

  * This module is maintained by The Ansible Community
        METADATA:
          status:
          - preview
          supported_by: community

However in a playbook I always hit this error:
fatal: [localhost]: FAILED! => {"msg": "lookup plugin (listFolders) not found"}

Here is a sample playbook that produces the error:

---
- name: "Test custom lookup plugin"
  hosts: localhost
  tasks:
    - name: lookup listFolders
      debug:
        msg: '{{ lookup("listFolders") }}'

EXPECTED RESULTS
TASK [lookup listFolders] ***************************************************************************************************************************************************************
ok: [localhost]
ACTUAL RESULTS
TASK [lookup listFolders] ***************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"msg": "lookup plugin (listFolders) not found"}
> ansible-playbook testplaybook.yml 

[WARNING]: No inventory was parsed, only implicit localhost is available

[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'


PLAY [Test custom lookup plugin] ************************************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************************************************************************************
ok: [localhost]

TASK [lookup listFolders] ***************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"msg": "lookup plugin (listFolders) not found"}

PLAY RECAP ******************************************************************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
@ansibot
Copy link
Contributor

ansibot commented Jan 14, 2020

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot ansibot added affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. 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 Jan 14, 2020
@mkrizek
Copy link
Contributor

mkrizek commented Jan 14, 2020

Doing with_listFolders: finds the lookup plugin correctly (of course failing then with The error was: AttributeError: module 'ansible.plugins.lookup.listFolders' has no attribute 'LookupModule').

For "{{ lookup("listFolders", ...) }}", loading the plugin appears to be case sensitive. The following change will make the loader find the plugin:

diff --git a/lib/ansible/template/__init__.py b/lib/ansible/template/__init__.py
index 062c4d6889..7cea02bc77 100644
--- a/lib/ansible/template/__init__.py
+++ b/lib/ansible/template/__init__.py
@@ -749,7 +749,7 @@ class Templar:
         return self._lookup(name, *args, **kwargs)
 
     def _lookup(self, name, *args, **kwargs):
-        instance = self._lookup_loader.get(name.lower(), loader=self._loader, templar=self)
+        instance = self._lookup_loader.get(name, loader=self._loader, templar=self)
 
         if instance is not None:
             wantlist = kwargs.pop('wantlist', False)

Having said that I am not sure as to why the behavior is different for each of the above or if it is intended.

@philbert
Copy link
Author

Yes, it was a case sensitivity issue. I confirmed that changing the file name to listfolders.py allowed my playbook to pick up the plugin correctly.

It looks to me that your fix would bring consistency to all 3 functions: with_*, lookup() and ansible-doc?

Thanks for the quick response!

@bcoca
Copy link
Member

bcoca commented Jan 15, 2020

all 3 should be case sensitive, seems with_ lookup is not.

mkrizek added a commit to mkrizek/ansible that referenced this issue Jan 16, 2020
This brings consistency to lookup(), with_ and ansible-doc.

Fixes ansible#66464
samdoran pushed a commit that referenced this issue Jan 27, 2020
This brings consistency to lookup(), with_ and ansible-doc.

Fixes #66464

* Add a porting guide entry
@sivel sivel removed the needs_triage Needs a first human triage before being processed. label Jan 28, 2020
@ansible ansible locked and limited conversation to collaborators Feb 24, 2020
ruozeng-w pushed a commit to ruozeng-w/ansible that referenced this issue Apr 18, 2020
This brings consistency to lookup(), with_ and ansible-doc.

Fixes ansible#66464

* Add a porting guide entry
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. 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.

5 participants