How to run a delegated task for an offline host using Ansible

ansibleautomation

I have Ansible tasks for enabling and disabling Nagios checking for some hosts. They use "delegate_to" the Nagios server. However, I can't use them when the host in question is offline, because Ansible tries to SSH in and marks the task failed when it can't.

Since this task doesn't actually require contacting the host in any way, it seems there should be a way to have Ansible ignore the host and communicate only with the delegate. Is this possible?

Best Answer

As implied by some of the comments, it is likely that something else is causing the SSH connection error rather than the delegated task. When using delegte_to:, Ansible only connects via SSH to the machine indicated in the delegate clause (in cases other than localhost).

I would try the suggested disabling of facts (gather_facts: no) and also share the output of your failed playbook run(s). It could also be that there is a non-delegated task/role included in the playbook which is failing the play due to the target host being down.