From f8b3441431eae5ada0977cb4135fdeef4a1ba369 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Fri, 27 Jul 2018 13:32:55 -0700 Subject: [PATCH] ansible: work around Ansible PR #41749 --- ansible_mitogen/target.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ansible_mitogen/target.py b/ansible_mitogen/target.py index e5365dd4..47249f25 100644 --- a/ansible_mitogen/target.py +++ b/ansible_mitogen/target.py @@ -39,6 +39,7 @@ import functools import grp import json import logging +import new import operator import os import pwd @@ -46,16 +47,25 @@ import re import signal import stat import subprocess +import sys import tempfile import traceback -import ansible.module_utils.json_utils -import ansible_mitogen.runner import mitogen.core import mitogen.fork import mitogen.parent import mitogen.service +# Ansible since PR #41749 inserts "import __main__" into +# ansible.module_utils.basic. Mitogen's importer will refuse such an import, so +# we must setup a fake "__main__" before that module is ever imported. The +# str() is to cast Unicode to bytes on Python 2.6. +if not sys.modules.get(str('__main__')): + sys.modules[str('__main__')] = new.module(str('__main__')) + +import ansible.module_utils.json_utils +import ansible_mitogen.runner + LOG = logging.getLogger(__name__)