4

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?

  • Perhaps disable gathering facts and/or use ignore_errors: yes. Alternatively, rework your playbook to talk directly to your Nagios server and use the host in question as a variable. – Mxx Oct 12 '14 at 5:48
  • You might want to try gather_facts: False so that Ansible doesn't try to connect to those hosts to gather facts about them. – Bruce P Oct 15 '14 at 19:19
2

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.

0

You'll need to skip all the usual tasks of the unavailable host by using e.g. tags, disable fact gathering for it and it will work. Tested like this:

test_delegate.yml:

- hosts: unavailable.test
  gather_facts: false
  tasks:
    - command: /bin/stuff
    - ping:
      delegate_to: localhost
      tags: nagios

Result:

$ ansible-playbook -i unavailable.test, -tnagios test_delegate.yml 

PLAY [unavailable.test] ********************************************************

TASK [ping] ********************************************************************
ok: [unavailable.test -> localhost]

PLAY RECAP *********************************************************************
unavailable.test           : ok=1    changed=0    unreachable=0    failed=0   

localhost here in the example stands for the reachable host, nagios in your case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.