From 8bf0c8dc5ce53e90ff6b593ca480c11f51a77b3b Mon Sep 17 00:00:00 2001 From: davixx Date: Fri, 15 Feb 2013 19:14:01 +0100 Subject: [PATCH] Solving bug https://github.com/ansible/ansible/issues/2004 Now handle positive integer value in virtual files if they are separated by group of space characters where the count is unpredictable. Thanks to romeotheriault for filing this bug. --- library/sysctl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/library/sysctl b/library/sysctl index c92df256907..3de0659e6a0 100644 --- a/library/sysctl +++ b/library/sysctl @@ -79,6 +79,7 @@ author: David "DaviXX" CHANIAL import os import tempfile +import re # ============================================================== @@ -185,13 +186,22 @@ def sysctl_check(current_step, **sysctl_args): if current_step == 'after' and sysctl_args['checks'] in ['after', 'both']: if sysctl_args['value'] is not None: + + # reading the virtual file f = open(sysctl_args['key_path'],'r') output = f.read() f.close() output = output.strip(' \t\n\r') + + # multi positive integer values separated by spaces as described in issue #2004 : + if re.search('^([\d\s]+)$', sysctl_args['value']): + # replace all groups of spaces by one space + output = re.sub('(\s+)', ' ', output) + + # normal case, finded value must be equal to the submitted value : if output != sysctl_args['value']: return 1, 'key seems not set to value even after update/sysctl, founded : <%s>, wanted : <%s>' % (output, sysctl_args['value']) - + return 0, '' # weird end