# Help with using a lookup plugin from a collection

**URL:** <https://forum.ansible.com/t/help-with-using-a-lookup-plugin-from-a-collection/3490>\
**Category:** Get Help\
**Tags:** dev, plugin, collections, galaxy-ng\
**Created:** [January 26, 2024, 7:03pm UTC](https://forum.ansible.com/t/help-with-using-a-lookup-plugin-from-a-collection/3490 "2024-01-26T19:03:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![trevor](https://avatars.discourse-cdn.com/v4/letter/t/258eb7/32.png) [@trevor](https://forum.ansible.com/u/trevor)\
**Post date:** [January 26, 2024, 7:03pm UTC](https://forum.ansible.com/t/help-with-using-a-lookup-plugin-from-a-collection/3490/1 "2024-01-26T19:03:41Z")

</div>

Hello 👋

Apologies in advance if this is a super basic question, but I’ve been struggling with getting this to work the way I want it to for a while.

I am developing an Ansible lookup plugin for internal use at my company. We have a Galaxy API server that I am supposed to upload it to. My collection that contains the lookup plugin looks like the following:

```bash
├── README.md
├── examples
│ └── test.yml
└── plugins
    └── lookup
        └── my_plugin.py
└── galaxy.yml

```

I can build and install the collection just fine. It installs to `$HOME/.ansible/collections/my_namespace/my_collection_name`.

Here is a sample of how I’m trying to use the lookup plugin from a playbook:

```yaml
---
- name: A test playbook
  hosts: localhost
  gather_facts: false
  collections:
    - my_namespace.my_collection_name

  vars:
    some_var_from_my_plugin: "{{ lookup('my_plugin', 'the_var_im_looking_for') }}"

# ...

```

However, I always get this error:

```auto
fatal: [localhost]: FAILED! => {"msg": "An unhandled exception occurred while templating '{{ lookup('my_plugin', 'the_var_im_looking_for') }}'. Error was a <class 'ansible.errors.AnsibleError'>, original message: lookup plugin (my_plugin) not found"}

```

I can work around this if I set the following in my `ansible.cfg` file, but this isn’t a practical solution for how other users in the org will be using it:

```ini
[defaults]
lookup_plugins = /path/to/my/home/.ansible/collections/my_namespace/my_collection_name/plugins/lookup

```

What is the correct way to invoke a lookup plugin from a collection?

---

<div class="post-metadata">

**Author:** ![akira6592](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akira6592/32/222_2.png) [@akira6592](https://forum.ansible.com/u/akira6592)\
**Post date:** [January 27, 2024, 1:15am UTC](https://forum.ansible.com/t/help-with-using-a-lookup-plugin-from-a-collection/3490/2 "2024-01-27T01:15:06Z")

</div>

@trevor

Hello.

In this case, the `collections` keyword may not work.

How about using FQCN as follow?

```yaml
    some_var_from_my_plugin: "{{ lookup('my_namespace.my_collection_name.my_plugin', 'the_var_im_looking_for') }}"

```

See also:

[https://docs.ansible.com/ansible/latest/collections\_guide/collections\_using\_playbooks.html#using-collections-in-playbooks](https://docs.ansible.com/ansible/latest/collections_guide/collections_using_playbooks.html#using-collections-in-playbooks)

> Note that an FQCN is still required for non-action or module plugins (for example, lookups, filters, and tests).

---

<div class="post-metadata">

**Author:** ![trevor](https://avatars.discourse-cdn.com/v4/letter/t/258eb7/32.png) [@trevor](https://forum.ansible.com/u/trevor)\
**Post date:** [January 28, 2024, 4:49pm UTC](https://forum.ansible.com/t/help-with-using-a-lookup-plugin-from-a-collection/3490/3 "2024-01-28T16:49:23Z")

</div>

Thank you! I’ll give this a try tomorrow.

---

<div class="post-metadata">

**Author:** ![trevor](https://avatars.discourse-cdn.com/v4/letter/t/258eb7/32.png) [@trevor](https://forum.ansible.com/u/trevor)\
**Post date:** [January 29, 2024, 12:55pm UTC](https://forum.ansible.com/t/help-with-using-a-lookup-plugin-from-a-collection/3490/4 "2024-01-29T12:55:58Z")

</div>

Yep. That did it. Thank you!

---

<div class="post-metadata">

**Author:** ![akira6592](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akira6592/32/222_2.png) [@akira6592](https://forum.ansible.com/u/akira6592)\
**Post date:** [January 29, 2024, 1:04pm UTC](https://forum.ansible.com/t/help-with-using-a-lookup-plugin-from-a-collection/3490/5 "2024-01-29T13:04:58Z")

</div>

My pleasure 😀

I’m glad it went well.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [February 28, 2024, 1:05pm UTC](https://forum.ansible.com/t/help-with-using-a-lookup-plugin-from-a-collection/3490/6 "2024-02-28T13:05:09Z")

</div>

Closed on February 28, 2024, 1:05pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
