title: ansible-playbook wait for ssh timing out with ping error, but works locally
body: <p>I am trying to ssh to an ec2 instance, via my ansible-playbook file.  I can ssh into the instance locally, and currently have the following configuration in my ansible-playbook file:</p>
  
  <pre><code>- name: Wait for SSH to come up
    delegate_to: "{{ public_dns }}"
    wait_for_connection:
      delay: 60
      timeout: 120
    with_items: "{{ public_ip }}"
    remote_user: ubuntu
    connection: ssh
    register: item
  </code></pre>
  
  <p>However, when I run this, I get the following error:</p>
  
  <blockquote>
    <p>failed: [localhost -> {{ public_dns }}] (item={'_ansible_item_result':
    True, '_ansible_no_log': False, '_ansible_delegated_vars':
    {'ansible_delegated_host': u'{{ public_dns }}', 'ansible_host': u'{{
    public_dns }}'}, 'changed': False, 'elapsed': 184, 'failed': True,
    'item': u'{{ public_ip }}', 'msg': u"timed out waiting for ping module
    test success: 'ping'", '_ansible_ignore_errors': None}) => {"changed":
    false, "elapsed": 184, "item": "{{ public_ip }}", "msg": "timed out
    waiting for ping module test success: 'ping'"}</p>
  </blockquote>
  
  <p>When I ping the public_dns or public_ip value from my machine both are successful.</p>
  
  <p>Why would the ping event fail when running the Ansible file?  (I'm not purposefully trying to ping the instance, I actually want to connect to it via ssh.  However the error shows that Ansible may be trying to ping the instance before connecting, based on the "timed out waiting for ping module test success")</p>
  
  <p>I have since changed the method to:</p>
  
  <pre><code>- name: Add new instance to host group
    add_host:
    hostname: ""{{ public_ip }}"
    groupname: launched
  
  - name: Wait for SSH to come up
    wait_for:
      host: launched
      port: 22
      sleep: 30
      delay: 10
      timeout: 360
    state: started
  </code></pre>
  
  <p>However, this has been throwing a different error, of "Timeout when waiting for launched:22" The traceback includes the following:</p>
  
  <blockquote>
    <p>connect_socket = socket.create_connection((host, port), connect_timeout)  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 557, in create_connection
        for res in getaddrinfo(host, port, 0, SOCK_STREAM):. </p>
  </blockquote>
  
  <p>Any ideas?</p>