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

Report fact exceptions 25365 #25708

Closed
wants to merge 5 commits into from
Closed

Report fact exceptions 25365 #25708

wants to merge 5 commits into from

Conversation

alikins
Copy link
Contributor

@alikins alikins commented Jun 14, 2017

SUMMARY
Add a 'fail_on_error' option to setup.py and set a 'ansible_facts_exceptions' with any fact collector exceptions.

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
ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

lib/ansible/modules_utils/facts/system/setup.py

ANSIBLE VERSION
ansible 2.4.0 (report_fact_exceptions_25365 2960a510a6) last updated 2017/06/14 12:45:40 (GMT -400)
  config file = None
  configured module search path = [u'/home/adrian/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/adrian/src/ansible/lib/ansible
  executable location = /home/adrian/src/ansible/bin/ansible
  python version = 2.7.13 (default, May 10 2017, 20:04:28) [GCC 6.3.1 20161221 (Red Hat 6.3.1-1)]


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

The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_chVxqA/ansible_module_setup.py", line 180, in collect
    collected_facts=collected_facts)
  File "/tmp/ansible_chVxqA/ansible_modlib.zip/ansible/module_utils/facts/collector.py", line 68, in collect_with_namespace
    facts_dict = self.collect(module=module, collected_facts=collected_facts)
  File "/tmp/ansible_chVxqA/ansible_modlib.zip/ansible/module_utils/facts/system/env.py", line 34, in collect
    raise Exception("Just a test exception from env fact collector")
Exception: Just a test exception from env fact collector

localhost | FAILED! => {
    "changed": false, 
    "facts_exceptions": [
        {
            "collector_name": "env", 
            "error_message": "Just a test exception from env fact collector", 
            "traceback": "Traceback (most recent call last):\n  File \"/tmp/ansible_chVxqA/ansible_module_setup.py\", line 180, in collect\n    collected_facts=collected_facts)\n  File \"/tmp/ansible_chVxqA/ansible_modlib.zip/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 \"/tmp/ansible_chVxqA/ansible_modlib.zip/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 \"/tmp/ansible_chVxqA/ansible_module_setup.py\", line 180, in collect\n    collected_facts=collected_facts)\n  File \"/tmp/ansible_chVxqA/ansible_modlib.zip/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 \"/tmp/ansible_chVxqA/ansible_modlib.zip/ansible/module_utils/facts/system/local.py\", line 40, in collect\n    37/0\nZeroDivisionError: division by zero\n"
        }
    ], 
    "failed": true, 
    "invocation": {
        "module_args": {
            "fact_path": "/etc/ansible/facts.d", 
            "fail_on_error": true, 
            "filter": "*", 
            "gather_subset": [
                "all"
            ], 
            "gather_timeout": 10
        }
    }, 
    "msg": "There was one or more exceptions while collecting facts and fail_on_error is True. The first exception is provided as the 'exception' return value."
}

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
@alikins
Copy link
Contributor Author

alikins commented Jun 14, 2017

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"
        }
    ], 

@alikins
Copy link
Contributor Author

alikins commented Jun 14, 2017

Example output for: ansible localhost -m setup -a 'fail_on_error=True'
(verbosity was default, so exception not shown like -vvv)

[newswoop:F25:ansible (report_fact_exceptions_25365 %)]$ ansible localhost -m setup -a 'fail_on_error=True'
 [WARNING]: No inventory was parsed, only implicit localhost is available

 [WARNING]: provided hosts list is empty, only localhost is available

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ZeroDivisionError: division by zero
localhost | FAILED! => {
    "changed": false, 
    "facts_exceptions": [
        {
            "collector_name": "local", 
            "error_message": "division by zero", 
            "traceback": "Traceback (most recent call last):\n  File \"/tmp/ansible_TbCY4V/ansible_module_setup.py\", line 189, in collect\n    collected_facts=collected_facts)\n  File \"/tmp/ansible_TbCY4V/ansible_modlib.zip/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 \"/tmp/ansible_TbCY4V/ansible_modlib.zip/ansible/module_utils/facts/system/local.py\", line 40, in collect\n    37/0\nZeroDivisionError: division by zero\n"
        }, 
        {
            "collector_name": "env", 
            "error_message": "Just a test exception from env fact collector", 
            "traceback": "Traceback (most recent call last):\n  File \"/tmp/ansible_TbCY4V/ansible_module_setup.py\", line 189, in collect\n    collected_facts=collected_facts)\n  File \"/tmp/ansible_TbCY4V/ansible_modlib.zip/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 \"/tmp/ansible_TbCY4V/ansible_modlib.zip/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"
        }
    ], 
    "failed": true, 
    "msg": "There was one or more exceptions while collecting facts and fail_on_error is True. The first exception is provided as the 'exception' return value."
}

@ansibot ansibot added affects_2.4 This issue/PR affects Ansible v2.4 bugfix_pull_request core_review In order to be merged, this PR must follow the core review workflow. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. labels Jun 14, 2017
@alikins
Copy link
Contributor Author

alikins commented Jun 14, 2017

Example output of: ansible localhost -m setup -a 'fail_on_error=False'
(fail_on_error=False is the default as well)


[newswoop:F25:ansible (report_fact_exceptions_25365 %)]$ ansible localhost -m setup -a 'fail_on_error=False'
 [WARNING]: No inventory was parsed, only implicit localhost is available

 [WARNING]: provided hosts list is empty, only localhost is available

localhost | SUCCESS => {
    "ansible_facts": {
        "ansible_all_ipv4_addresses": [
            "192.168.1.140", 
            "192.168.122.1", 
            "192.168.1.102"
        ], 

<  LOTS AND LOTS OF NORMAL FACTS CUT FOR SPACE >

        "gather_subset": [
            "all"
        ], 
        "module_setup": true
    }, 
    "ansible_facts_exceptions": [
        {
            "collector_name": "local", 
            "error_message": "division by zero", 
            "traceback": "Traceback (most recent call last):\n  File \"/tmp/ansible_wRem0r/ansible_module_setup.py\", line 189, in collect\n    collected_facts=collected_facts)\n  File \"/tmp/ansible_wRem0r/ansible_modlib.zip/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 \"/tmp/ansible_wRem0r/ansible_modlib.zip/ansible/module_utils/facts/system/local.py\", line 40, in collect\n    37/0\nZeroDivisionError: division by zero\n"
        }, 
        {
            "collector_name": "env", 
            "error_message": "Just a test exception from env fact collector", 
            "traceback": "Traceback (most recent call last):\n  File \"/tmp/ansible_wRem0r/ansible_module_setup.py\", line 189, in collect\n    collected_facts=collected_facts)\n  File \"/tmp/ansible_wRem0r/ansible_modlib.zip/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 \"/tmp/ansible_wRem0r/ansible_modlib.zip/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"
        }
    ], 
    "changed": false, 
    "failed": false
}

@bcoca
Copy link
Member

bcoca commented Jun 14, 2017

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

@ansibot ansibot added needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. test_pull_requests and removed needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. labels Jun 14, 2017
@ansibot
Copy link
Contributor

ansibot commented Jun 14, 2017

The test ansible-test sanity --test pep8 failed with the following error:

lib/ansible/modules/system/setup.py:195:17: E265 block comment should start with '# '

click here for bot help

@ansibot ansibot added ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. labels Jun 14, 2017
It doesn't test fail_on_error=true with collector exceptions
yet though.
@ansibot ansibot removed the ci_verified Changes made in this PR are causing tests to fail. label Jun 14, 2017
@ansibot
Copy link
Contributor

ansibot commented Jun 14, 2017

The test ansible-test sanity --test pep8 failed with the following error:

lib/ansible/modules/system/setup.py:195:17: E265 block comment should start with '# '

click here for bot help

@ansibot ansibot added the ci_verified Changes made in this PR are causing tests to fail. label Jun 14, 2017
@nitzmahone nitzmahone removed the needs_triage Needs a first human triage before being processed. label Jun 15, 2017
@ansibot ansibot added stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Jun 23, 2017
@ansibot ansibot added the needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html label Jul 18, 2017
@ansibot
Copy link
Contributor

ansibot commented Aug 24, 2017

cc @david_obrien
click here for bot help

@ansibot ansibot added the test This PR relates to tests. label Sep 1, 2017
@ansibot ansibot added the support:community This issue/PR relates to code supported by the Ansible community. label Nov 21, 2017
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bugfix_pull_request labels Mar 2, 2018
@ansibot ansibot added the traceback This issue/PR includes a traceback. label May 29, 2018
@dagwieers dagwieers added test This PR relates to tests. and removed test This PR relates to tests. test_pull_requests labels Jun 22, 2018
@ansibot
Copy link
Contributor

ansibot commented Nov 26, 2018

@ansibot ansibot added the system System category label Feb 17, 2019
@jimi-c
Copy link
Member

jimi-c commented Jun 5, 2020

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!

@jimi-c jimi-c closed this Jun 5, 2020
@ansible ansible locked and limited conversation to collaborators Jul 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. ci_verified Changes made in this PR are causing tests to fail. has_issue module This issue/PR relates to a module. needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team. system System category test This PR relates to tests. traceback This issue/PR includes a traceback.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants