Fix for AnsiballZ when the remote clock is behind (#18660)

Some machines have system clocks which can fall behind (for instance,
a host without a CMOS battery like Raspberry Pi).  When managing those
machines we have to workaround the fact that the zip format does not
handle file timestamps before 1980.  The workaround is to substitute in
the timestamp from the controller instead of from the managed machine.

Fixes #18640
pull/18668/head
Toshio Kuratomi 8 years ago committed by GitHub
parent 4d78c784a6
commit 3c6d71522e

@ -22,6 +22,7 @@ __metaclass__ = type
import ast import ast
import base64 import base64
import datetime
import imp import imp
import json import json
import os import os
@ -317,7 +318,12 @@ if __name__ == '__main__':
# py3: zipped_mod will be text, py2: it's bytes. Need bytes at the end # py3: zipped_mod will be text, py2: it's bytes. Need bytes at the end
sitecustomize = u'import sys\\nsys.path.insert(0,"%%s")\\n' %% zipped_mod sitecustomize = u'import sys\\nsys.path.insert(0,"%%s")\\n' %% zipped_mod
sitecustomize = sitecustomize.encode('utf-8') sitecustomize = sitecustomize.encode('utf-8')
z.writestr('sitecustomize.py', sitecustomize) # Use a ZipInfo to work around zipfile limitation on hosts with
# clocks set to a pre-1980 year (for instance, Raspberry Pi)
zinfo = zipfile.ZipInfo()
zinfo.filename = 'sitecustomize.py'
zinfo.date_time = ( %(year)i, %(month)i, %(day)i, %(hour)i, %(minute)i, %(second)i)
z.writestr(zinfo, sitecustomize)
z.close() z.close()
exitcode = invoke_module(module, zipped_mod, ANSIBALLZ_PARAMS) exitcode = invoke_module(module, zipped_mod, ANSIBALLZ_PARAMS)
@ -680,6 +686,7 @@ def _find_snippet_imports(module_name, module_data, module_path, module_args, ta
interpreter_parts = interpreter.split(u' ') interpreter_parts = interpreter.split(u' ')
interpreter = u"'{0}'".format(u"', '".join(interpreter_parts)) interpreter = u"'{0}'".format(u"', '".join(interpreter_parts))
now=datetime.datetime.utcnow()
output.write(to_bytes(ACTIVE_ANSIBALLZ_TEMPLATE % dict( output.write(to_bytes(ACTIVE_ANSIBALLZ_TEMPLATE % dict(
zipdata=zipdata, zipdata=zipdata,
ansible_module=module_name, ansible_module=module_name,
@ -687,6 +694,12 @@ def _find_snippet_imports(module_name, module_data, module_path, module_args, ta
shebang=shebang, shebang=shebang,
interpreter=interpreter, interpreter=interpreter,
coding=ENCODING_STRING, coding=ENCODING_STRING,
year=now.year,
month=now.month,
day=now.day,
hour=now.hour,
minute=now.minute,
second=now.second,
))) )))
module_data = output.getvalue() module_data = output.getvalue()

Loading…
Cancel
Save