The Computer Oracle

ansible: silently skip unreachable hosts

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Thinking It Over

--

Chapters
00:00 Ansible: Silently Skip Unreachable Hosts
01:11 Answer 1 Score 0
01:45 Answer 2 Score 0
02:00 Accepted Answer Score 6
02:28 Answer 4 Score 1
02:38 Thank you

--

Full question
https://superuser.com/questions/1181577/...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#ansible

#avk47



ACCEPTED ANSWER

Score 6


Going to add this answer: a fix was added in Ansible 2.7: https://github.com/ansible/ansible/blob/stable-2.7/changelogs/CHANGELOG-v2.7.rst#major-changes

New keyword ignore_unreachable for plays and blocks. Allows ignoring tasks that fail due to unreachable hosts, and check results with is unreachable test.

EDIT: From personal experience, I need to add ignore_errors along with it for the playbook to actually continue.




ANSWER 2

Score 1


Append to your oneline ansible |grep -A1 'rc=0'.
This will only show the passing plays / servers.




ANSWER 3

Score 0


You'd need to create a callback plugin to modify the way Ansible produces its output.

You can start with default.py provided as an example with Ansible. Search for the unreachable string and modify the script to suit your needs.

For example, to make it less prominent, you can for example override the value of COLOR_UNREACHABLE variable.

Save the modified code to callback_plugins in your project directory, point to the directory, and enable the plugin in the ansible.cfg configuration file.




ANSWER 4

Score 0


One way I found was to run this script against my hosts file first, and then edit the list accordingly. Then run the Ansible script.

It's a work around but still better than having to keep an eye on Ansible all the time waiting for it to stop again.