0

I am looking to run a playbook that checks if a host is active, and if not check again in 24 hours.

start playbook

    do while host X is not up
    {
        wait 24 hours
    }

Is this possible in ansible? From the docs, it's very unclear if it is.

Garrett Hyde
  • 5,409
  • 8
  • 49
  • 55

1 Answers1

1

You can use Ansible's wait_for module.

- name: Wait for host
  wait_for:
    host: "{{ inventory_hostname }}"
    port: 22
    sleep: 86400     # check every 24 hours
    timeout: 604800  # exit after 7 days
  delegate_to: localhost
Garrett Hyde
  • 5,409
  • 8
  • 49
  • 55
  • 2
    In case you are not waiting for a reboot, but the initial boot, the parameter `gather_facts: no` is helpful. This should be set on the same indentation level as `wait_for`, but even better would be `wait_for_connection`. See https://docs.ansible.com/ansible/latest/collections/ansible/builtin/wait_for_connection_module.html – Isaac Apr 08 '21 at 15:33