LAB 1: Magic Variables for Service Discovery, Multiple Environments

Magic Variables for Service Discovery, Multiple Environments

file: ansible.cfg

fact_caching = yaml
fact_caching_connection = /tmp/facts

file: roles/geerlingguy.haproxy/templates/haproxy.cfg.j2

{% for host in groups['app']  %}
    server {‌{ hostvars[host]['ansible_hostname'] }} {‌{ hostvars[host]['ansible_eth0']['ipv4']['address'] }}:80 cookie {‌{ hostvars[host]['ansible_hostname'] }} check
{% endfor %}