Pipe output from '/sbin/sysctl -n' through sed to remove spaces/tabs #76
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.