any_errors_fatal doesn't fail with unreachable hosts

188 views
Skip to first unread message

Mark Faine

unread,
Mar 10, 2021, 3:34:57 PM3/10/21
to Ansible Project

I'm trying to ping servers and fail immediately at the first one that is unreachable.  However, this doesn't seem to work.  I found this old issue about it but apparently it hasn't been resolved.  https://github.com/ansible/ansible/issues/16475

---
- name: Ping
  hosts: all
  gather_facts: false
  any_errors_fatal: true
  tasks:
    - name: Ping Servers
      ping:

I've purposely poisoned the inventory and yet it just says those hosts are unreachable and continues on its way, it should fail at the first unreachable host.

Thanks,
-Mark

Jorge Rúa

unread,
Mar 10, 2021, 4:44:50 PM3/10/21
to ansible...@googlegroups.com


What happens if you add serial:1 and max_fail_percentage:1 and removing any_errors_fatal directive? 

--
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/a8fdae92-0d13-4e80-a993-ba2e0b25e4bcn%40googlegroups.com.

Mark Faine

unread,
Mar 10, 2021, 5:18:54 PM3/10/21
to Ansible Project
It still continues on after failing, it just does so one host at a time.

PLAY [Ping] ******************************************************************************************************************************************************************

TASK [Ping Servers] **********************************************************************************************************************************************************
fatal: [myhost1]: UNREACHABLE! => {"changed": false, "msg": "Data could not be sent to remote host \"myhost1\". Make sure this host can be reached over ssh: ", "unreachable": true}

NO MORE HOSTS LEFT ***********************************************************************************************************************************************************

NO MORE HOSTS LEFT ***********************************************************************************************************************************************************

PLAY [Ping] ******************************************************************************************************************************************************************

TASK [Ping Servers] **********************************************************************************************************************************************************
fatal: [myhost2]: UNREACHABLE! => {"changed": false, "msg": "Data could not be sent to remote host \"myhost2\". Make sure this host can be reached over ssh: ", "unreachable": true}

NO MORE HOSTS LEFT ***********************************************************************************************************************************************************

NO MORE HOSTS LEFT ***********************************************************************************************************************************************************

PLAY [Ping] ******************************************************************************************************************************************************************

TASK [Ping Servers] **********************************************************************************************************************************************************
...

Mark Faine

unread,
Mar 11, 2021, 10:41:44 AM3/11/21
to Ansible Project
So, you guys think I should file an issue for this?  I don't know what else to do.

Jorge Rúa

unread,
Mar 11, 2021, 10:53:11 AM3/11/21
to ansible...@googlegroups.com
I've tried the following with a vanilla ansible.cfg (nothing but defaults)

mkdir ~/temp

➜  temp cat test.yml
- hosts: all
  serial: 1
  max_fail_percentage: 1
  gather_facts: false
  tasks:
    - ping:

➜  temp cat inventory
[all]
unreachable
localhost
➜  temp ansible-playbook -i inventory test.yml -k
SSH password:

PLAY [all] ************************************************************************************************************************************************************************************

TASK [ping] ***********************************************************************************************************************************************************************************
fatal: [unreachable]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname unreachable: Name or service not known", "unreachable": true}

PLAY RECAP ************************************************************************************************************************************************************************************
unreachable                : ok=0    changed=0    unreachable=1    failed=0    skipped=0    rescued=0    ignored=0  

As you can see it does not continue with localhost, which will succeed if I revert the inventory order.

Regards,









Mark Faine

unread,
Mar 11, 2021, 12:15:22 PM3/11/21
to ansible...@googlegroups.com
I don't know what to tell you, it does for me.


Sent from ProtonMail mobile



-------- Original Message --------
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/9DZI9gGoUnU/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/CAFtje5Psc2ZGMFvPs2sSE%2BBXKN6_d0%2BDQ5REiAPi0dpRu4z6%2BQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages