Skip to content

Evaluation Error: Unknown variable: '_sort_options_alphabetic'. #577

Description

@kBite

EDIT: Well, only saw the PR after submitting. This issue is fixed by #576


While testing v7.2.0 I noticed Puppet runs failing due to Evaluation Error: Unknown variable: '_sort_options_alphabetic'.

Info: Using environment 'haproxy_v7_2_0'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Unknown variable: '_sort_options_alphabetic'. (file: /etc/puppetlabs/code/environments/haproxy_v7_2_0/modules/haproxy/manifests/backend.pp, line: 132, column: 35) on node some-server.com
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run

With conversion of *.erb to *.epp templates $_sort_options_alphabetic is now given as template parameter:

$parameters = {
  'section_name'             => $section_name,
  'mode'                     => $mode,
  'description'              => $description,
  '_sort_options_alphabetic' => $_sort_options_alphabetic,
  'options'                  => $options,
}

This surfaces a bug in the variables assignment logic: in case $options is a Hash, but the key option does not contain httpchk $_sort_options_alphabetic stays undefined (e.g. when using tcp-check instead).

...
  if $options.is_a(Hash) and 'option' in $options {
    if ('httpchk' in $options['option']) {
      warning('Overriding the value of $sort_options_alphabetic to "false" due to "httpchk" option defined')
      $_sort_options_alphabetic = false
    }
  } else {
    ...
  }
...

This wasn't an issue before, because the variable was only evaluated in the *.erb template. It was effectively treated as false.

There are multiple options to resolve this: (1) adding or ('tcp-check' in $options['option']) to the condition, (2) adding an else or elsif, (3) adding pick($_sort_options_alphabetic, false) to the parameters hash, or ... some less minimal options like refactoring the assignment and others I didn't think of.


On a side note: pick() is either redundant on line 108 or the stdlib's description of pick() isn't (fully) correct

$picked_sort_options_alphabetic = pick($sort_options_alphabetic, $haproxy::globals::sort_options_alphabetic)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions