mirror of
https://github.com/valitydev/salt.git
synced 2024-11-09 01:36:48 +00:00
Merge pull request #21360 from terminalmage/issue21300
Fix traceback in sysctl.present state output
This commit is contained in:
commit
1c23c1f784
@ -15,6 +15,9 @@ Control the kernel sysctl system.
|
||||
# Import python libs
|
||||
import re
|
||||
|
||||
# Import salt libs
|
||||
from salt.exceptions import CommandExecutionError
|
||||
|
||||
|
||||
def __virtual__():
|
||||
'''
|
||||
@ -58,48 +61,67 @@ def present(name, value, config=None):
|
||||
if not configured:
|
||||
ret['result'] = None
|
||||
ret['comment'] = (
|
||||
'Sysctl option {0} might be changed, we failed to check config file at {1}.\n'
|
||||
'The file is either unreadable, or missing.').format(name, config)
|
||||
'Sysctl option {0} might be changed, we failed to check '
|
||||
'config file at {1}. The file is either unreadable, or '
|
||||
'missing.'.format(name, config)
|
||||
)
|
||||
return ret
|
||||
if name in current and name not in configured:
|
||||
if re.sub(' +|\t+', ' ', current[name]) != re.sub(' +|\t+', ' ', str(value)):
|
||||
if re.sub(' +|\t+', ' ', current[name]) != \
|
||||
re.sub(' +|\t+', ' ', str(value)):
|
||||
ret['result'] = None
|
||||
ret['comment'] = (
|
||||
'Sysctl option {0} set to be changed to {1}'
|
||||
).format(name, value)
|
||||
'Sysctl option {0} set to be changed to {1}'
|
||||
.format(name, value)
|
||||
)
|
||||
return ret
|
||||
else:
|
||||
ret['result'] = None
|
||||
ret['comment'] = 'Sysctl value is currently set on the running system but not in a config file.\n'\
|
||||
'Sysctl option {0} set to be changed to {1} in config file.'.format(name, value)
|
||||
ret['comment'] = (
|
||||
'Sysctl value is currently set on the running system but '
|
||||
'not in a config file. Sysctl option {0} set to be '
|
||||
'changed to {1} in config file.'.format(name, value)
|
||||
)
|
||||
return ret
|
||||
elif name in configured and name not in current:
|
||||
ret['result'] = None
|
||||
ret['comment'] = 'Sysctl value {0} is present in configuration file but is not present in the running config.\n'\
|
||||
'The value {0} is set to be changed to {1} '
|
||||
ret['comment'] = (
|
||||
'Sysctl value {0} is present in configuration file but is not '
|
||||
'present in the running config. The value {0} is set to be '
|
||||
'changed to {1}'.format(name, value)
|
||||
)
|
||||
return ret
|
||||
elif name in configured and name in current:
|
||||
if str(value).split() == __salt__['sysctl.get'](name).split():
|
||||
ret['result'] = True
|
||||
ret['comment'] = 'Sysctl value {0} = {1} is already set'.format(
|
||||
name,
|
||||
value
|
||||
)
|
||||
ret['comment'] = (
|
||||
'Sysctl value {0} = {1} is already set'
|
||||
.format(name, value)
|
||||
)
|
||||
return ret
|
||||
# otherwise, we don't have it set anywhere and need to set it
|
||||
ret['result'] = None
|
||||
ret['comment'] = 'Sysctl option {0} set to be changed to {1}'.format(name, value)
|
||||
ret['comment'] = (
|
||||
'Sysctl option {0} would be changed to {1}'.format(name, value)
|
||||
)
|
||||
return ret
|
||||
|
||||
update = __salt__['sysctl.persist'](name, value, config)
|
||||
try:
|
||||
update = __salt__['sysctl.persist'](name, value, config)
|
||||
except CommandExecutionError as exc:
|
||||
ret['result'] = False
|
||||
ret['comment'] = (
|
||||
'Failed to set {0} to {1}: {2}'.format(name, value, exc)
|
||||
)
|
||||
return ret
|
||||
|
||||
if update == 'Updated':
|
||||
ret['changes'] = {name: value}
|
||||
ret['comment'] = 'Updated sysctl value {0} = {1}'.format(name, value)
|
||||
elif update == 'Already set':
|
||||
ret['comment'] = 'Sysctl value {0} = {1} is already set'.format(
|
||||
name,
|
||||
value
|
||||
)
|
||||
ret['comment'] = (
|
||||
'Sysctl value {0} = {1} is already set'
|
||||
.format(name, value)
|
||||
)
|
||||
|
||||
return ret
|
||||
|
Loading…
Reference in New Issue
Block a user