puppet-keepalived icon indicating copy to clipboard operation
puppet-keepalived copied to clipboard

LVS real server options - upper case not allowed by puppet but needed by keepalvied

Open realpdm opened this issue 10 years ago • 6 comments

When setting up a real server settings in the keepalived.conf file is which check to use for the server. All of these checks seem to be required to be upper case. Ie, HTTP_GET works but http_get does not work.

Due to the way options are passed in the module the template takes the options hash and translates that directly into keepalived.conf config.

It turns out that puppet does not want you to start variable names with a capital letter. ( https://docs.puppetlabs.com/puppet/3.8/reference/deprecated_language.html#variable-names-beginning-with-capital-letters ).

This works: options => { weight => 1, http_get => { ....

This does not work options => { weight => 1, HTTP_GET => { .... The puppet parser says: Error: Could not parse for environment production: Syntax error at 'HTTP_GET'; expected '}' at...

I'm pondering ways to solve this and will send a PR if I figure it out. I wanted to raise the issue in case someone has already solved it or has a bright idea of how to do so.

The best ideas I have so far is to make the check be specially called out and not part of the options template or to have some sort of postfix to the variable name that says to upper case is when turned into config.

realpdm avatar Aug 06 '15 00:08 realpdm

The easiest way I can think of is adding something among the lines of:

sorted_options.each_with_index do |(key, value), index|
  if value.is_a?(Hash)
    if key =~ /http_get/
      buffer << key.upcase
    else
      buffer << "\n" unless index == 0
      buffer << "\n#{indent}#{key} {"
      buffer << format_options(value, indent_level+1)
      buffer << "\n#{indent}}"
  elsif value === true
    ...
  end
end

arioch avatar Aug 06 '15 07:08 arioch

I was hoping to have something more general purpose for all checks. Maybe in the main module store the possible checks from keepalived in an array and in the template match each against that array. If it matches key.upcase. I'll give this idea a try and see how it looks.

realpdm avatar Aug 06 '15 15:08 realpdm

Ok that seems to work somewhat cleanly. Posted here just for FYI, I have some other ideas on how to re-use a common set of backends for multiple VIPs so I will send a PR through once I have that worked out. I'll do them separately though.

diff -r /home/pmoore/puppet-keepalived/manifests/lvs/real_server.pp ./manifests/lvs/real_server.pp
37a38
>   $valid_healthchecks = [ 'HTTP_GET','SSL_GET','TCP_CHECK','SMTP_CHECK','MISC_CHECK' ]
diff -r /home/pmoore/puppet-keepalived/templates/lvs_real_server.erb ./templates/lvs_real_server.erb
13c13,14
<         buffer << "\n#{indent}#{key} {"
---
>         format_key = key.upcase if @valid_healthchecks.any?{ |s| s.casecmp(key)==0 }
>         buffer << "\n#{indent}#{format_key || key } {"

realpdm avatar Aug 06 '15 17:08 realpdm

That's an excellent idea. If you spec & doc it I'll merge it. :+1:

arioch avatar Aug 06 '15 19:08 arioch

This is working without any problems:

options        => {
      'SSL_GET' => {
        url             => {
          path   => '/some/path',
          digest => '2f4e0fd321d2d5a573861afa6193d7db',
        },
        connect_timeout => 1,
        connect_port    => 443,
      },
    },

saz avatar Sep 25 '19 19:09 saz

I think this issue can be closed.

saz avatar Sep 25 '19 19:09 saz