Regarding not to proceed further if ansible task fails

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.)

Hi Todd,

Thanks for your help.
I will send you

Hi John,

Thanks for providing your inputs. Let me try

(attachments)


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)


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

I will send

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)


Hi John,

Thanks for providing your inputs and suggestions.

(attachments)


Have you checked out the any_errors_fatal? 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 to the block. You can set any_errors_fatal at the play or block level.

- 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)


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)


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)


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)


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)


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)


I suggested to remove the entire serial statement

(attachments)


Okay Visser let me try

(attachments)


Hi David,

I tried using block level but it throws error

(attachments)


Hi Vesser,

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

(attachments)


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

Hi Todd,

I will provide that information.