--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/87c9f759-872f-40b7-b80c-73f61817fb82n%40googlegroups.com.
Yes any_errors_fatal is what you need: https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_error_handling.html#aborting-on-the-first-error-any-errors-fatalWhen you say it doesn't seem to work, what does not seem to work?Kosala
Hello,My playbook has several hosts, and I have some tasks with assert and fail modules. How to do that if the task gets any fatal error in the play within particular host - the whole play should is terminated ?I thought that playbook command any_errors_fatal would work, but seems not.Is there any other way to make playbook stop if any of the hosts experiences errors ?I see ansible has meta modules - there are some kind like end_play module, maybe this one would work..Thank you.--
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 ansible-project+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/87c9f759-872f-40b7-b80c-73f61817fb82n%40googlegroups.com.
--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/VjdgAcJWJzc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAP7S5HawfBqkb4L1DjmZumHmJFw-Rtm8Fuh4t2JCuKmr_AE_-A%40mail.gmail.com.
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.On 6/06/2023, at 6:51 PM, Edvinas Kairys <edvina...@gmail.com> wrote:
Hello, thanks for reply.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAOrc2M9XhNiSe5ieGYMoonMU0gnScrp1fUv2YtzZdm4gy8sW_g%40mail.gmail.com.
The doc says it should do what you’re after.If you setany_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 setany_errors_fatal
at the play or block level.I never have used it personally, but are you setting any_errors_fatal:true at the task level or playbook level?
Hello, thanks for reply.I've two hosts in the play, and one of the hosts assert module doesnt validate to true and fails. With any_errors_fatal command I expect the playbook to stop on all hosts within the play. But in my case, the play stops only on failed host, it continues with other host where assertions passed.Is this expected behaviour ?
Yes any_errors_fatal is what you need: https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_error_handling.html#aborting-on-the-first-error-any-errors-fatalWhen you say it doesn't seem to work, what does not seem to work?Kosala
Hello,My playbook has several hosts, and I have some tasks with assert and fail modules. How to do that if the task gets any fatal error in the play within particular host - the whole play should is terminated ?I thought that playbook command any_errors_fatal would work, but seems not.Is there any other way to make playbook stop if any of the hosts experiences errors ?I see ansible has meta modules - there are some kind like end_play module, maybe this one would work..Thank you.--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/87c9f759-872f-40b7-b80c-73f61817fb82n%40googlegroups.com.
--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/VjdgAcJWJzc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAP7S5HawfBqkb4L1DjmZumHmJFw-Rtm8Fuh4t2JCuKmr_AE_-A%40mail.gmail.com.
--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAOrc2M9XhNiSe5ieGYMoonMU0gnScrp1fUv2YtzZdm4gy8sW_g%40mail.gmail.com.
--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/66611F66-7964-4D3F-8CB8-2018FEBAB763%40gmail.com.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/87c9f759-872f-40b7-b80c-73f61817fb82n%40googlegroups.com.
--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/VjdgAcJWJzc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAP7S5HawfBqkb4L1DjmZumHmJFw-Rtm8Fuh4t2JCuKmr_AE_-A%40mail.gmail.com.
--
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 ansible-project+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAOrc2M9XhNiSe5ieGYMoonMU0gnScrp1fUv2YtzZdm4gy8sW_g%40mail.gmail.com.
--
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 ansible-project+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/66611F66-7964-4D3F-8CB8-2018FEBAB763%40gmail.com.
--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/VjdgAcJWJzc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAKtKohQtv40%2BsXbpkfhQwJwZC%3DDS2RyjtFj12_gz1QDfZFWTag%40mail.gmail.com.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/87c9f759-872f-40b7-b80c-73f61817fb82n%40googlegroups.com.
--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/VjdgAcJWJzc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAP7S5HawfBqkb4L1DjmZumHmJFw-Rtm8Fuh4t2JCuKmr_AE_-A%40mail.gmail.com.
--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAOrc2M9XhNiSe5ieGYMoonMU0gnScrp1fUv2YtzZdm4gy8sW_g%40mail.gmail.com.
--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/66611F66-7964-4D3F-8CB8-2018FEBAB763%40gmail.com.
--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/VjdgAcJWJzc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
gather_facts: false
any_errors_fatal: True
roles:
- test
Roles task (block commented):
---
# - name: Run test pbook
# block:
- assert:
that:
- ansible_hostname == 'TEONET01A'
- debug:
msg: In role
# rescue:
# - debug:
# msg: Rescue
Runs as expected and play exists after fatal error in assert:
root@PCEDVKAIL3:/etc/ansible# ansible-playbook playbook.yml
PLAY [TEONET01A,TEONET01B] ***************************************************************************************************************************************************************************************************************************************************************
TASK [test : assert] *********************************************************************************************************************************************************************************************************************************************************************
[WARNING]: ansible-pylibssh not installed, falling back to paramiko
ok: [10.8.250.46] => {
"changed": false,
"msg": "All assertions passed"
}
[WARNING]: ansible-pylibssh not installed, falling back to paramiko
fatal: [10.8.250.47]: FAILED! => {
"assertion": "ansible_hostname == 'TEONET01A'",
"changed": false,
"evaluated_to": false,
"msg": "Assertion failed"
}
NO MORE HOSTS LEFT ***********************************************************************************************************************************************************************************************************************************************************************
PLAY RECAP *******************************************************************************************************************************************************************************************************************************************************************************
10.8.250.46 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
10.8.250.47 : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
Now how it works with block/rescue - seems like bug
same playbook:
- hosts: TEONET01A,TEONET01B
gather_facts: false
any_errors_fatal: True
roles:
- test
Roles (block uncommented):
---
- name: Run test pbook
block:
- assert:
that:
- ansible_hostname == 'TEONET01A'
- debug:
msg: In role
rescue:
- debug:
msg: Rescue
Runs as not expected and play continues with other host even the host assert fails:
root@PCEDVKAIL3:/etc/ansible# ansible-playbook playbook.yml
PLAY [TEONET01A,TEONET01B] ***************************************************************************************************************************************************************************************************************************************************************
TASK [test : assert] *********************************************************************************************************************************************************************************************************************************************************************
[WARNING]: ansible-pylibssh not installed, falling back to paramiko
ok: [10.8.250.46] => {
"changed": false,
"msg": "All assertions passed"
}
[WARNING]: ansible-pylibssh not installed, falling back to paramiko
fatal: [10.8.250.47]: FAILED! => {
"assertion": "ansible_hostname == 'TEONET01A'",
"changed": false,
"evaluated_to": false,
"msg": "Assertion failed"
}
TASK [test : debug] **********************************************************************************************************************************************************************************************************************************************************************
ok: [10.8.250.46] => {
"msg": "In role"
}
TASK [test : debug] **********************************************************************************************************************************************************************************************************************************************************************
ok: [10.8.250.47] => {
"msg": "Rescue"
}
PLAY RECAP *******************************************************************************************************************************************************************************************************************************************************************************
10.8.250.46 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
10.8.250.47 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=1 ignored=0