summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToshio Kuratomi <a.badger@gmail.com>2016-11-29 01:21:13 -0800
committerToshio Kuratomi <a.badger@gmail.com>2016-11-29 01:22:22 -0800
commitfaaabec3971da36cebf2b849ed0ae65919b1df31 (patch)
treeb0411276cc4e0916fd5d6fd3dc4bf3ec0d85ccb5
parent288f6684cf9bcb38980fc7735738a91a90c0cb65 (diff)
downloadansible-faaabec3971da36cebf2b849ed0ae65919b1df31.tar.gz
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 (cherry picked from commit 3c6d71522e9922156121b731222e9ac6146c9cb1)
-rw-r--r--lib/ansible/executor/module_common.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/ansible/executor/module_common.py b/lib/ansible/executor/module_common.py
index 41b57b5fcb..a94060ab9a 100644
--- a/lib/ansible/executor/module_common.py
+++ b/lib/ansible/executor/module_common.py
@@ -22,6 +22,7 @@ __metaclass__ = type
import ast
import base64
+import datetime
import imp
import json
import os
@@ -317,7 +318,12 @@ if __name__ == '__main__':
# 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 = 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()
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 = u"'{0}'".format(u"', '".join(interpreter_parts))
+ now=datetime.datetime.utcnow()
output.write(to_bytes(ACTIVE_ANSIBALLZ_TEMPLATE % dict(
zipdata=zipdata,
ansible_module=module_name,
@@ -687,6 +694,12 @@ def _find_snippet_imports(module_name, module_data, module_path, module_args, ta
shebang=shebang,
interpreter=interpreter,
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()