if failed

is there a way i can run a task if a task fails? how can i mention that

Ansible block/rescue ?

On the task, ignore_errors=yes + register then the subsequent task
when: registeredvar|failed

ok, lets say i have 5 tasks, if 4th one fails, can i run 2nd one using this when: registeredvar|failed ?

out of order?

yeah, it has to be in sequence?

ansible executes in sequence, so task 2 executes before task 4 and you
cannot base the decision of it's execution on something that happens
after.