Today I’ve needed an Ansible play which first tries to connect with A (e.g. port 22, user hello) and if that should fail, fall back to B (e.g. port 22, user world). I’ve started scripting and it all looked great until I’ve ran into a big problem: Whenever a SSH connection fails, Ansible throws a “fatal” instead of just an usual “failed”, so “ignore_errors” does not help at all.
I now came up with my own solution, which involves a callback module: Whenever the environment variable soft_connection_errors is set within a task, SSH connections will fail and no longer throw any fatal errors. I’ve uploaded my code as a Gist: Ansible Connection Bootstrapper
Is there any better solution available? Runtime method patching just doesn’t seem right to me, even if it perfectly works.