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:
βββ 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:
---
- 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:
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:
[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?