Changed when new sysctl file is created
When destination sysctl file is missing, it is created. But, for idempotency purposes, the creation process now takes place just before it is used, in the main code path so an empty file is not left over if the code module.fail_jsons before the file is really used.
This commit is contained in:
parent
aea822c47a
commit
05d45fc1fa
1 changed files with 8 additions and 11 deletions
19
sysctl
19
sysctl
|
@ -155,17 +155,6 @@ def sysctl_check(current_step, **sysctl_args):
|
|||
if not os.access(sysctl_args['key_path'], os.R_OK):
|
||||
return 1, 'key_path is not a readable file, key seems to be uncheckable'
|
||||
|
||||
# sysctl file exists and openable ?
|
||||
# TODO choose if prefered to use os.access() instead try/catch on open
|
||||
if current_step == 'before':
|
||||
if not os.access(sysctl_args['sysctl_file'], os.W_OK):
|
||||
try:
|
||||
f = open(sysctl_args['sysctl_file'],'w')
|
||||
f.write('')
|
||||
f.close()
|
||||
except IOError, e:
|
||||
return 1, 'unable to create supplied sysctl file (directory missing)'
|
||||
|
||||
# no smart checks at this step ?
|
||||
if sysctl_args['checks'] == 'none':
|
||||
return 0, ''
|
||||
|
@ -246,6 +235,14 @@ def main():
|
|||
if res != 0:
|
||||
module.fail_json(msg='checks_before failed with: ' + msg)
|
||||
|
||||
if not os.access(sysctl_args['sysctl_file'], os.W_OK):
|
||||
try:
|
||||
f = open(sysctl_args['sysctl_file'],'w')
|
||||
f.write('')
|
||||
f.close()
|
||||
except IOError, e:
|
||||
module.fail_json(msg='unable to create supplied sysctl file (destination directory probably missing)')
|
||||
|
||||
# reading the file
|
||||
for line in open(sysctl_args['sysctl_file'], 'r').readlines():
|
||||
if not line.strip():
|
||||
|
|
Loading…
Add table
Reference in a new issue