-
Notifications
You must be signed in to change notification settings - Fork 23.8k
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
Report fact exceptions 25365 #25708
Report fact exceptions 25365 #25708
Conversation
If setup.py encounters an exception while running a fact collector, the default (fail_on_error=False) is to not consider that a fatal error. In that case, all collectors will run, and any exceptions found will be collected in 'ansible_facts_exceptions' and returned in the 'facts_exceptions' return value. If 'fail_on_error=True', the module will return a failure (fail_json()). The 'ansible_facts_exceptions' and 'facts_exceptions' return value will still have the list of exceptions encounterd. The first exception in the list will be returned as the 'exception' return value so callback plugins can display it. This is provided to aid in debugging fact collection errors. Fixes #25365
Example sections of facts output of 'ansible localhost -m setup' (default fail_on_error behavior) "ansible_facts_exceptions": [
{
"collector_name": "env",
"error_message": "Just a test exception from env fact collector",
"traceback": "Traceback (most recent call last):\n File \"/home/adrian/debug_dir/ansible_module_setup.py\", line 180, in collect\n collected_facts=collected_facts)\n File \"/home/adrian/debug_dir/ansible/module_utils/facts/collector.py\", line 68, in collect_with_namespace\n facts_dict = self.collect(module=module, collected_facts=collected_facts)\n File \"/home/adrian/debug_dir/ansible/module_utils/facts/system/env.py\", line 34, in collect\n raise Exception(\"Just a test exception from env fact collector\")\nException: Just a test exception from env fact collector\n"
},
{
"collector_name": "local",
"error_message": "division by zero",
"traceback": "Traceback (most recent call last):\n File \"/home/adrian/debug_dir/ansible_module_setup.py\", line 180, in collect\n collected_facts=collected_facts)\n File \"/home/adrian/debug_dir/ansible/module_utils/facts/collector.py\", line 68, in collect_with_namespace\n facts_dict = self.collect(module=module, collected_facts=collected_facts)\n File \"/home/adrian/debug_dir/ansible/module_utils/facts/system/local.py\", line 40, in collect\n 37/0\nZeroDivisionError: division by zero\n"
}
], |
Example output for: ansible localhost -m setup -a 'fail_on_error=True'
|
Example output of: ansible localhost -m setup -a 'fail_on_error=False'
|
i would add 2nd toggle to return all exceptions, the default is would be not to fail on many of the errors (this varied in previous code) ... facts are normally big/slow enough to not add tons of normally unused exception output to results |
The test
|
It doesn't test fail_on_error=true with collector exceptions yet though.
The test
|
cc @david_obrien |
Hi @alikins, going through backlog and saw this was quite out of date. Per discussion we're going to close this and add a future project to re-evaluate how we handle this problem. Thanks! |
SUMMARY
ISSUE TYPE
COMPONENT NAME
lib/ansible/modules_utils/facts/system/setup.py
ANSIBLE VERSION
ADDITIONAL INFORMATION
Example output when running 'ansible -vvv localhost -m setup.py -a fail_on_error=True' where the 'local' facts collector hits a divide-by-zero