title: Ansible wait_for doesn't seem to work
body: <p>I'm provisioning a new server via Terraform and using Ansible as the provisioner on my local system.</p>
  
  <p>Terraform provisions a system on EC2, and then it runs the Ansible playbook providing the IP of the newly built system as the inventory.</p>
  
  <p>I want to use Ansible to wait for the system to finish booting and prevent further tasks from being attempted up until a connection can be established. Up until this point I have been using a manual pause which is inconvenient and imprecise.</p>
  
  <p>Ansible doesn't seem to do what the documentation says it will (unless I'm wrong, a very possible scenario). Here's my code:</p>
  
  <pre><code>- name: waiting for server to be alive
      wait_for:
        state: started
        port: 22
        host: "{{ ansible_ssh_host | default(inventory_hostname) }}"
        delay: 10
        timeout: 300
        connect_timeout: 300
        search_regex: OpenSSH
      delegate_to: localhost
  </code></pre>
  
  <p>What happens in this step is that the connection doesn't wait any more than 10 seconds to make the connection, and it fails. If the server has booted and I try the playbook again, it works fine and performs as expected.</p>
  
  <p>I've also tried <code>do_until</code> style loops which never seem to work. All examples given in documentation use shell output, and I don't see any way that it would work for non-shell modules.</p>
  
  <p>I also can't seem to get any debug information if I try to register a result and print it out using the debug module.</p>
  
  <p>Anyone have any suggestions as to what I'm doing wrong?</p>