Cookbooks
keepalived
documentation
Keepalived Real Server

keepalived_real_server

back to resource list (opens in a new tab)

The keepalived_real_server resource can be used to configure real_server blocks within a virtual_server. They are managed as separate configuration files, and injected into the virtual_server block via include directives configured via the real_servers property of the keepalived_virtual_server resource.

A keepalived_real_server can be associated with a healthcheck via an include of a file containing a check sub-block using the healthcheck property. If using any of the health check resources provided by this cookbook, you can use the config_file method on the associated resource to automatically get the appropriate configuration path, as shown below.

More information available at https://www.keepalived.org/manpage.html (opens in a new tab)

Actions

  • :create
  • :delete

Properties

NameTypeDefaultDescriptionAllowed Values
ipaddressStringnilIP Address of the Server
portIntegernilPort of the Server
healthcheckStringnilIncludes a healthcheck file
weightIntegernilScript to run for notifications when any transition of state happens
inhibit_on_failuretrue, falsenil
notify_upStringnilScript to execute when healthchecker considers the service as up
notify_downStringnilScript to execute when healthchecker considers the service as down
config_directoryString/etc/keepalived/servers.ddirectory for the config file to reside in
config_fileString::File.join(config_directory, 'keepalived_real_server__#{ipaddress}-#{port}__.conf')full path to the config file
cookbookStringkeepalivedWhich cookbook to look in for the template
sourceStringreal_server.conf.erbName of the template to render

Examples

keepalived_real_server 'Secure Web Server' do
  ipaddress ipaddress
  port      port
  notify_up '/usr/local/bin/keepalived-notify-up.sh'
  notify_down '/usr/local/bin/keepalived-notify-down.sh'
  inhibit_on_failure true
  notifies :restart, 'service[keepalived]', :delayed
end
keepalived_http_get 'health_check_url' do
  nb_get_retry 3
  url path: '/health_check', status_code: 200
  notifies :restart, 'service[keepalived]', :delayed
end
 
keepalived_real_server 'fe01' do
  ipaddress '192.168.1.1'
  port 80
  weight 5
  inhibit_on_failure true
  healthcheck resources(keepalived_http_get: 'health_check_url').config_file
  notifies :restart, 'service[keepalived]', :delayed
end