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

Pipe output from '/sbin/sysctl -n' through sed to remove spaces/tabs

Open PaulGale opened this issue 1 year ago • 1 comments

The exec resource "enforce-sysctl-value-${qtitle}" for enforcing sysctl values fails for kernel parameters whose values are returned as a white space separated tuple.

Example:

% /sbin/sysctl -n net.ipv4.tcp_wmem 4096 229376 4194304

Each value in the results is separated by a horizontal tab which, if not removed, causes the call to /usr/bin/test to always fail and Puppet to report that a change has been applied when none should have.

One can verify the presence of tabs in the output by piping it through /usr/bin/xxd.

% /sbin/sysctl -n net.ipv4.tcp_wmem | xxd 00000000: 3430 3936 0932 3239 3337 3609 3431 3934 4096.229376.4194 00000010: 3330 340a 304.

Tabs are the bytes with the value 09.

By piping the output through sed tabs are converted to a single white space making comparison possible:

% /sbin/sysctl -n net.ipv4.tcp_wmem | sed -r -e 's/[ \t]+/ /g' | xxd 00000000: 3430 3936 2032 3239 3337 3620 3431 3934 4096 229376 4194 00000010: 3330 340a 304.

Space characters are the bytes with the value 20.

I would have included an automated unit test to verify this but I am unfamiliar with how write tests for Puppet modules. However, I did test it manually and it works on RHEL 8.

Kernel parameters that don't contain tabs are unaffected and are enforced as normal.

PaulGale avatar May 03 '23 04:05 PaulGale

@thias Any chance of getting this merged and released, if you're still looking?

nebakke avatar Aug 09 '24 01:08 nebakke