-
Notifications
You must be signed in to change notification settings - Fork 267
Description
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)
- According to https://github.com/puppetlabs/puppetlabs-stdlib/blob/main/REFERENCE.md#pick
pick()
returns "... the first value in a list of values that is not undefined or an empty string." - The defined type's parameter
$sort_options_alphabetic
is Boolean. There is/seems to be no way this parameter could beundef
or''
without failing the data type.