Normalise string sysctl values by trying integer conversion.
@@ -14,6 +14,7 @@ import six
from six.moves import filterfalse, shlex_quote
from pyinfra.api import FunctionCommand, operation, StringCommand
+from pyinfra.api.util import try_int
from . import files
from .util.files import chmod, sed_replace
@@ -368,7 +369,7 @@ def sysctl(
server.sysctl(
name='Change the fs.file-max value',
key='fs.file-max',
- value='100000',
+ value=100000,
persist=True,
)
'''
@@ -379,6 +380,12 @@ def sysctl(
else value
)
+ value = (
+ [try_int(v) for v in value]
+ if isinstance(value, list)
+ else try_int(value)
+ )
+
existing_value = host.fact.sysctl.get(key)
if not existing_value or existing_value != value:
yield 'sysctl {0}={1}'.format(key, string_value)
