# Regarding not to proceed further if ansible task fails

**URL:** <https://forum.ansible.com/t/regarding-not-to-proceed-further-if-ansible-task-fails/38407>\
**Category:** Ansible Project\
**Created:** [September 6, 2023, 3:22am UTC](https://forum.ansible.com/t/regarding-not-to-proceed-further-if-ansible-task-fails/38407 "2023-09-06T03:22:49Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [September 14, 2023, 3:42am UTC](https://forum.ansible.com/t/regarding-not-to-proceed-further-if-ansible-task-fails/38407/21 "2023-09-14T03:42:41Z")

</div>

That’s a task file, not a playbook. But at least you’ve quit posting pictures of your screen. The problem does not appear to be in that file.

Of the 5 things I asked for, you’ve now done the third one.

1. the command line you use to invoke this playbook

2. the playbook itself

3. the task file that is being pulled in from the playbook (please, not another picture of it!)

4. the job log (copy-and-paste, not a picture of part of it!)

5. output from the following command:  
ansible-config dump --only-changed

(BTW, line 95 has a quoting problem. You probably want to single-quote the outer string so the inner double quotes do what you expect. This is not the problem you’ve been posting about though. It was made obvious by running ansible-lint on that task file.)

---

<div class="post-metadata">

**Author:** ![Ashok-2017](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ashok-2017/32/659_2.png) [@Ashok-2017](https://forum.ansible.com/u/Ashok-2017)\
**Post date:** [September 18, 2023, 5:25am UTC](https://forum.ansible.com/t/regarding-not-to-proceed-further-if-ansible-task-fails/38407/22 "2023-09-18T05:25:03Z")

</div>

Hi Todd,

Thanks for your help.  
I will send you

---

<div class="post-metadata">

**Author:** ![Ashok-2017](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ashok-2017/32/659_2.png) [@Ashok-2017](https://forum.ansible.com/u/Ashok-2017)\
**Post date:** [September 18, 2023, 5:51am UTC](https://forum.ansible.com/t/regarding-not-to-proceed-further-if-ansible-task-fails/38407/23 "2023-09-18T05:51:30Z")

</div>

Hi John,

Thanks for providing your inputs. Let me try

> **(attachments)**
>
> ![image_6487327.JPG](https://us1.discourse-cdn.com/ansible/original/2X/b/b5391f926f4d45d639d202c55e95076874572caa.jpeg)  
> ![image_6487327.JPG](https://us1.discourse-cdn.com/ansible/original/2X/7/746a17df1881d9151d71ea21c638cb3ce0456522.jpeg)

---

<div class="post-metadata">

**Author:** ![Ashok-2017](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ashok-2017/32/659_2.png) [@Ashok-2017](https://forum.ansible.com/u/Ashok-2017)\
**Post date:** [September 18, 2023, 7:02am UTC](https://forum.ansible.com/t/regarding-not-to-proceed-further-if-ansible-task-fails/38407/24 "2023-09-18T07:02:28Z")

</div>

Hi John,

I have configured the meta\_play: end\_play in roles where the task has failed but it will not exit .  
Can you please guide me?

For example, if any task fails, it will come out the playbook and not to proceed further to execute tasks.

> **(attachments)**
>
> ![image_6487327.JPG](https://us1.discourse-cdn.com/ansible/original/2X/b/b5391f926f4d45d639d202c55e95076874572caa.jpeg)  
> ![image_6487327.JPG](https://us1.discourse-cdn.com/ansible/original/2X/7/746a17df1881d9151d71ea21c638cb3ce0456522.jpeg)

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [September 18, 2023, 8:01am UTC](https://forum.ansible.com/t/regarding-not-to-proceed-further-if-ansible-task-fails/38407/25 "2023-09-18T08:01:48Z")

</div>

Please focus on the actual problem, and respond to Todd’s mail and provide the requested data.

---

<div class="post-metadata">

**Author:** ![Ashok-2017](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ashok-2017/32/659_2.png) [@Ashok-2017](https://forum.ansible.com/u/Ashok-2017)\
**Post date:** [September 18, 2023, 8:59am UTC](https://forum.ansible.com/t/regarding-not-to-proceed-further-if-ansible-task-fails/38407/26 "2023-09-18T08:59:50Z")

</div>

I will send

---

<div class="post-metadata">

**Author:** ![jcpetro](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@jcpetro](https://forum.ansible.com/u/jcpetro)\
**Post date:** [September 18, 2023, 12:58pm UTC](https://forum.ansible.com/t/regarding-not-to-proceed-further-if-ansible-task-fails/38407/27 "2023-09-18T12:58:18Z")

</div>

Honestly, I can’t. I just used one of the examples from the documentation and that solved my problem. My suggestion, is that you might want to poke at that. I do a lot of trial and error stuff when it comes to ansible in a couple of virtual machines I set up on my desktop using either virtualbox or docker, depending on what I am trying to accomplish. With regards to the meta module, I had used it once, but then the playbook was obsolete since the host I had written it for was retired, so I just got rid of the code, because there was no use for it.

> **(attachments)**
>
> ![image_6487327.JPG](https://us1.discourse-cdn.com/ansible/original/2X/b/b5391f926f4d45d639d202c55e95076874572caa.jpeg)  
> ![image_6487327.JPG](https://us1.discourse-cdn.com/ansible/original/2X/7/746a17df1881d9151d71ea21c638cb3ce0456522.jpeg)

---

<div class="post-metadata">

**Author:** ![Ashok-2017](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ashok-2017/32/659_2.png) [@Ashok-2017](https://forum.ansible.com/u/Ashok-2017)\
**Post date:** [September 18, 2023, 1:12pm UTC](https://forum.ansible.com/t/regarding-not-to-proceed-further-if-ansible-task-fails/38407/28 "2023-09-18T13:12:17Z")

</div>

Hi John,

Thanks for providing your inputs and suggestions.

> **(attachments)**
>
> ![image_6487327.JPG](https://us1.discourse-cdn.com/ansible/original/2X/b/b5391f926f4d45d639d202c55e95076874572caa.jpeg)  
> ![image_6487327.JPG](https://us1.discourse-cdn.com/ansible/original/2X/7/746a17df1881d9151d71ea21c638cb3ce0456522.jpeg)

---

<div class="post-metadata">

**Author:** ![skratbag](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/skratbag/32/4836_2.png) [@skratbag](https://forum.ansible.com/u/skratbag)\
**Post date:** [September 18, 2023, 11:12pm UTC](https://forum.ansible.com/t/regarding-not-to-proceed-further-if-ansible-task-fails/38407/29 "2023-09-18T23:12:38Z")

</div>

Have you checked out the any\_errors\_fatal? [https://docs.ansible.com/ansible/latest/playbook\_guide/playbooks\_error\_handling.html](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_error_handling.html)

If you set `any_errors_fatal` and a task returns an error, Ansible finishes the fatal task on all hosts in the current batch, then stops executing the play on all hosts. Subsequent tasks and plays are not executed. You can recover from fatal errors by adding a [rescue section](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_blocks.html#block-error-handling) to the block. You can set `any_errors_fatal` at the play or block level.

```auto
- hosts: somehosts
  any_errors_fatal: true
  roles:
    - myrole

- hosts: somehosts
  tasks:
    - block:
        - include_tasks: mytasks.yml
      any_errors_fatal: true

```

You can use this feature when all tasks must be 100% successful to continue playbook execution. For example, if you run a service on machines in multiple data centers with load balancers to pass traffic from users to the service, you want all load balancers to be disabled before you stop the service for maintenance. To ensure that any failure in the task that disables the load balancers will stop all other tasks:

> **(attachments)**
>
> ![image_6487327.JPG](https://us1.discourse-cdn.com/ansible/original/2X/b/b5391f926f4d45d639d202c55e95076874572caa.jpeg)  
> ![image_6487327.JPG](https://us1.discourse-cdn.com/ansible/original/2X/7/746a17df1881d9151d71ea21c638cb3ce0456522.jpeg)

---

<div class="post-metadata">

**Author:** ![Ashok-2017](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ashok-2017/32/659_2.png) [@Ashok-2017](https://forum.ansible.com/u/Ashok-2017)\
**Post date:** [September 19, 2023, 12:05am UTC](https://forum.ansible.com/t/regarding-not-to-proceed-further-if-ansible-task-fails/38407/30 "2023-09-19T00:05:31Z")

</div>

Hi David,

Thanks for providing your inputs and suggestions. I have tried with any\_errors\_fatal and block level in roles but can’t make it work.

Note: I am trying to implement in roles level.

> **(attachments)**
>
> ![image_6487327.JPG](https://us1.discourse-cdn.com/ansible/original/2X/b/b5391f926f4d45d639d202c55e95076874572caa.jpeg)  
> ![image_6487327.JPG](https://us1.discourse-cdn.com/ansible/original/2X/7/746a17df1881d9151d71ea21c638cb3ce0456522.jpeg)

---

<div class="post-metadata">

**Author:** ![skratbag](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/skratbag/32/4836_2.png) [@skratbag](https://forum.ansible.com/u/skratbag)\
**Post date:** [September 19, 2023, 1:25am UTC](https://forum.ansible.com/t/regarding-not-to-proceed-further-if-ansible-task-fails/38407/31 "2023-09-19T01:25:59Z")

</div>

This is at the playbook or block level from what I can see. The roles you are using should be included in a playbook and the playbook defines the any\_errors\_fatal: true (see the example).  
This would include any included roles or tasks.

> **(attachments)**
>
> ![image_6487327.JPG](https://us1.discourse-cdn.com/ansible/original/2X/b/b5391f926f4d45d639d202c55e95076874572caa.jpeg)  
> ![image_6487327.JPG](https://us1.discourse-cdn.com/ansible/original/2X/7/746a17df1881d9151d71ea21c638cb3ce0456522.jpeg)

---

<div class="post-metadata">

**Author:** ![Ashok-2017](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ashok-2017/32/659_2.png) [@Ashok-2017](https://forum.ansible.com/u/Ashok-2017)\
**Post date:** [September 19, 2023, 3:31am UTC](https://forum.ansible.com/t/regarding-not-to-proceed-further-if-ansible-task-fails/38407/32 "2023-09-19T03:31:34Z")

</div>

Hi all,

Please find below;

Jenkins configuration:

(“${environment}” == “uat”) {

ansiblePlaybook(

playbook: ‘deploy.yml’,

inventory: ‘hosts’,

tags: ‘downtime’,

extraVars: [

app\_env: ‘uat’,

jfrog\_username:

jfrog\_password:

branch: “${branch}”,

maintanance: ‘no’,

build\_version: version

deploy.yml:

- hosts: “{{ app\_env }}”

gather\_facts: no

remote\_user: ansible

become: true

serial: 1

tasks:

- block:

- include\_tasks: main.yml

any\_errors\_fatal: true

vars\_prompt:

- name: “jfrog\_username”

prompt: “Enter JFrog username”

private: no

- name: “jfrog\_password”

prompt: “Enter JFrog password”

private: yes

tags: [downtime, nodowntime]

- hosts: “{{ app\_env }}”

gather\_facts: no

remote\_user: ansible

become: true

serial: 1

ignore\_errors: no

any\_errors\_fatal: true

roles:

- deploy

vars\_prompt:

- name: “jfrog\_username”

prompt: “Enter JFrog username”

private: no

- name: “jfrog\_password”

prompt: “Enter JFrog password”

private: yes

tags: [downtime, nodowntime]

Jenkins Logs:

ansible-playbook deploy.yml -i hosts -t downtime -e app\_env=uat -e jfrog\_username= -e jfrog\_password= -e branch=uat -e maintanance=no -e build\_version=558

**10:44:18** ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.

**10:44:18**

**10:44:18** The error appears to have been in ‘/var/jenkins\_home/workspace/SG-MyInfo-Deployment/deploy.yml’: line 28, column 11, but may

**10:44:18** be elsewhere in the file depending on the exact syntax problem.

**10:44:18**

**10:44:18** The offending line appears to be:

**10:44:18**

**10:44:18** - block:

**10:44:18** - include\_tasks: main.yml

**10:44:18** ^ here

TASK [deploy : Check if multiple files exist and fail playbook if any file does not exist] \*\*\*

**14:50:07** fatal: [10.119.39.101]: FAILED! =\> {“failed”: true, “msg”: “the field ‘args’ has an invalid value, which appears to include a variable that is undefined. The error was: ‘item’ is undefined\n\nThe error appears to have been in ‘/var/jenkins\_home/workspace/SG-MyInfo-Deployment/deploy/tasks/main.yml’: line 8, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Check if multiple files exist and fail playbook if any file does not exist\n ^ here\n”}

**14:50:07** …ignoring

**14:50:07** ERROR! invalid meta action requested: end\_host

**14:50:07**

> **(attachments)**
>
> ![image_6487327.JPG](https://us1.discourse-cdn.com/ansible/original/2X/b/b5391f926f4d45d639d202c55e95076874572caa.jpeg)  
> ![image_6487327.JPG](https://us1.discourse-cdn.com/ansible/original/2X/7/746a17df1881d9151d71ea21c638cb3ce0456522.jpeg)

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [September 19, 2023, 10:02am UTC](https://forum.ansible.com/t/regarding-not-to-proceed-further-if-ansible-task-fails/38407/33 "2023-09-19T10:02:28Z")

</div>

There is Jenkins in the mix.  
And there are now more errors as well.

But I think the serial=1 is your problem.  
If that host fails, then there are no other hosts in the play.  
Try without serial=1

> **(attachments)**
>
> ![image_6487327.JPG](https://us1.discourse-cdn.com/ansible/original/2X/b/b5391f926f4d45d639d202c55e95076874572caa.jpeg)  
> ![image_6487327.JPG](https://us1.discourse-cdn.com/ansible/original/2X/7/746a17df1881d9151d71ea21c638cb3ce0456522.jpeg)

---

<div class="post-metadata">

**Author:** ![Ashok-2017](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ashok-2017/32/659_2.png) [@Ashok-2017](https://forum.ansible.com/u/Ashok-2017)\
**Post date:** [September 19, 2023, 10:27am UTC](https://forum.ansible.com/t/regarding-not-to-proceed-further-if-ansible-task-fails/38407/34 "2023-09-19T10:27:02Z")

</div>

Hi Visser,

Thanks for your inputs and suggestion. But if I use serial is 1, the task will execute on one host at a time. Not sure whether i am making correct statement or not. As i know, this could not cause any issue.

> **(attachments)**
>
> ![image_6487327.JPG](https://us1.discourse-cdn.com/ansible/original/2X/b/b5391f926f4d45d639d202c55e95076874572caa.jpeg)  
> ![image_6487327.JPG](https://us1.discourse-cdn.com/ansible/original/2X/7/746a17df1881d9151d71ea21c638cb3ce0456522.jpeg)

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [September 19, 2023, 11:03am UTC](https://forum.ansible.com/t/regarding-not-to-proceed-further-if-ansible-task-fails/38407/35 "2023-09-19T11:03:54Z")

</div>

I suggested to remove the entire serial statement

> **(attachments)**
>
> ![image_6487327.JPG](https://us1.discourse-cdn.com/ansible/original/2X/b/b5391f926f4d45d639d202c55e95076874572caa.jpeg)  
> ![image_6487327.JPG](https://us1.discourse-cdn.com/ansible/original/2X/7/746a17df1881d9151d71ea21c638cb3ce0456522.jpeg)

---

<div class="post-metadata">

**Author:** ![Ashok-2017](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ashok-2017/32/659_2.png) [@Ashok-2017](https://forum.ansible.com/u/Ashok-2017)\
**Post date:** [September 19, 2023, 12:20pm UTC](https://forum.ansible.com/t/regarding-not-to-proceed-further-if-ansible-task-fails/38407/36 "2023-09-19T12:20:28Z")

</div>

Okay Visser let me try

> **(attachments)**
>
> ![image_6487327.JPG](https://us1.discourse-cdn.com/ansible/original/2X/b/b5391f926f4d45d639d202c55e95076874572caa.jpeg)  
> ![image_6487327.JPG](https://us1.discourse-cdn.com/ansible/original/2X/7/746a17df1881d9151d71ea21c638cb3ce0456522.jpeg)

---

<div class="post-metadata">

**Author:** ![Ashok-2017](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ashok-2017/32/659_2.png) [@Ashok-2017](https://forum.ansible.com/u/Ashok-2017)\
**Post date:** [September 20, 2023, 9:06am UTC](https://forum.ansible.com/t/regarding-not-to-proceed-further-if-ansible-task-fails/38407/37 "2023-09-20T09:06:10Z")

</div>

Hi David,

I tried using block level but it throws error

> **(attachments)**
>
> ![image_6487327.JPG](https://us1.discourse-cdn.com/ansible/original/2X/b/b5391f926f4d45d639d202c55e95076874572caa.jpeg)  
> ![image_6487327.JPG](https://us1.discourse-cdn.com/ansible/original/2X/7/746a17df1881d9151d71ea21c638cb3ce0456522.jpeg)

---

<div class="post-metadata">

**Author:** ![Ashok-2017](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ashok-2017/32/659_2.png) [@Ashok-2017](https://forum.ansible.com/u/Ashok-2017)\
**Post date:** [September 20, 2023, 9:24am UTC](https://forum.ansible.com/t/regarding-not-to-proceed-further-if-ansible-task-fails/38407/38 "2023-09-20T09:24:40Z")

</div>

Hi Vesser,

I tried without using serial=1 but can’t make it to work

> **(attachments)**
>
> ![image_6487327.JPG](https://us1.discourse-cdn.com/ansible/original/2X/b/b5391f926f4d45d639d202c55e95076874572caa.jpeg)  
> ![image_6487327.JPG](https://us1.discourse-cdn.com/ansible/original/2X/7/746a17df1881d9151d71ea21c638cb3ce0456522.jpeg)

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [September 20, 2023, 2:20pm UTC](https://forum.ansible.com/t/regarding-not-to-proceed-further-if-ansible-task-fails/38407/39 "2023-09-20T14:20:00Z")

</div>

Neither of these responses is informative. What results - from the job log - constitute “can’t make it work”? What exactly did you try? What did you change, and what did you change it to? When you tell us that “it throws error” without including - from the job log - the error that it throws, what possible response can you expect besides “Does it now? And what error did it throw exactly?” We have established from many days ago that something is causing the equivalent of . We saw this in the job log. This may be related to something in your Ansible configuration. The output from the command would tell us, but you still have not shared that with us. It could also be related to how your task file is being invoked from your playbook: , , indirectly through , or some other way. Another thing: Knowing the parameters you are using might be very helpful in our trying to reproduce the issue you are having. I mean the section before any , , , , etc. There are keywords and values there that directly affect how plays run. We’re trying to help you. That would be much easier to do if you provided the requested information. – Todd

---

<div class="post-metadata">

**Author:** ![Ashok-2017](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ashok-2017/32/659_2.png) [@Ashok-2017](https://forum.ansible.com/u/Ashok-2017)\
**Post date:** [September 20, 2023, 11:51pm UTC](https://forum.ansible.com/t/regarding-not-to-proceed-further-if-ansible-task-fails/38407/40 "2023-09-20T23:51:01Z")

</div>

Hi Todd,

I will provide that information.

[Previous page](https://forum.ansible.com/t/regarding-not-to-proceed-further-if-ansible-task-fails/38407.md?page=1)
