Create a varnish director using groups
If you have varnish fronting your webservers you can use ansible's hostvars inventory variable and jinja2 to automatically generate the director VCL.
This below assumes you have a group named webservers that includes all the hosts varnish must reverse proxy to, and that that group was run in the current or previous playbook.
vcl.j2
{% for host in groups['webservers'] %}
backend web{{loop.index}} {
.host = "{{hostvars[host]['ansible_fqdn']}}";
.probe = { .url = "/healthtest.html";
.expected_response=200;
.interval = 15s;
.timeout = 7s;
.window = 5;
.threshold = 3;
}
}
{% endfor %}
director default_web round-robin {
{% for host in groups['webservers'] %}
{ .backend = web{{loop.index}}; }
{% endfor %}
}
Written by Darryl Stoflet
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ansible
Authors
Misha Behersky
78.97K
tartansandal
73.31K
Related Tags
#ansible
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#