It works if you do it in a single play.
Why are you using two different plays anyway?




On Sun, 29 Mar 2020 at 13:00, Shifa Shaikh <[email protected]> wrote:

> I have two Plays having one task each.
>
>
> The first Play 1 checks if the/var/test.datexists on each target host.
>
>
> Only if the Play 1 is successful do I want the second play Play 2 to run
> which executes scripts in parallel.
>
>
> If Play 1 fails i.e if the test.dat does not exist I wish to terminate the
> entire playbook without the Play 2 getting executed.
>
>
> For this purpose, I have set any_errors_fatal set to true
>
>
> I need to have an ansible Play strategy set to free as each of the
> scripts takes 30 minutes to complete hence running them in parallel is the
> requirement.
>
>
> My understanding of ansible is limited.
>
>
> I understand that if I have both the tasks under a single Play and set the
> strategy to free both the tasks will run in parallel which is something I
> do not want.
>
>
> ---
>
> - name: Play 1- check for login and script
>   hosts: all_hosts
>   any_errors_fatal: true
>   strategy: free
>   tasks:
>
>    - name: Check script existence
>      shell: "ls /var/test.dat"
>      register: checkscript
>
>    - name:
>      fail:
>        msg: "script {{ scriptdet }} missing on {{ inventory_hostname }}"
>      when: checkscript.rc != 0
>
> - name: Play 2- Run scripts
>   hosts: all_hosts
>   user: "{{ USER }}"
>   strategy: free
>
>   tasks:
>    - name: Execute backup script
>      shell: "{{ scriptdet }}"
>      args:
>        chdir: ~/..
>
>
> I tried the above playbook but I see the second play executes despite the
> first play's task failed.
>
>
> Can you please suggest how can I get this to work?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/1b0ccbc8-6dac-4d90-acd4-c4a852b38f5b%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/1b0ccbc8-6dac-4d90-acd4-c4a852b38f5b%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
-- 
Sent from a mobile device - please excuse the brevity, spelling and
punctuation.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAL8fbwM%3D8cvVVL_3U_UWjkQfNrZH%3D0qFttJ5dP7RtABRzV83mw%40mail.gmail.com.

Reply via email to