1

I'm aware of the ignore_errors: yes flag, to ignore failures during the playbook run, but I wish to know if there is anything in Ansible that I can set, that is not a 'ignore behavior' but still runs the playbook until it ends. That's because I want to have better report control.

To illustrate, currently this is my 'RUN-RECAP':

PLAY RECAP *******************************************************************************************************************************************************************************************
<server>                  : ok=195  changed=0    unreachable=0    failed=0    skipped=0    rescued=0    **ignored=10**

The "ignored=10" is actually "failed checks" What I need would be a PLAY RECAP like this:

PLAY RECAP *******************************************************************************************************************************************************************************************
<server>                  : ok=195  changed=0    unreachable=0    **failed=10**    skipped=0    rescued=0    ignored=0
2
  • Have you also set ignore_unreachable?
    – Jeff Schaller
    Commented Jun 25, 2021 at 11:23
  • The Failures are not due to unreachable hosts, but due to checks that fail or not in each run. It is OK that a check fails, I don't want to have the run aborted, but I also don't want to be listed as skipped with "ignored_*" but as failed.
    – Dumb admin
    Commented Jul 1, 2021 at 10:23

2 Answers 2

0

Regarding your question

if there is anything in Ansible that I can set, that is not a 'ignore behavior' but still runs the playbook until it ends.

you may have a look into Error handling in playbooks and Defining failure as

Ansible lets you define what “failure” means in each task using the failed_when conditional.

as well Handling errors with blocks.

3
  • this is not in any way near what dumb admin asked!!!
    – YosSaL
    Commented Nov 7, 2022 at 6:58
  • @YosefSalmalian, regarding "but I also don't want to be listed as skipped with ignored but as failed" what would be near then? The assert module, fail module or tweaking or Developing an own Callback plugin? I assume writing an plugin then. Maybe you can provide an answer here too.
    – U880D
    Commented Nov 7, 2022 at 7:36
  • there is no solution to this problem, maybe running tasks that may fail in different playbooks so they can fail...
    – YosSaL
    Commented Nov 7, 2022 at 7:42
0

One tactic you could use is to ignore the errors, but store the failure condition in a variable, and assert the state of that variable as the last task in the playbook. That way:

  • All your tasks will be attempted, regardless of failure
  • The playbook as a whole fails if any of your tasks fails, so you will see success or failure in the report at the end and can use the command's return code if you want
  • Task failures are highlighed in red by default even if they're ignored, so their messages are easy to locate in the playbook output.
  • This also works with loops, since the registered output has its own failed property that marks whether any of the loop items fails.

For example:

  - set_fact:
      global_fail: false

  - name: Assert the state of something
    ansible.builtin.assert:
      that:
        - <condition you want to assert>
      success_msg: ...
      fail_msg: ...
    register: assert_task
    ignore_errors: true

  - set_fact:
      global_fail: "{{ global_fail or (assert_task.failed is defined and assert_task.failed) }}"

  <Further tasks here>

  - name: Assert that no tasks failed
    ansible.builtin.assert:
      that:
        - not global_fail
      success_msg: "All tasks succeeded"
      fail_msg: "One or more tasks failed"





You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .