Remove plugin
option from inventory config for compatibility with passthrough plugins
#674
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
One niche but useful feature of Ansible inventory plugins is the ability to call one plugin from another. For example, you can write a custom plugin (
my.plugin.multi_cloud
) that acts as a sort of normalization interface between project inventories deployed on multiple cloud platforms. This makes it feasible to create a single set of Ansible Playbooks that can act on hosts across cloud platforms because they can expect managed node (inventory host) data to be consistent across those cloud platform vendors.For example,
my.plugin.multi_cloud
inventory plugin might look something like the following code, which simply dynamically loads one or another underlying (upstream) vendor'ed inventory plugins based on the value of the shell environment variable calledCLOUD_PLATFORM
:In the above example, we see code loading either this
google.cloud.gcp_compute
inventory plugin or Amazon'samazon.aws.aws_ec2
inventory plugin.Later, we can invoke the underlying (upstream) plugin in a passthrough manner like this:
However, in order for this to work, we must supply the underlying plugin with knowledge of the fact that we are calling it from a different actual plugin. This is facilitated via Ansible's built in
_redirected_names
class property. Before calling the underlying plugin'sparse()
method, we must first do:Now the underlying plugin will be permitted to run because the underlying plugin is informing Ansible that one of the names it is permitted to use is this "redirected" (aliased) name of the calling plugin. We have effectively monkey-patched the plugin during runtime, which is exactly what we want.
Unfortunately, for this
google.cloud.gcp_compute
inventory plugin, that's not enough, because of the fact that theplugin
option in its configuration file is also checked and compared against this same name. That's something that, for example, theamazon.aws.aws_ec2
inventory plugin doesn't do, and for good reason: enforcing this check with hardcoded options breaks the built-in functionality of the Ansible module loading alias features.That's why I'm suggesting we remove this option. It isn't needed for the
auto
inventory plugin to load the plugin correctly, nor does it ever really need to be checked once this plugin is actually running; it's already running! But its presence does break existing Ansible features, and makes the above use case of a pass-through plugin, for example, infeasible.Thanks for considering this proposal.
SUMMARY
ISSUE TYPE
COMPONENT NAME
ADDITIONAL INFORMATION