-
Notifications
You must be signed in to change notification settings - Fork 23.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Abort/fail if host is unreachable #18782
Comments
Maybe |
@krzysztof-magosa : Unfortunately, unreachable doesn't seem to be considered a fatal in a way that "any_errors_fatal" or "max_failure_percentage" will detect. Even when combined with "gather_facts: false" and running a ping action on the host, it shows up in the output with a "fatal" prefix, but still doesn't seem to trigger the termination of the play with any combination of "any_errors_fatal" or "max_failure_percentage" I've tried. According to one of the Stack Overflow discussions I've read, this behavior changed in 2.1, it worked before that. |
Hi @linsomniac, have you tested recently to see if the issue has been corrected? |
This makes sure that 'current hosts in play' are the same as the initial hosts selected for the play, will detect unreachable, but also 'failed' hosts. - assert:
that:
- ansible_play_hosts == ansible_play_hosts_all another way is checking the registered var value for 'unreachable' key (via hostvars or clearing host errors). - fail: msg='host {{item}} was unreachable'
when: "'unreachable' in hostvars[item]['registeredvar']"
with_items: "{{ ansible_play_hosts_all }}"
run_once: True |
@jimi-c as of 2.4, any_errors_fatal only looks at failed tasks, still does not consider unreachable 'failed' - hosts: localhost, unreachable_host
gather_facts: false
any_errors_fatal: yes
tasks:
- debug: msg='changed'
- ping:
- debug: msg='changed' results in
|
@bcoca we have a deployment playbook against a set of static hosts. if one is unreachable, we need to fail (to avoid the potential of having inconsistency amongst the hosts). we're on ansible 2.3 -- do you recommend adding
to each playbook that demands consensus amongst hosts? The second suggestion;
seems like it could break in future versions if string/varname changes. |
I recently hit this issue I believe in
|
Is there any workaround for this issue? |
Hello there, I'd like to share what is working for me - name: Check SSH hosts reachability.
hosts: all
tasks:
- name: Simple command (ping).
ping:
- name: Check if ansible_play_hosts == ansible_play_hosts_all (means UNREACHABLE hosts detected)
run_once: True
assert:
that:
- ansible_play_hosts == ansible_play_hosts_all Results of the play
|
Reading #15523 It looks like aborting on unreachable hosts used to be how Ansible behaved in v1. It was then changed to ignore unreachable hosts in v2, reverted to failing in 2.2, and then changed to ignore again in 2.4. Although the suggested workaround of asserting Given that Ansible's behaviour has gone back and forth between failing and ignoring unreachable hosts a few times, perhaps making the behaviour configurable would be a reasonable approach? Perhaps a play/ansible.cfg/environment variable config item like |
Hello team, I need quick help!!! We have an ansible 2.9 version, any idea if this problem has been fixed in 2.9? https://docs.ansible.com/ansible/latest/index.html Please let me know. Thanks, |
I think this is covered by the |
Thank you very much for your submission to Ansible. It means a lot to us that you've taken time to contribute. Unfortunately, this issue has been open for some time while waiting for a contributor to take it up but there does not seem to have been anyone that did so. So we are going to close this issue to clear up the queues and make it easier for contributors to browse possible implementation targets. However, we're absolutely always up for discussion. Because this project is very active, we're unlikely to see comments made on closed tickets and we lock them after some time. If you or anyone else has any further questions, please let us know by using any of the communication methods listed in the page below: In the future, sometimes starting a discussion on the development list prior to proposing or implementing a feature can make getting things included a little easier, but it's not always necessary. Thank you once again for this and your interest in Ansible! |
ISSUE TYPE
COMPONENT NAME
Abort/fail if host is unreachable
ANSIBLE VERSION
CONFIGURATION
N/A
OS / ENVIRONMENT
N/A
SUMMARY
Ansible does not seem to treat an unreachable host as a failure, and in some cases (especially tasks where Ansible is involved in monitoring), I need any and all unreachable hosts to exit failure immediately, instead of continuing on to other hosts.
It looks like I'm not the only one either:
http://stackoverflow.com/questions/25930503/aborting-ansible-playbook-if-a-host-is-unreachable
http://stackoverflow.com/questions/31221165/ansible-abort-execution-if-a-host-is-unreachable
http://stackoverflow.com/questions/39657431/ansible-unreachable-instead-failed
FWIW, none of the suggestions in the posts above worked for me.
STEPS TO REPRODUCE
The feature would hopefully be as simple as a boolean that a user can toggle, e.g. 'fail_on_unreachable: true'
EXPECTED RESULTS
I expected some method for failing/aborting on unreachable hosts.
ACTUAL RESULTS
Couldn't find a good way to do it.
The text was updated successfully, but these errors were encountered: