mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #5676 from simonz05/bugfix-sysctl-multivalue2
Correctly compare values returned by 'sysctl -e -n'
This commit is contained in:
commit
7b76ad9e62
1 changed files with 16 additions and 1 deletions
|
@ -148,7 +148,7 @@ class SysctlModule(object):
|
|||
if self.args['sysctl_set']:
|
||||
if self.proc_value is None:
|
||||
self.changed = True
|
||||
elif self.proc_value != self.args['value']:
|
||||
elif not self._values_is_equal(self.proc_value, self.args['value']):
|
||||
self.changed = True
|
||||
self.set_proc = True
|
||||
|
||||
|
@ -161,6 +161,21 @@ class SysctlModule(object):
|
|||
if self.set_proc:
|
||||
self.set_token_value(self.args['name'], self.args['value'])
|
||||
|
||||
def _values_is_equal(self, a, b):
|
||||
"""Expects two string values. It will split the string by whitespace
|
||||
and compare each value. It will return True if both lists are the same,
|
||||
contain the same elements and the same order."""
|
||||
if a is None or b is None:
|
||||
return False
|
||||
|
||||
a = a.split()
|
||||
b = b.split()
|
||||
|
||||
if len(a) != len(b):
|
||||
return False
|
||||
|
||||
return len([i for i, j in zip(a, b) if i == j]) == len(a)
|
||||
|
||||
# ==============================================================
|
||||
# SYSCTL COMMAND MANAGEMENT
|
||||
# ==============================================================
|
||||
|
|
Loading…
Reference in a new issue