-
Notifications
You must be signed in to change notification settings - Fork 23.7k
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
ansible-inventory gives extra error text from openstack plugin, making it non-parsable #50100
Comments
Or you can filter out 'non-json' output https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/json_utils.py#L32 |
That method will still not give valid JSON in all cases because it appends a warning to the end. I put up a proposed workaround in AWX. If that is accepted, then we won't need any changes here. |
Also, in the method you linked to... # Filter trailing junk
lines = lines[start:] I think this is filtering the leading junk. The trailing junk is dealt with in latter code. |
This is still quite a problem, because spitting on our side seems unlikely to be accepted. I have argued that we need some form of splitting to use the verbosity flag as well (absolutely necessary for plugin use), but there is no clear plan for that right now. We could consider a workaround specific to this problem. Here is the stack trace getting to that warning.
Code bits in question: ansible/lib/ansible/plugins/inventory/openstack.py Lines 196 to 197 in bafc1f8
This suggests that using Looking at this, I'm was not optimistic that it can be resolved in the inventory plugin code. The error logs seem to be an implementation detail within the library. The plugin could try to adjust the python logging configuration. That is somewhat complicated by the fact that they use their own logging utilities, However, once I got pdb shell and looked, I saw a big honking |
@AlanCoding: Greetings! Thanks for taking the time to open this issue. In order for the community to handle your issue effectively, we need a bit more information. Here are the items we could not find in your description:
Please set the description of this issue with this template: |
SUMMARY
Cannot properly use
ansible-inventory
with inventory files that use the openstack inventory plugin.ISSUE TYPE
COMPONENT NAME
lib/ansible/cli/inventory.py
lib/ansible/plugins/inventory/openstack.py
ANSIBLE VERSION
CONFIGURATION
OS / ENVIRONMENT
Mac, in inventory loading. Dependency for plugin:
openstacksdk==0.19.0
STEPS TO REPRODUCE
Create an
openstack.yml
file and aclouds.yaml
file that gives auth information for a real OpenStack server. Documented at:https://docs.ansible.com/ansible/2.7/plugins/inventory/openstack.html
My own, more detailed, personal example:
https://github.com/AlanCoding/Ansible-inventory-file-examples/tree/master/plugins/example_openstack
Then run
EXPECTED RESULTS
JSON outputed to stdout
Other information going to stderr is okay with me.
ACTUAL RESULTS
I have extra messages, which go to stdout
The ultimate culprit is at:
https://github.com/openstack/openstacksdk/blob/9675c1fb0b065017a0fadf75f52d8193cce7dd24/openstack/config/cloud_region.py#L583-L604
Here is the call stack and traceback:
This problem could be addressed by the client library, but this is hideously complicated to dive into that. We could somehow turn down the log level, but it's a high custom implementation and there's a lot of class instantiations it gets passed around to. Or, something could have the smarts to not call this method if it's not applicable given the input data. That would be on the client library side, and not the code inside the openstack inventory plugin.
Alternatively (and I think this is most reasonable solution), either the inventory plugin or
ansible-inventory
itself should redirect stdout while a 3rd party library is being called, because we can't trust that library to not write to stdout.Having this content in stdout means that we can't parse the output from
ansible-inventory
with the stock python JSON library.The text was updated successfully, but these errors were encountered: