Regarding not to proceed further if ansible task fails

Hi All,

When I tried to download packages from jfrog repository, If it gets downloaded, it is okay. But if it is unable to download, we should not proceed further to execute other tasks.

How to write ansible task?

If we use register and based on the condition, shall we stop to expect tasks?

Can you please help me?

Hi Ashok,

The methods you need are here https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_error_handling.html

There are some good ideas on how to halt and abort a playbook if errors occur

Regards

Hi ,

Can someone help me?

This is the default behavior, if task #1 fails, subsequent tasks will
not run for that host. In the previous response they point you on how
to continue on error, the implication being the default is to stop on
error.

Hi Brian

Noted and Thanks for your response.
But, when we tried to download packages, the package is not available and then the task fails .

The next tasks also executed and It does not come out of the script.

In that case, I have written a task to verify whether file exists or not and then any_fail_on_error: true .

Is it correct?

Hii

What you describe is nonstandard behaviour.
Instead of guessing, please show us your playbook and any other relevant code.

Hi ,

The following script, which only skip the task and execute further:

But, What I did : If the file doesn’t exist, it cannot proceed to execute tasks and cone out ofcthe script:

Is it correct?

Can someone help me with this?

Hi All,

Can you please help?

(attachments)


I don’t wish to defend the horrid things that Google Groups does to pasted text, particularly where whitespace matters.

However, photos of text is about useless. For example, there’s no practical way to run a linter on pictures of text. It’s impossible to say with certainty that a task in a clipped photo is correct.

You’ve been working with these tasks now for almost a week. Is there any behavior you see that makes you think they don’t do what you expect? If so, then copy-and-past (not screenshots!) the evidence from the run log, include the relevant tasks, data, etc., and explain what you expect contrasted with what is actually happening.
Otherwise, yes, it is correct! (?)

Hi ,

I have tried but it didn’t stop when task fails.

If we use failed_when: true, it can work.

Can you please help?

(attachments)


Hi Brian,

The logs are:

Even if the task fails, it can proceed to execute further tasks . But don’t want that.

What I am trying to achieve is If the task fails, it will not proceed further to execute tasks and come out of the script

(attachments)


From the documentation

By default, Ansible continues to execute tasks as long as there are hosts that have not yet failed. You might like to set a maximum failure percentage or similar.

Do you have this running on multiple hosts? or is it on a single host?

https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_error_handling.html

Regards
David

(attachments)


I don’t know if this was mentioned at all, but have you looked at the meta module? I used it to break out of a play when something failed.

https://docs.ansible.com/ansible/latest/collections/ansible/builtin/meta_module.html

–John

(attachments)


from the output you have EXPLICIT ignores to the failures, that is why Ansible is continuing to more tasks, remove the ignores if you don’t want the failure to be ignored.

Hi Brian,

Did not configure the ignore_errors in playbook

(attachments)

Not in the part you are showing, but the output you showed has ignoring .. which you only get with that keyword.

You didn’t show any playbook so far, just (fuzzy pictures of computer screens with) task files that are included.
If you can post the TEXTUAL version of the playbook that includes them.

Please do not post any more photos of computer screens… just the actual text.
So: no pictures - just text.

Hi All,

PFA for the ansible playbook

(attachments)

deploy_tasks_main (1).yml (7.81 KB)