Is there an elegant way to ensure that pip dependencies are installed when writing Ansible lookup plugins?

trevor
Thu, 12 Oct 2023 11:39:51 +0000
Get Help

I’m writing an Ansible lookup plugin that pulls secrets from a secret source and inserts them as variables into Ansible playbooks. I was trying to figure out if there’s a way to have any of the pip dependencies installed automatically for the user before they try to run the plugin.

For instance, the top of my plugin looks something like this:

# [...licence stuff...]
from __future__ import absolute_import, division, print_function

__metaclass__ = type

from ansible.plugins.lookup import LookupBase
from ansible.errors import AnsibleError

import some_super_niche_sdk

I’d like to have some_super_niche_sdk automatically installed so that the plugin just works when they run a playbook that uses it.

I’ve searched the developer docs as well as the singular and plural form of “dependency” here in the Ansible forums and wasn’t able to find an answer.

Based the lack of an affirmative answer for simple dependency handling at install-time, I’m guessing that the user is just expected to read the “module not found” error from Python and install the dependency manually, but I wanted to see if this problem has been solved by a more experienced Ansible dev before packaging the plugin with that assumption.

Thanks in advance.

6 posts - 4 participants