Our trade portal runs on six application servers behind a pair of HAProxy machines, and Ansible writes the HAProxy configuration. The template loops over the app group and takes each server's address from its facts:
server {{ host }} {{ hostvars[host]['ansible_default_ipv4']['address'] }}:8080 check
To make playbook runs faster, we turned on fact caching: gathering = smart and a jsonfile cache on the control node. With smart gathering Ansible collects facts from a host only when the cache has none for it, and the cache keeps them for fact_caching_timeout, which defaults to a day.
On a Wednesday in October we replaced two of the application servers with new instances built from a new image. They came up with new private addresses, the site playbook configured them, and they passed their checks.…