@ -159,7 +159,6 @@ import binascii
import copy
import copy
import hashlib
import hashlib
import json
import json
import locale
import os
import os
import re
import re
import shutil
import shutil
@ -215,12 +214,12 @@ def get_cert_days(module, cert_file):
_ , out , _ = module . run_command ( openssl_cert_cmd , check_rc = True )
_ , out , _ = module . run_command ( openssl_cert_cmd , check_rc = True )
try :
try :
not_after_str = re . search ( r " \ s+Not After \ s*: \ s+(.*) " , out . decode ( ' utf8 ' ) ) . group ( 1 )
not_after_str = re . search ( r " \ s+Not After \ s*: \ s+(.*) " , out . decode ( ' utf8 ' ) ) . group ( 1 )
not_after = datetime . datetime. fromtimestamp( time . mktime ( time . strptime ( not_after_str , ' % b %d % H: % M: % S % Y % Z ' ) ) )
not_after = datetime . fromtimestamp( time . mktime ( time . strptime ( not_after_str , ' % b %d % H: % M: % S % Y % Z ' ) ) )
except AttributeError :
except AttributeError :
module . fail_json ( msg = " No ' Not after ' date found in {0} " . format ( cert_file ) )
module . fail_json ( msg = " No ' Not after ' date found in {0} " . format ( cert_file ) )
except ValueError :
except ValueError :
module . fail_json ( msg = " Failed to parse ' Not after ' date of {0} " . format ( cert_file ) )
module . fail_json ( msg = " Failed to parse ' Not after ' date of {0} " . format ( cert_file ) )
now = datetime . datetime. utcnow( )
now = datetime . utcnow( )
return ( not_after - now ) . days
return ( not_after - now ) . days
@ -789,7 +788,7 @@ def main():
)
)
# AnsibleModule() changes the locale, so change it back to C because we rely on time.strptime() when parsing certificate dates.
# AnsibleModule() changes the locale, so change it back to C because we rely on time.strptime() when parsing certificate dates.
locale. setlocale ( locale . LC_ALL , " C " )
module. run_command_environ_update = dict ( LANG = ' C ' , LC_ALL = ' C ' , LC_MESSAGES = ' C ' , LC_CTYPE = ' C ' )
cert_days = get_cert_days ( module , module . params [ ' dest ' ] )
cert_days = get_cert_days ( module , module . params [ ' dest ' ] )
if cert_days < module . params [ ' remaining_days ' ] :
if cert_days < module . params [ ' remaining_days ' ] :