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

make gettting options with falback simpler #82547

Draft
wants to merge 2 commits into
base: devel
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/ansible/plugins/__init__.py
Expand Up @@ -90,6 +90,21 @@ def get_options(self, hostvars=None):
options[option] = self.get_option(option, hostvars=hostvars)
return options

def get_ff_option(self, *options, hostvars=None, pc=None):
''' convinience function for when plugins have not followed strict conventions (user/remote_user)
and/or relied on playcontext, which is not strictly up2date, specially in loops. '''
bcoca marked this conversation as resolved.
Show resolved Hide resolved
for option in options:
if self.has_option(option):
return self.get_option(option, hostvars)

# fallback to play context
if pc is not None:
for option in options:
if hasattr(pc, option):
return getattr(pc, option)

raise KeyError("The %s plugin '%s' does not support any of these options: %s" % (self.plugin_type, self._load_name, ', '.join(options))
bcoca marked this conversation as resolved.
Show resolved Hide resolved

def set_option(self, option, value):
self._options[option] = C.config.get_config_value(option, plugin_type=self.plugin_type, plugin_name=self._load_name, direct={option: value})

Expand Down