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

exclude lookup_terms from config errors #41740

Merged
merged 5 commits into from
Jun 21, 2018
Merged

Conversation

bcoca
Copy link
Member

@bcoca bcoca commented Jun 20, 2018

SUMMARY
ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

config
plugins/lookup

ANSIBLE VERSION
>=2.6

@ansibot ansibot added affects_2.7 This issue/PR affects Ansible v2.7 bug This issue/PR relates to a bug. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Jun 20, 2018
@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label Jun 20, 2018
@sivel
Copy link
Member

sivel commented Jun 20, 2018

I can confirm at minimum that this resolves #41696

@ansibot ansibot added the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. label Jun 20, 2018
Copy link
Contributor

@s-hertel s-hertel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting weird behavior for required options in lookups but it doesn't seem like it's due to this. Also doesn't appear that any plugins are broken by it at the moment.

diff --git a/lib/ansible/plugins/lookup/vars.py b/lib/ansible/plugins/lookup/vars.py
index 9ce5d30467..8119f110f1 100644
--- a/lib/ansible/plugins/lookup/vars.py
+++ b/lib/ansible/plugins/lookup/vars.py
@@ -18,6 +18,9 @@ DOCUMENTATION = """
         description:
             - What to return if a variable is undefined.
             - If no default is set, it will result in an error if any of the variables is undefined.
+      test_req_options:
+        description: test required options
+        required: true

with or without the required option outputs

$ ansible -m debug -a msg="{{ lookup('vars', 'foobar', default='ok', test_req_options='test') }}" -c local localhost
 [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

localhost | FAILED! => {
    "msg": "An unhandled exception occurred while running the lookup plugin 'vars'. Error was a <class 'ansible.errors.AnsibleError'>, original message: Invalid settings supplied for test_req_options: No setting was provided for required configuration plugin_type: lookup plugin: vars setting: test_req_options "
}

(Actually, looks like on devel required: True just might be ignored for lookup plugins right now?)

@@ -365,7 +366,8 @@ def get_config_value_and_origin(self, config, cfile=None, plugin_type=None, plug
if plugin_name:
entry += 'plugin: %s ' % plugin_name
entry += 'setting: %s ' % config
raise AnsibleError("No setting was provided for required configuration %s" % (entry))
if not plugin_type or config not in INTERNAL_DEFS.get(plugin_type):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INTERNAL_DEFS.get(plugin_type, ()) since Nonetype isn't iterable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't get that error, weird since it is defined on top in same file .... and plugin_type is not used if None

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got that error using an inventory plugin, not a lookup.

@bcoca
Copy link
Member Author

bcoca commented Jun 20, 2018

the other behaviour is because of how i pass 'direct' ... its a bug

@bcoca
Copy link
Member Author

bcoca commented Jun 20, 2018

try now, that should fix 'direct processing'

if plugin_name:
entry += 'plugin: %s ' % plugin_name
entry += 'setting: %s ' % config
if not plugin_type or config not in INTERNAL_DEFS.get(plugin_type):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Causes unhelpful error if get() returns None

$ cat nmap_inv.yml
plugin: nmap

$ ansible-inventory -i nmap_inv.yml --graph
ERROR! Invalid settings supplied for address: argument of type 'NoneType' is not iterable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, misunderstood your prev comment

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushing fix, good catch

@ansible ansible deleted a comment from ansibot Jun 20, 2018
@s-hertel
Copy link
Contributor

Looks good to me, shipit

@ansibot ansibot added shipit This PR is ready to be merged by Core and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Jun 20, 2018
@bcoca bcoca merged commit 0102e42 into ansible:devel Jun 21, 2018
@bcoca bcoca deleted the lookup_terms_fix branch June 21, 2018 21:51
bcoca added a commit to bcoca/ansible that referenced this pull request Jun 21, 2018
* exclude lookup_terms from config errors
* moved direct

(cherry picked from commit 0102e42)
mattclay pushed a commit that referenced this pull request Jun 22, 2018
* exclude lookup_terms from config errors
* moved direct

(cherry picked from commit 0102e42)
jacum pushed a commit to jacum/ansible that referenced this pull request Jun 26, 2018
* exclude lookup_terms from config errors
* moved direct
kbreit pushed a commit to kbreit/ansible that referenced this pull request Jul 3, 2018
* exclude lookup_terms from config errors
* moved direct

(cherry picked from commit 0102e42)
@ansible ansible locked and limited conversation to collaborators Jun 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.7 This issue/PR affects Ansible v2.7 bug This issue/PR relates to a bug. shipit This PR is ready to be merged by Core support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants