@ -138,6 +138,7 @@ def validate_size(value, module):
def map_obj_to_commands ( updates , module , os_version ) :
def map_obj_to_commands ( updates , module , os_version ) :
dest_group = ( ' console ' , ' monitor ' , ' buffered ' , ' on ' )
commands = list ( )
commands = list ( )
want , have = updates
want , have = updates
for w in want :
for w in want :
@ -149,23 +150,36 @@ def map_obj_to_commands(updates, module, os_version):
state = w [ ' state ' ]
state = w [ ' state ' ]
del w [ ' state ' ]
del w [ ' state ' ]
if facility :
w [ ' dest ' ] = ' facility '
if state == ' absent ' and w in have :
if state == ' absent ' and w in have :
if dest == ' host ' :
if dest :
if ' 12. ' in os_version :
if dest == ' host ' :
commands . append ( ' no logging {0} ' . format ( name ) )
if ' 12. ' in os_version :
commands . append ( ' no logging {0} ' . format ( name ) )
else :
commands . append ( ' no logging host {0} ' . format ( name ) )
elif dest in dest_group :
commands . append ( ' no logging {0} ' . format ( dest ) )
else :
else :
commands . append ( ' no logging host {0} ' . format ( name ) )
module . fail_json ( msg = ' dest must be among console, monitor, buffered, host, on ' )
elif dest :
commands . append ( ' no logging {0} ' . format ( dest ) )
else :
module . fail_json ( msg = ' dest must be among console, monitor, buffered, host, on ' )
if facility :
if facility :
commands . append ( ' no logging facility {0} ' . format ( facility ) )
commands . append ( ' no logging facility {0} ' . format ( facility ) )
if state == ' present ' and w not in have :
if state == ' present ' and w not in have :
if facility :
if facility :
commands . append ( ' logging facility {0} ' . format ( facility ) )
present = False
for entry in have :
if entry [ ' dest ' ] == ' facility ' and entry [ ' facility ' ] == facility :
present = True
if not present :
commands . append ( ' logging facility {0} ' . format ( facility ) )
if dest == ' host ' :
if dest == ' host ' :
if ' 12. ' in os_version :
if ' 12. ' in os_version :
@ -177,10 +191,17 @@ def map_obj_to_commands(updates, module, os_version):
commands . append ( ' logging on ' )
commands . append ( ' logging on ' )
elif dest == ' buffered ' and size :
elif dest == ' buffered ' and size :
if level and level != ' debugging ' :
present = False
commands . append ( ' logging buffered {0} {1} ' . format ( size , level ) )
else :
for entry in have :
commands . append ( ' logging buffered {0} ' . format ( size ) )
if entry [ ' dest ' ] == ' buffered ' and entry [ ' size ' ] == size and entry [ ' level ' ] == level :
present = True
if not present :
if level and level != ' debugging ' :
commands . append ( ' logging buffered {0} {1} ' . format ( size , level ) )
else :
commands . append ( ' logging buffered {0} ' . format ( size ) )
else :
else :
if dest :
if dest :
@ -205,18 +226,12 @@ def parse_size(line, dest):
size = None
size = None
if dest == ' buffered ' :
if dest == ' buffered ' :
match = re . search ( r ' logging buffered (\ S+) ' , line , re . M )
match = re . search ( r ' logging buffered (?: (\ d+))?(?: [a-z]+)? ' , line , re . M )
if match :
if match :
try :
if match . group ( 1 ) is not None :
int_size = int ( match . group ( 1 ) )
size = match . group ( 1 )
except ValueError :
else :
int_size = None
size = " 4096 "
if int_size :
if isinstance ( int_size , int ) :
size = str ( match . group ( 1 ) )
else :
size = str ( 4096 )
return size
return size
@ -241,15 +256,12 @@ def parse_level(line, dest):
else :
else :
if dest == ' buffered ' :
if dest == ' buffered ' :
match = re . search ( r ' logging buffered (?:\ d+ )([a-z]+)' , line , re . M )
match = re . search ( r ' logging buffered (?: \ d+ )?(?: ([a-z]+))? ' , line , re . M )
else :
else :
match = re . search ( r ' logging {0} ( \ S+) ' . format ( dest ) , line , re . M )
match = re . search ( r ' logging {0} ( \ S+) ' . format ( dest ) , line , re . M )
if match :
if match and match . group ( 1 ) in level_group :
if match . group ( 1 ) in level_group :
level = match . group ( 1 )
level = match . group ( 1 )
else :
level = ' debugging '
else :
else :
level = ' debugging '
level = ' debugging '
@ -412,5 +424,6 @@ def main():
module . exit_json ( * * result )
module . exit_json ( * * result )
if __name__ == ' __main__ ' :
if __name__ == ' __main__ ' :
main ( )
main ( )