Last active
March 9, 2017 20:38
-
-
Save stefhen/2572426aade68c985be3a8572d3c48aa to your computer and use it in GitHub Desktop.
generate haproxy.cfg with chef
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Wrapper cookbook snippet and upstream cookbook here: https://github.com/sous-chefs/haproxy | |
haproxy_lb 'backend-service-name-here' do | |
params([ | |
'bind 0.0.0.0:80', | |
'mode http', | |
'balance roundrobin', | |
'option forwardfor', | |
'option http-server-close' | |
]) | |
@params << "maxconn #{node['webloadbalancer']['dispatchers']['maxconn']}" | |
# populate backend servers via chef search | |
search_criteria = '' | |
search_criteria << %(chef_environment:#{node.chef_environment}) | |
search_criteria << ' AND ' | |
search_criteria << %(run_list:recipe\\[#{service_cookbook}\\:\\:#{service_recipe}\\]) | |
search('node', search_criteria).sort.each do |n| | |
@params << "server #{n['name']} #{n['ipaddress']}:#{node['webloadbalancer']['forward-port']} weight 100 check inter 5s rise 2 fall 3" | |
end | |
end | |
include_recipe 'haproxy::manual' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment