I'm using Ansible to update a pool of EC2 servers with a rolling update, in batches of 25%. In between batches, I'm pausing long enough for the server health checks to start to pass again (since they'll fail while the application server restarts).
The question is, can I skip the delay on the final pass so the playbook will finish sooner? Here is the script. The last line is the API I want:
---
- hosts: tag_deploy_environment_development
serial: "25%"
remote_user: ec2-user
become: no
vars:
health_check_healthy_threshold: 2
health_check_interval: 10
server_port: 80
tasks:
#- debug: var=vars
#- debug: var=ansible_facts
- name: "Copy the current server version from disk"
include_role:
name: deploy-code
tasks_from: push-files
- name: "Wait for {{ server_port }} to become available"
wait_for:
port: "{{ server_port }}"
timeout: 60
state: started
# I would like to check whether we are on the final batch,
# and don't pause in that case:
- pause:
seconds: "{{ health_check_healthy_threshold * health_check_interval }}"
prompt: Waiting to allow AWS health checks to pass
when: ansible_facts['remaining_batches'] > 0