---

- name: Wait for API node to come back up
  become: false
  local_action: >
      wait_for host="{{ inventory_hostname }}" port="{{ api_app_port }}"
      delay={{ delay | default(2) }}
      timeout={{ timeout | default(30) }}
- name: Register instance with loadbalancer again
  # Note that, on initialization of the whole environment, when there are
  # no origin servers yet behind the loadbalancer, this task could fail if
  # the loadbalancer is configured with a health check that fails one of
  # various status codes that could result from everything not being set
  # up yet.  You can get around this by having the loadbalancer simply
  # probe for port 80 while you're initializing everything, and then
  # switch it later to a HTTP check for a success response from a
  # particular resource.
  local_action: ec2_elb
  when: level == 'production' or level == 'staging'
  become: false
  args:
    instance_id: "{{ ansible_ec2_instance_id }}"
    ec2_elbs: "{{ api_elb_name }}"
    aws_access_key: "{{ aws_access_key }}"
    aws_secret_key: "{{ aws_secret_key }}"
    aws_region: "{{ aws_region }}"
    state: present
    wait_timeout: 22

---

- name: Wait for API node to come back up
  become: false
  local_action: >
      wait_for host="{{ ansible_ssh_host }}" port="{{ api_app_port }}"
      delay={{ delay | default(2) }}
      timeout={{ timeout | default(30) }}
- name: Register instance with loadbalancer again
  # Note that, on initialization of the whole environment, when there are
  # no origin servers yet behind the loadbalancer, this task could fail if
  # the loadbalancer is configured with a health check that fails one of
  # various status codes that could result from everything not being set
  # up yet.  You can get around this by having the loadbalancer simply
  # probe for port 80 while you're initializing everything, and then
  # switch it later to a HTTP check for a success response from a
  # particular resource.
  local_action: ec2_elb
  when: level == 'production' or level == 'staging'
  become: false
  args:
    instance_id: "{{ ansible_ec2_instance_id }}"
    ec2_elbs: "{{ api_elb_name }}"
    aws_access_key: "{{ aws_access_key }}"
    aws_secret_key: "{{ aws_secret_key }}"
    aws_region: "{{ aws_region }}"
    state: present
    wait_timeout: 22

Fix staging api wait_for task
Fix staging api wait_for task

In staging api deployment, use ansible_ssh_host because sometimes we
like to specify the hostname with that variable in inventory instead of
having to modify our /etc/hosts files. ansible_ssh_host should be
defined in either case, but inventory_host is not going to work if you
don't have a matching /etc/hosts entry.
