title: ec2_ami ansible module causes AWS instance to be unreachable
body: <p>I'm running and Ansible AWX 1.0.7.2 server, using Ansible 2.6.2 on Ubuntu 18.04.1 LTS.</p>
  
  <p>I'm attempting to create an Ansible playbook (used in AWX) which does the following:</p>
  
  <ul>
  <li>creates an AMI of an AWS instance</li>
  <li>waits for the instance to be available again</li>
  <li>installs updates to the server</li>
  <li>deletes AMIs over a week old</li>
  </ul>
  
  <p>My workbook is working on most hosts. However, on two of my instances, the AMIs are being created, but after that the hosts are showing as unreachable and the plays after are failing.</p>
  
  <p>This is the playbook I'm using:</p>
  
  <pre><code>---
  - hosts: all
    remote_user: "{{ remote_user }}"
    tasks:
    - name: Create an AMI for backup
      ec2_ami:
        instance_id: "{{ instance_id }}"
        name: "{{ inventory_hostname }}-{{ ansible_date_time.iso8601_basic_short }}"
        tags:
          Name: "{{ inventory_hostname }}-{{ ansible_date_time.iso8601_basic_short }}"
      register: result
  
    - name: Pause for 120 seconds to allow instance to become reachable again
      pause: seconds=120
  
    - include_tasks: update-RedHat.yml
      when: (ansible_os_family == 'RedHat' and result.changed|default(false)|bool == true)
  
    - include_tasks: update-Debian.yml
      when: (ansible_os_family == 'Debian' and result.changed == true)
  </code></pre>
  
  <p>And the output where the playbook is failing:</p>
  
  <pre><code>fatal: [testserver.mydomain.com]: UNREACHABLE! =&gt; {
      "changed": false,
      "msg": "Failed to connect to the host via ssh: OpenSSH_7.6p1 Ubuntu-4, OpenSSL 1.0.2n  7 Dec 2017\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 3353\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Control master terminated unexpectedly\r\nShared connection to testserver.mydomain.com closed.\r\n",
      "unreachable": true
  </code></pre>
  
  <p>}</p>
  
  <p>Both if the instances that are failing have large (256GB) volumes attached and become available for 30-60 seconds when the image is being created and I presume this is the problem. However, multiple methods for inserting a delay don't seem to help - it seems ansible is checking for connectivity immediately no matter what I do.</p>
  
  <p>You can see the pause after the image is created. This is working on the other hosts, but on the failing ones it's not getting this far as it's already showing as unreachable before it gets to that.</p>
  
  <p>I tried this after the image creation step:</p>
  
  <pre><code>  - name: wait for host to come back up
      wait_for: host={{ inventory_hostname }} port=22 delay=60 timeout=180 state=started
  </code></pre>
  
  <p>But got the same failure and message.</p>
  
  <p>It seems the error is within the <code>ec2_ami</code> task, so I also tried inserting a <code>wait</code>:</p>
  
  <pre><code>---
  - hosts: all
    remote_user: "{{ remote_user }}"
    wait: yes
    tasks:
    - name: Create an AMI for backup
      ec2_ami:
        instance_id: "{{ instance_id }}"
        name: "{{ inventory_hostname }}-{{ ansible_date_time.iso8601_basic_short }}"
        tags:
          Name: "{{ inventory_hostname }}-{{ ansible_date_time.iso8601_basic_short }}"
      register: result
  </code></pre>
  
  <p>But this made no difference either, the instance is still showing as unreachable.</p>
  
  <p>Is there any way I can get around this?</p>