Skip to content

global section parameters are sorted alphabetically, breaking order-dependent directives #639

Description

@maxadamo

Describe the Bug

The global section of haproxy-base.cfg.epp renders configuration parameters sorted alphabetically. This breaks HAProxy directives that require a specific ordering to take effect.

A concrete example: tune.lua.bool-sample-conversion must appear before any lua-load or lua-load-per-thread directive. Because l sorts before t, lua-load is always rendered first, causing HAProxy to silently ignore tune.lua.bool-sample-conversion with the following warning:

config : parsing [/etc/haproxy/haproxy.cfg:9] : ignored as some Lua was loaded already.
"tune.lua.bool-sample-conversion" must be set before any "lua-load" or
"lua-load-per-thread" directive for it to be considered.

This is a silent misconfiguration — HAProxy starts without error, but the tunable has no effect.

Expected Behavior

The module should either preserve the order in which parameters are supplied in the hash, or provide a mechanism to control ordering explicitly. Alphabetical sorting should not silently override HAProxy's own directive ordering requirements.

Steps to Reproduce

  1. Configure the haproxy class with both tune.lua.bool-sample-conversion and lua-load in the global parameters hash
  2. Apply the Puppet catalog
  3. Inspect the rendered /etc/haproxy/haproxy.cfglua-load appears before tune.lua.bool-sample-conversion due to alphabetical sorting
  4. Restart HAProxy and observe the warning in the logs

Workaround

Prepending a space to the key name forces it to sort before l:

{ ' tune.lua.bool-sample-conversion' => 'normal' },
{ 'lua-load' => '/etc/haproxy/lua/cors.lua' },

This is clearly unintended use of the API and fragile — it relies on ASCII sort order of whitespace preceding letters.

Suggested Fix

Make sorting optional. A sort_global_params parameter defaulting to true would preserve backward compatibility while allowing users to opt out when directive ordering matters:

class { 'haproxy':
  sort_global_params => false,
  global_options => {
    'tune.lua.bool-sample-conversion' => 'normal',
    'lua-load'                        => '/etc/haproxy/lua/cors.lua',
  }
}

Alternatively, preserving insertion order by default (since Ruby hashes are ordered since 1.9) would be a simpler fix with no API change required.

Environment

  • puppetlabs-haproxy version: 8.2.0
  • HAProxy version: 3.2
  • Platform: Ubuntu 24.04
  • Puppet version: 8.x

Additional Context

The alphabetical sort is implemented in haproxy-base.cfg.epp line 2. Other HAProxy directives may have similar ordering requirements — this is not specific to Lua. The fix should be general rather than special-casing individual directives.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions