Haproxy cookbook

Haproxy frontend attributes are not showing up

We are trying to configure following frontend using haproxy cookbook

frontend http
bind :80
option http-keep-alive
rspidel ^Server:. ** **rspidel ^X-Powered-By:. <em>
rspidel ^X-AspNet-Version:. $

frontend.rb

haproxy_frontend frontend do
bind node['haproxy'][frontend]['bind']
option node['haproxy'][frontend]['option']
mode node['haproxy'][frontend]['mode']
extra_options node['haproxy'][frontend]['extra_options']
acl node['haproxy'][frontend]['acl']
use_backend node['haproxy'][frontend]['backend']
default_backend node['haproxy'][frontend]['default_backend']
end

attributes.rb
default['haproxy']['http']['extra_options'] = { 'rspidel' => '^Server:. ', 'rspidel' => '^X-Powered-By:.* ', 'rspidel' => '^X-AspNet-Version:.$' }

Problem:
After running the chef client I was expecting all of the attributes related to "rspidel" will show up under frontend, instead only "rspidel ^Server:.*$" exist in haproxy.

Chef-client resulted in following WARNING's

/home/ganga/chef-repo/.chef/local-mode-cache/cache/cookbooks/nrhl_haproxy/attributes/erpfcfrontend.rb:37: warning: key "rspidel" is duplicated and overwritten on line 37
/home/ganga/chef-repo/.chef/local-mode-cache/cache/cookbooks/nrhl_haproxy/attributes/erpfcfrontend.rb:37: warning: key "rspidel" is duplicated and overwritten on line 37
/home/ganga/chef-repo/.chef/local-mode-cache/cache/cookbooks/nrhl_haproxy/attributes/erpfcfrontend.rb:48: warning: key "rspidel" is duplicated and overwritten on line 48
/home/ganga/chef-repo/.chef/local-mode-cache/cache/cookbooks/nrhl_haproxy/attributes/erpfcfrontend.rb:48: warning: key "rspidel" is duplicated and overwritten on line 48

CookBook Version: 8.1.1
Chef Client Version: 15.4.45
OS: Centos7

Can't you make extra options just strings?

I haven't tried that, as per the definition it has to be a HASH.

Can you show me how I can make extra options as strings?

default['haproxy']['http']['extra_options'] = { 'rspidel' => '^Server:. ', 'rspidel' => '^X-Powered-By:. ', 'rspidel' => '^X-AspNet-Version:. $' }*

You can have multiple configurations of the same name with different options by specifying the different options within an Array.

So:
'config_statement' => ['options_1, 'options_2', 'options_3']

Will generate:
config_statement options_1;
config_statement options_2;
config_statement options_3;

2 Likes

Thanks @bmhughes. It worked for me.